// 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" } } } } });