Created
June 2, 2020 11:04
-
-
Save RafalFilipek/b1826f3294cda9575f0d55335dee4385 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 Options = { | |
| actions: { | |
| setErrorInfo: "setErrorInfo", | |
| setInitializingData: "setInitializingData", | |
| setOfferTypeGroup: "setOfferTypeGroup", | |
| setOfferType: "setOfferType", | |
| setProcedure: "setProcedure", | |
| setOffer: "setOffer", | |
| setShouldAddAnotherDevice: "setShouldAddAnotherDevice", | |
| setSelectedProcesableContract: "setSelectedProcesableContract", | |
| setIsUserLoggedIn: "setIsUserLoggedIn", | |
| setIsUserVerified: "setIsUserVerified", | |
| setHasOfferBeenBought: "setHasOfferBeenBought", | |
| setHasAccountBeenChanged: "setHasAccountBeenChanged", | |
| setAddressWithServices: "setAddressWithServices", | |
| setFixMigrationProcedure: "setFixMigrationProcedure", | |
| setSelectedAccount: "setSelectedAccount", | |
| setLocationData: "setLocationData" | |
| }, | |
| guards: { | |
| isError: "isError", | |
| isLoveOfferType: "isLoveOfferType", | |
| isFixOfferType: "isFixOfferType", | |
| hasOfferWithDevice: "hasOfferWithDevice", | |
| isDataLDF: "isDataLDF", | |
| isLoggedInWithoutSelectedAccount: "isLoggedInWithoutSelectedAccount", | |
| mustBeVerifiedForDiscount: "mustBeVerifiedForDiscount", | |
| isUserVerified: "isUserVerified", | |
| isUserLoggedIn: "isUserLoggedIn", | |
| isActivationProcedure: "isActivationProcedure", | |
| isRetentionOrMnpProcedure: "isRetentionOrMnpProcedure", | |
| shouldAddAnotherOffer: "shouldAddAnotherOffer", | |
| hasOfferBeenBought: "hasOfferBeenBought", | |
| isSelectedUpsellOffer: "isSelectedUpsellOffer", | |
| hasUserAccountBeenChanged: "hasUserAccountBeenChanged", | |
| isSelectedNewAddress: "isSelectedNewAddress", | |
| isMaintenance: "isMaintenance" | |
| }, | |
| services: { | |
| initializingStep: "initializingStep", | |
| offerTypeGroupsStep: "offerTypeGroupsStep", | |
| offerTypesStep: "offerTypesStep", | |
| proceduresStep: "proceduresStep", | |
| offersStep: "offersStep", | |
| summaryStep: "summaryStep", | |
| authorizationStep: "authorizationStep", | |
| verifyAndBuyStep: "verifyAndBuyStep", | |
| procesableContractsStep: "procesableContractsStep", | |
| changeAccountStep: "changeAccountStep", | |
| loginStep: "loginStep", | |
| addressesAndServicesStep: "addressesAndServicesStep", | |
| fixMigrationProceduresStep: "fixMigrationProceduresStep", | |
| accountsStep: "accountsStep", | |
| locationStep: "locationStep" | |
| } | |
| }; | |
| const m = Machine({ | |
| strict: true, | |
| id: `suflerMachine`, | |
| context: { | |
| config: { | |
| market: 'B2C', | |
| isMaintenance: false | |
| }, | |
| user: { | |
| isLoggedIn: false, | |
| isVerified: false, | |
| selectedAccount: null, | |
| procesableContracts: [] | |
| }, | |
| offerTypeGroups: { | |
| selectedOfferTypeGroup: null | |
| }, | |
| offerTypes: { | |
| selectedOfferType: null | |
| }, | |
| location: { | |
| data: null | |
| }, | |
| offers: { | |
| selectedOffer: null, | |
| withDevice: false, | |
| withDiscount: false | |
| }, | |
| procedures: { | |
| selectedProcedure: null | |
| }, | |
| upsell: { | |
| selectedUpsellOffer: null, | |
| data: null | |
| }, | |
| summary: { | |
| shouldAddAnotherDevice: false | |
| }, | |
| errorInfo: { | |
| code: null | |
| }, | |
| redirect: { | |
| data: null | |
| }, | |
| procesableContracts: { | |
| selectedProcesableContract: null | |
| }, | |
| verifyAndBuy: { | |
| hasOfferBeenBought: null | |
| }, | |
| changeAccount: { | |
| hasAccountBeenChanged: false | |
| }, | |
| addressesAndServices: { | |
| selectedAddressWithServices: null, | |
| selectedNewAddress: false | |
| }, | |
| fixMigrationProcedure: { | |
| selectedFixMigrationProcedure: null | |
| } | |
| }, | |
| initial: "initializing", | |
| states: { | |
| initializing: { | |
| id: "initializing", | |
| invoke: { | |
| id: "step", | |
| src: Options.services.initializingStep, | |
| onDone: { | |
| target: "initializingActionResolver", | |
| actions: Options.actions.setInitializingData | |
| }, | |
| onError: { | |
| target: "error", | |
| actions: Options.actions.setErrorInfo | |
| } | |
| } | |
| }, | |
| initializingActionResolver: { | |
| id: "initializingActionResolver", | |
| on: { | |
| "": [{ | |
| target: "#maintenance", | |
| cond: Options.guards.isMaintenance | |
| }, { | |
| target: "#offerTypeGroups" | |
| }] | |
| } | |
| }, | |
| offerTypeGroups: { | |
| id: "offerTypeGroups", | |
| invoke: { | |
| id: "step", | |
| src: Options.services.offerTypeGroupsStep, | |
| onDone: { | |
| actions: Options.actions.setOfferTypeGroup, | |
| target: "#offerTypes" | |
| }, | |
| onError: { | |
| target: "#error" | |
| } | |
| } | |
| }, | |
| offerTypes: { | |
| id: "offerTypes", | |
| invoke: { | |
| id: "step", | |
| src: Options.services.offerTypesStep, | |
| onDone: { | |
| actions: Options.actions.setOfferType, | |
| target: "#offerTypesActionResolver" | |
| }, | |
| onError: { | |
| target: "#error" | |
| } | |
| } | |
| }, | |
| offerTypesActionResolver: { | |
| id: "offerTypesActionResolver", | |
| initial: "init", | |
| states: { | |
| init: { | |
| on: { | |
| "": [{ | |
| target: "#upsell", | |
| cond: Options.guards.isSelectedUpsellOffer | |
| }, { | |
| target: "fix", | |
| cond: Options.guards.isFixOfferType | |
| }, { | |
| target: "#procedures" | |
| }] | |
| } | |
| }, | |
| fix: { | |
| on: { | |
| "": [{ | |
| target: "#addressesAndServices", | |
| cond: Options.guards.isUserLoggedIn | |
| }, { | |
| target: "#procedures" | |
| }] | |
| } | |
| } | |
| } | |
| }, | |
| procedures: { | |
| id: "procedures", | |
| invoke: { | |
| id: "step", | |
| src: Options.services.proceduresStep, | |
| onDone: { | |
| actions: Options.actions.setProcedure, | |
| target: "#proceduresActionsResolver" | |
| }, | |
| onError: { | |
| target: "#error" | |
| } | |
| } | |
| }, | |
| proceduresActionsResolver: { | |
| id: "proceduresActionsResolver", | |
| initial: "init", | |
| states: { | |
| init: { | |
| on: { | |
| "": [{ | |
| target: "#upsell", | |
| cond: Options.guards.isSelectedUpsellOffer | |
| }, { | |
| target: "fix", | |
| cond: Options.guards.isFixOfferType | |
| }, { | |
| target: "#location", | |
| cond: Options.guards.isLoveOfferType | |
| }, { | |
| target: "#offers", | |
| cond: Options.guards.isActivationProcedure | |
| }, { | |
| target: "check", | |
| cond: Options.guards.isRetentionOrMnpProcedure | |
| }, { | |
| target: "#authorization" | |
| }] | |
| } | |
| }, | |
| fix: { | |
| on: { | |
| "": [{ | |
| target: "#location", | |
| cond: Options.guards.isActivationProcedure | |
| }, { | |
| target: "#authorization" | |
| }] | |
| } | |
| }, | |
| check: { | |
| on: { | |
| "": [{ | |
| target: "#procesableContracts", | |
| cond: Options.guards.isUserLoggedIn | |
| }, { | |
| target: "#authorization" | |
| }] | |
| } | |
| } | |
| } | |
| }, | |
| offers: { | |
| id: "offers", | |
| invoke: { | |
| id: "step", | |
| src: Options.services.offersStep, | |
| onDone: { | |
| actions: Options.actions.setOffer, | |
| target: "#offersActionResolver" | |
| }, | |
| onError: { | |
| target: "#error" | |
| } | |
| } | |
| }, | |
| offersActionResolver: { | |
| id: "offersActionResolver", | |
| initial: "init", | |
| states: { | |
| init: { | |
| on: { | |
| "": [{ | |
| target: "#redirect", | |
| cond: Options.guards.hasOfferWithDevice | |
| }, { | |
| target: "#redirect", | |
| cond: Options.guards.isFixOfferType | |
| }, { | |
| target: "#redirect", | |
| cond: Options.guards.isLoveOfferType | |
| }, { | |
| target: "mobile" | |
| }] | |
| } | |
| }, | |
| mobile: { | |
| on: { | |
| "": [{ | |
| target: "#redirect", | |
| cond: Options.guards.isDataLDF | |
| }, { | |
| target: "#accounts", | |
| cond: Options.guards.isLoggedInWithoutSelectedAccount | |
| }, { | |
| target: "#verifyAndBuy", | |
| cond: Options.guards.mustBeVerifiedForDiscount | |
| }, { | |
| target: "#summary" | |
| }] | |
| } | |
| } | |
| } | |
| }, | |
| summary: { | |
| id: "summary", | |
| invoke: { | |
| id: "step", | |
| src: Options.services.summaryStep, | |
| onDone: { | |
| actions: Options.actions.setShouldAddAnotherDevice, | |
| target: "#summaryActionResolver" | |
| }, | |
| onError: { | |
| target: "#error" | |
| } | |
| } | |
| }, | |
| summaryActionResolver: { | |
| id: "summaryActionResolver", | |
| on: { | |
| "": [{ | |
| target: "#procedures", | |
| cond: Options.guards.shouldAddAnotherOffer | |
| }, { | |
| target: "#redirect" | |
| }] | |
| } | |
| }, | |
| changeAccount: { | |
| id: "changeAccount", | |
| invoke: { | |
| id: "step", | |
| src: Options.services.changeAccountStep, | |
| onDone: { | |
| actions: [Options.actions.setHasAccountBeenChanged, Options.actions.setSelectedAccount], | |
| target: "#changeAccountActionResolver" | |
| }, | |
| onError: { | |
| target: "error" | |
| } | |
| } | |
| }, | |
| changeAccountActionResolver: { | |
| id: "changeAccountActionResolver", | |
| on: { | |
| "": [{ | |
| target: "#initializing", | |
| cond: Options.guards.hasUserAccountBeenChanged | |
| }, // @TODO czy to zadziała | |
| { | |
| target: "hist" | |
| }] | |
| } | |
| }, | |
| accounts: { | |
| id: "accounts", | |
| invoke: { | |
| id: "step", | |
| src: Options.services.accountsStep, | |
| // Gdzie dodać do koszyka? Tutaj, czy wewnątrz maszyny 'accounts'? | |
| onDone: { | |
| target: "#summary", | |
| actions: Options.actions.setSelectedAccount | |
| }, | |
| onError: { | |
| target: "#error" | |
| } | |
| } | |
| }, | |
| upsell: { | |
| id: "upsell" | |
| }, | |
| login: { | |
| id: "login", | |
| invoke: { | |
| id: "step", | |
| src: Options.services.loginStep, | |
| onDone: { | |
| target: "#loginActionResolver", | |
| actions: Options.actions.setIsUserLoggedIn | |
| }, | |
| onError: { | |
| target: "error" | |
| } | |
| } | |
| }, | |
| /* | |
| * TODO: | |
| * Po zalogowaniu przekierowanie na wybór konta MOBILE, dopiero potem do 'Initializing' | |
| */ | |
| loginActionResolver: { | |
| id: "loginActionResolver", | |
| on: { | |
| "": [{ | |
| cond: Options.guards.isUserLoggedIn, | |
| target: "#initializing" | |
| }, // @TODO czy to zadziała | |
| { | |
| target: "#hist" | |
| }] | |
| } | |
| }, | |
| authorization: { | |
| id: "authorization", | |
| invoke: { | |
| src: Options.services.authorizationStep, | |
| onDone: { | |
| target: "#authorizationActionResolver", | |
| actions: Options.actions.setIsUserLoggedIn | |
| }, | |
| onError: { | |
| target: "error" | |
| } | |
| } | |
| }, | |
| authorizationActionResolver: { | |
| id: "authorizationActionResolver", | |
| type: "final", | |
| // @TODO | |
| on: { | |
| "": [{ | |
| target: "#addressesAndServices", | |
| cond: Options.guards.isFixOfferType | |
| }, { | |
| target: "#offers" | |
| }] | |
| } | |
| }, | |
| procesableContracts: { | |
| id: "procesableContracts", | |
| invoke: { | |
| id: "step", | |
| src: Options.services.procesableContractsStep, | |
| onDone: { | |
| actions: Options.actions.setSelectedProcesableContract, | |
| target: "#offers" | |
| }, | |
| onError: { | |
| target: "#error" | |
| } | |
| } | |
| }, | |
| verifyAndBuy: { | |
| id: "verifyAndBuy", | |
| invoke: { | |
| id: "step", | |
| src: Options.services.verifyAndBuyStep, | |
| onDone: { | |
| target: "#verifyAndBuyActionResolver", | |
| actions: [Options.actions.setIsUserVerified, Options.actions.setHasOfferBeenBought] | |
| }, | |
| onError: { | |
| target: "error" | |
| } | |
| } | |
| }, | |
| verifyAndBuyActionResolver: { | |
| id: "verifyAndBuyActionResolver", | |
| on: { | |
| "": [{ | |
| target: "#summary", | |
| cond: Options.guards.hasOfferBeenBought | |
| }, { | |
| target: "#offers" | |
| }] | |
| } | |
| }, | |
| addressesAndServices: { | |
| id: "addressesAndServices", | |
| invoke: { | |
| id: "step", | |
| src: Options.services.addressesAndServicesStep, | |
| onDone: { | |
| actions: Options.actions.setAddressWithServices, | |
| target: "#addressesAndServicesActionResolver" | |
| }, | |
| onError: { | |
| target: "#error" | |
| } | |
| } | |
| }, | |
| addressesAndServicesActionResolver: { | |
| id: "addressesAndServicesActionResolver", | |
| on: { | |
| "": [{ | |
| target: "#location", | |
| cond: Options.guards.isSelectedNewAddress | |
| }, { | |
| target: "#fixMigrationProcedures" | |
| }] | |
| } | |
| }, | |
| fixMigrationProcedures: { | |
| id: "fixMigrationProcedures", | |
| invoke: { | |
| id: "step", | |
| src: Options.services.fixMigrationProceduresStep, | |
| onDone: { | |
| actions: Options.actions.setFixMigrationProcedure, | |
| target: "#offers" | |
| }, | |
| onError: { | |
| target: "error" | |
| } | |
| } | |
| }, | |
| location: { | |
| id: "location", | |
| invoke: { | |
| id: "step", | |
| src: Options.services.locationStep, | |
| onDone: { | |
| actions: Options.actions.setLocationData, | |
| target: "#offers" | |
| }, | |
| onError: { | |
| target: "#error" | |
| } | |
| } | |
| }, | |
| maintenance: { | |
| id: "maintenance", | |
| type: "final" | |
| }, | |
| error: { | |
| id: "error", | |
| type: "final" | |
| }, | |
| redirect: { | |
| id: "redirect", | |
| type: "final" | |
| }, | |
| hist: { | |
| id: "hist", | |
| type: "history" | |
| } | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment