Created
January 30, 2020 01:08
-
-
Save tmbtech/e12bbc738a0ba16000564f9cca7ace90 to your computer and use it in GitHub Desktop.
Revisions
-
tmbtech revised this gist
Jan 30, 2020 . No changes.There are no files selected for viewing
-
tmbtech created this gist
Jan 30, 2020 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,158 @@ // Available variables: // - Machine // - interpret // - assign // - send // - sendParent // - spawn // - raise // - actions // - XState (all XState exports) const fetchMachine = Machine({ id: "register_user", initial: "checkUserStatus", context: { alleToken: null, sessionToken: null, oktaTokens: null, registrationFields: { firstName: "", lastName: "", emailAddress: "", password: "" } }, states: { checkUserStatus: { initial: "checkUserLoggedIn", states: { checkUserLoggedIn: { invoke: { id: "checkIsLoggedIn", src: "checkIsLoggedIn", onDone: "isLoggedIn", onError: "isNotLoggedIn" } }, isLoggedIn: { entry: "redirectToAccount" }, isNotLoggedIn: { invoke: { id: "verifySMSCode", src: "verifySMSCode", onDone: { target: "#waitForInput", actions: "setAlleToken" }, onError: { target: "#redirectToPhoneVerification", actions: "redirectToPhoneVerification" } } } } }, redirectToPhoneVerification: { id: "redirectToPhoneVerification", type: "final" }, waitForInput: { id: "waitForInput", on: { REGISTRATION_SUBMITTED: { target: "hipaRequirement", actions: "setRegistrationFields" } } }, hipaRequirement: { initial: "showHipaaNotice", states: { showHipaaNotice: { on: { DECLINE: "confirmHipaaDecline", REGISTRATION_COMPLETE: { target: "#getOktaToken", actions: "setSessionToken" }, REGISTRATION_ERROR: { target: "acceptedHipaaWaitForInput" } } }, acceptedHipaaWaitForInput: { on: { REGISTRATION_COMPLETE: { target: "#getOktaToken", actions: "setSessionToken" }, REGISTRATION_ERROR: { target: "acceptedHipaaWaitForInput" } } }, confirmHipaaDecline: { on: { CLOSE: "showHipaaNotice", EXIT_REGISTRATION: "#redirectToHomepage", REGISTRATION_COMPLETE: { target: "#getOktaToken", actions: "setSessionToken" }, REGISTRATION_ERROR: { target: "acceptedHipaaWaitForInput" } } } } }, oktaAuth: { states: { getOktaToken: { id: "getOktaToken", invoke: { id: "getOktaToken", src: "getOktaToken", onDone: { target: "updateTokenManager", actions: "setOktaTokens" }, onError: "#redirectToLogin" } }, updateTokenManager: { invoke: { id: "updateTokenManger", src: "updateTokenManager", onDone: "#registrationComplete", onError: "#redirectToLogin" } } } }, redirects: { states: { redirectToLogin: { id: "redirectToLogin", entry: "redirectToLogin", type: "final" }, registrationComplete: { id: "registrationComplete", entry: "redirectToAccount", type: "final" }, redirectToHomepage: { id: "redirectToHomepage", entry: "redirectToHomepage", type: "final" } } } } });