// Available variables: // - Machine // - interpret // - assign // - send // - sendParent // - spawn // - raise // - actions // - XState (all XState exports) const CreateAccountStates = { loadingPrerequisites : 'loadingPrerequisites', createAccount : 'createAccount', addFirstPage : 'addFirstPage', addSecondPage : 'addSecondPage', loading : 'loading', error : 'error', finished : 'finished', } const CreateAccountEvents = { DONE : 'DONE', SUBMIT : 'SUBMIT', LOADING : 'LOADING', CREATE_ACCOUNT : 'CREATE_ACCOUNT', ADD_FIRST_PAGE : 'ADD_FIRST_PAGE', ERROR : 'ERROR', } const fetchMachine = Machine({ id: 'createMangoAccount', initial: CreateAccountStates.loadingPrerequisites, context: { error: false, errorMessage: '', profile: null, }, states: { loadingPrerequisites: { on: { DONE: { target: 'createAccount', actions: assign({ profile: (_, profile) => profile }), }, }, }, createAccount: { on: { SUBMIT: { target: 'loading', // TODO remap birthday actions: assign({ profile: (_, profile) => profile }), }, }, }, addFirstPage: { on: { DONE: 'addSecondPage', }, }, addSecondPage: { on: { DONE: 'finished' }, }, loading: { on: { CREATE_ACCOUNT: 'createAccount', ADD_FIRST_PAGE: 'addFirstPage', ERROR: 'error' }, }, error: { type: 'final', }, finished: { type: 'final', }, }, });