Skip to content

Instantly share code, notes, and snippets.

@jredrejo
Created May 4, 2022 18:22
Show Gist options
  • Save jredrejo/4b10be798f63c099f6dfe270c8adc3c2 to your computer and use it in GitHub Desktop.
Save jredrejo/4b10be798f63c099f6dfe270c8adc3c2 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const isQuick = context => {
return context.quick;
};
const isNewFacility = context => {
return context.setupType === 'new';
};
const isLODSetup = context => {
return context.setupType === 'lod';
};
const setQuick = assign({
quick: (_, event) => event.value,
});
const setSetupType = assign({
setupType: (_, event) => event.value,
});
const wizardMachine = Machine({
id: 'wizard',
initial: 'defaultLanguage',
context: {
quick: true,
setupType: false,
},
states: {
defaultLanguage: {
meta: { route: 'DEFAULT_LANGUAGE', path: '/' },
on: {
CONTINUE: 'gettingStarted',
},
},
gettingStarted: {
meta: { route: 'GETTING_STARTED', path: '/' },
on: {
CONTINUE: { target: 'quickOrAdvanced', actions: setQuick },
BACK: 'defaultLanguage',
},
},
quickOrAdvanced: {
always: [
{
cond: isQuick,
target: 'personalSetup',
},
{
target: 'deviceName',
},
],
},
personalSetup: {
meta: { route: 'PERSONAL_SETUP' },
on: {
BACK: 'gettingStarted',
},
},
deviceName: {
meta: { route: 'DEVICE_NAME', path: '/' },
on: {
CONTINUE: 'publicSetup',
BACK: 'gettingStarted',
},
},
publicSetup: {
meta: { route: 'PUBLIC_SETUP_METHOD', path: '/' },
on: {
CONTINUE: { target: 'importOrNew', actions: setSetupType },
BACK: 'deviceName',
},
},
importOrNew: {
always: [
{
cond: isNewFacility,
target: 'createFacility',
},
{
cond: isLODSetup,
target: 'importLODUsers',
},
{
target: 'importFacility',
},
],
},
createFacility: {
meta: { route: 'CREATE_FACILITY/1' },
CONTINUE: 'quickOrAdvanced',
on: {
BACK: 'publicSetup',
},
},
importFacility: {
meta: { route: 'IMPORT_FACILITY' },
on: {
BACK: 'publicSetup',
},
},
importLODUsers: {
meta: { route: 'IMPORT_LOD' },
on: {
BACK: 'publicSetup',
},
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment