Skip to content

Instantly share code, notes, and snippets.

@jredrejo
Last active July 1, 2020 16:08
Show Gist options
  • Save jredrejo/958de2f044e7ab03b8624e608ba31471 to your computer and use it in GitHub Desktop.
Save jredrejo/958de2f044e7ab03b8624e608ba31471 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const fetchMachine = Machine({
id: 'login',
initial: 'iddle',
context: {
appMode: false,
learner_can_login_without_password: false,
passwordMissing: false,
multipleFacilities: false,
facilities: [],
facilityUsers: [],
needsToCreatePassword: false,
username:'',
password: '',
},
states: {
iddle: {
on: {
FETCH: 'loading'
}
},
loading: {
on: {
APPMODE: 'listFacilityUsers',
NOT_APPMODE:'checkUsername',
APPMODE_NO_NETWORK: 'notAuthorized',
}
},
listFacilityUsers: {
on: {
CLICK: 'signedIn'
}
},
getFacilityUsers:{
on: {
SUCCESSS_LOWER_THAN_15:'listFacilityUsers',
SUCCESSS_MORE_THAN_15: 'checkUsername',
}
},
checkUsername:{
on:{
PASSWORD_LESS:'justEnterUsername',
PASSWORD_REQUIRED:'enterUsername'
}
},
enterUsername: {
on:{
CLICK: 'enterPassword'
}
},
justEnterUsername:{
on:{
CLICK: 'signedIn'
}
},
enterPassword: {
on: {
CLICK: 'checkPassword'
}
},
checkPassword: {
on: {
SUCCESS:'signedIn',
FAILURE:'enterPassword'
}
},
signedIn: {
type: 'final'
},
notAuthorized: {
type: 'final'
},
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment