Created
May 4, 2022 18:22
-
-
Save jredrejo/4b10be798f63c099f6dfe270c8adc3c2 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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