Created
December 1, 2020 21:57
-
-
Save barucAlmaguer/bb5f0f7252ec4334497205bf2a2462ae 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 loginMachine = Machine( | |
{ | |
initial: 'howToLogin', | |
context: { | |
ssoUrl: undefined, | |
email: '', | |
password: '', | |
error: undefined, | |
client: undefined, | |
}, | |
states: { | |
validateSso: { | |
on: { | |
"": [{ | |
target: 'howToLogin' | |
} | |
] | |
} | |
}, | |
howToLogin: { | |
on: { | |
WITH_SSO: { | |
target: 'loadingSso', | |
actions: ['setSessionSsoInfo'], | |
}, | |
WITH_EMAIL_PASS: 'loggedOut' | |
} | |
}, | |
loggedOut: { | |
on: { | |
CLICK_LOGIN: { | |
target: 'loading', | |
}, | |
CHANGE_EMAIL: { | |
actions: 'setEmail', | |
}, | |
CHANGE_PASSWORD: { | |
actions: 'setPassword', | |
}, | |
}, | |
}, | |
loadingSso: { | |
type: 'final', | |
onEntry: 'redirectHome', | |
}, | |
loading: { | |
invoke: { | |
src: 'tryLogin', | |
onDone: [ | |
{ | |
target: 'loggedIn', | |
cond: 'isLoginSuccessful', | |
actions: ['setSessionInfo'], | |
}, | |
{ target: 'errorOnLogin', actions: ['setErrors'] }, | |
], | |
onError: { | |
target: 'errorOnLogin', | |
actions: ['setErrors'], | |
}, | |
}, | |
}, | |
errorOnLogin: { | |
on: { | |
CLICK_LOGIN: { | |
target: 'loading', | |
}, | |
CHANGE_EMAIL: { | |
actions: 'setEmail', | |
}, | |
CHANGE_PASSWORD: { | |
actions: 'setPassword', | |
}, | |
}, | |
}, | |
loggedIn: { | |
type: 'final', | |
onEntry: 'redirectHome', | |
}, | |
}, | |
}, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment