Created
July 31, 2023 05:44
-
-
Save kepi74/42b731447bbd139413604c3b018492fa 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
| // Available variables: | |
| // - Machine | |
| // - interpret | |
| // - assign | |
| // - send | |
| // - sendParent | |
| // - spawn | |
| // - raise | |
| // - actions | |
| // - XState (all XState exports) | |
| const fetchMachine = Machine({ | |
| id: 'signIn', | |
| initial: 'idle', | |
| context: { | |
| error: null, | |
| signInWaitTiemout: 0, | |
| role: 'Seller', | |
| password: '', | |
| username: '', | |
| targetURL: null, | |
| token: null, | |
| }, | |
| states: { | |
| idle: { | |
| on: { | |
| SUBMIT: { | |
| target: 'submitting', | |
| actions: ['clearError', 'setCredentials'], | |
| }, | |
| }, | |
| }, | |
| submitting: { | |
| invoke: { | |
| src: 'authenticate', | |
| id: 'authenticate', | |
| onDone: [ | |
| { | |
| cond: 'isAuthenticated', | |
| actions: ['setToken', 'setTargetURL'], | |
| target: 'success', | |
| }, | |
| { | |
| cond: 'tooManyLoginAttempts', | |
| actions: ['setAuthenticationError', 'setSignInWaitTimeout'], | |
| target: 'signInBlocked', | |
| }, | |
| { | |
| actions: 'setAuthenticationError', | |
| target: 'idle', | |
| }, | |
| ], | |
| }, | |
| }, | |
| signInBlocked: { | |
| invoke: { | |
| id: 'signInBlockedCountdown', | |
| src: 'signInBlockedCountdown', | |
| }, | |
| on: { | |
| TICK: [ | |
| { | |
| cond: 'isSignInWaitTimeoutExpired', | |
| actions: 'clearSignInWaitTimeout', | |
| target: 'idle', | |
| }, | |
| { | |
| actions: 'decrementSignInWaitTimeout', | |
| }, | |
| ], | |
| }, | |
| }, | |
| success: { | |
| type: 'final', | |
| invoke: [ | |
| { | |
| id: 'persistToken', | |
| src: 'persistToken', | |
| }, | |
| { | |
| id: 'redirectToTargetRoleURL', | |
| src: 'redirectToTargetRoleURL', | |
| }, | |
| ], | |
| }, | |
| }, | |
| }); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment