// Available variables: // - Machine // - interpret // - assign // - send // - sendParent // - spawn // - raise // - actions // - XState (all XState exports) const investorOnboardingMachine = Machine( { id: 'onboarding', // schema: { // context: {} as InvestorOnboardingState, // events: {} as InvestorOnboardingEvents, // actions: {} as InvestorOnboardingActions, // services: {} as any, // }, // Initialize context // context: { // events: [], // steps: { // [Flow.ACCREDITATION]: ACCREDITATION_STEPS, // [Flow.INVESTMENT]: ACCREDITATION_STEPS, // }, // flow: Flow.ACCREDITATION, // }, initial: 'idle', states: { idle: { on: { BROWSE: { target: 'browsing', }, CAPTURE_INTEREST: { target: 'intro_accreditation', actions: ['onCaptureInterest'], // invoke: 'getCurrentStep', }, }, exit: ['saveToSessionStorage'], }, browsing: { on: { CAPTURE_INTEREST: { target: 'intro_accreditation', actions: ['saveToSessionStorage'], }, }, }, intro_accreditation: { on: { SUBMIT_INTRO_ACCREDITATION: { target: 'identification', actions: ['saveToSessionStorage'], }, }, }, identification: { on: { SUBMIT_IDENTIFICATION: [ { target: 'accreditation', // cond: () => { // // check condition // return true; // }, }, { target: 'passport_submitted', // cond: () => { // // check condition // }, }, ], }, }, accreditation: { on: { SET_ACCREDITATION_INDIVIDUAL: { target: 'accreditation_individual', // cond: () => { // }, }, SET_ACCREDITATION_FIRM_OR_FUND: { target: 'accreditation_firm_or_fund', // cond: () => { // }, }, SET_ACCREDITATION_TRUST: { target: 'accreditation_trust', // cond: () => { // }, }, }, }, accreditation_individual: { on: { SUBMIT_ACCREDITATION_INDIVIDUAL: { target: 'verification_individual', }, PASSPORT_SUBMITTED: { target: 'passport_submitted', }, }, }, accreditation_firm_or_fund: { on: { SUBMIT_ACCREDITATION_FIRM_OR_FUND: { target: 'verification_firm_or_fund', }, PASSPORT_SUBMITTED: { target: 'passport_submitted', }, }, }, accreditation_trust: { on: { SUBMIT_ACCREDITATION_TRUST: { target: 'verification_trust', }, PASSPORT_SUBMITTED: { target: 'passport_submitted', }, }, }, verification_individual: { on: { SUBMIT_VERIFICATION_INDIVIDUAL: { target: 'passport_submitted', }, }, }, verification_firm_or_fund: { on: { SUBMIT_VERIFICATION_FIRM_OR_FUND: { target: 'beneficial_ownership', // cond: () => {} }, }, }, verification_trust: { on: { SUBMIT_VERIFICATION_TRUST: { target: 'passport_submitted', }, }, }, beneficial_ownership: { on: { SUBMIT_BENEFICIAL_OWNERSHIP: { target: 'authorized_signatories', }, }, }, authorized_signatories: { on: { SUBMIT_AUTHORIZED_SIGNATORIES: { target: 'passport_submitted', }, }, }, passport_submitted: { on: { SUBMIT_PASSPORT_SUBMITTED: [ { target: 'tearsheet', // cond: () => {}, }, // { // target: 'SUBSCRIBE_FLOW', // // cond: () => {}, // }, // { // target: 'CREATE_PROVENANCE_WALLET', // type: 'final', // // cond: () => {} // }, ], }, }, tearsheet: { on: { TEARSHEET_INVEST: { target: 'commitment_amount', }, }, }, // INVESTMENT FLOW commitment_amount: { on: { SUBMIT_COMMITMENT: { target: 'eligibility_questions', // cond: () => { // // this is dynamic? // } }, }, }, eligibility_questions: { on: { SUBMIT_ELIGIBILITY_QUESTIONS: { target: 'closing_docs', // cond: () => { // // this is dynamic? // } }, }, }, closing_docs: { on: { SUBMIT_CLOSING_DOCS: { target: 'tax_forms', // cond: () => { // // this is dynamic? // } }, }, }, tax_forms: { on: { SUBMIT_TAX_FORMS: { target: 'security_questions_and_2fa', // cond: () => { // // this is dynamic? // } }, }, }, security_questions_and_2fa: { on: { SECURITY_QUESTIONS_AND_2FA_SUBMIT: { target: 'funding', // cond: () => { // // this is dynamic? // } }, }, }, funding: { on: { ADDED_FUNDS: { target: 'funds_added', }, }, }, funds_added: { type: 'final', }, }, }, { actions: { onCaptureInterest: assign({ flow: (context) => Flow.ACCREDITATION, }), // TODO fix event saveToSessionStorage: assign({ steps: (context, event) => { console.log('sending event', event); // Typing in the assign function doesn't work. const { completesSteps } = Events[event.type]; console.log(completesSteps); if (completesSteps) { completesSteps.forEach((step) => { console.log('completing for ', step, event); }); // useSessionStorage(INVESTOR_ONBOARDING_SESSION_STORAGE_KEY, JSON.stringify(context)); // const storeStep = { // isCompleted: true, // isCurrentStep: true, // // stepType: (Events[Object.keys(event)[0]] as InvestorOnboardingEvent).stepType, // } as Step; return { ...context.steps }; } return { ...context.steps }; }, }), }, // services: { // getCurrentStep: (context, event) => { // console.log('get current step service... ', context, event); // }, // }, } ); // const fetchMachine = Machine({ // id: 'fetch', // initial: 'idle', // context: { // retries: 0 // }, // actions: { // }, // states: { // idle: { // on: { // BROWSE: { // target: 'browsing', // }, // CAPTURE_INTEREST: { // target: 'intro_accreditation', // actions: assign({ // steps: (context) => { // console.log(context) // return context; // }, // }), // }, // }, // }, // browsing: { // on: { // CAPTURE_INTEREST: { // target: 'intro_accreditation', // }, // }, // }, // intro_accreditation: { // on: { // SUBMIT_INTRO_ACCREDITATION: 'identification', // }, // }, // identification: { // on: { // SUBMIT_IDENTIFICATION: [ // { // target: 'accreditation', // // cond: () => { // // // check condition // // return true; // // }, // }, // { // target: 'passport_submitted', // // cond: () => { // // // check condition // // }, // }, // ], // }, // }, // accreditation: { // on: { // SET_ACCREDITATION_INDIVIDUAL: { // target: 'accreditation_individual', // // cond: () => { // // }, // }, // SET_ACCREDITATION_FIRM_OR_FUND: { // target: 'accreditation_firm_or_fund', // // cond: () => { // // }, // }, // SET_ACCREDITATION_TRUST: { // target: 'accreditation_trust', // // cond: () => { // // }, // }, // }, // }, // accreditation_individual: { // on: { // SUBMIT_ACCREDITATION_INDIVIDUAL: { // target: 'verification_individual', // }, // PASSPORT_SUBMITTED: { // target: 'passport_submitted', // }, // }, // }, // accreditation_firm_or_fund: { // on: { // SUBMIT_ACCREDITATION_FIRM_OR_FUND: { // target: 'verification_firm_or_fund', // }, // PASSPORT_SUBMITTED: { // target: 'passport_submitted', // }, // }, // }, // accreditation_trust: { // on: { // SUBMIT_ACCREDITATION_TRUST: { // target: 'verification_trust', // }, // PASSPORT_SUBMITTED: { // target: 'passport_submitted', // }, // }, // }, // verification_individual: { // on: { // SUBMIT_VERIFICATION_INDIVIDUAL: { // target: 'passport_submitted', // }, // }, // }, // verification_firm_or_fund: { // on: { // SUBMIT_VERIFICATION_FIRM_OR_FUND: { // target: 'beneficial_ownership', // // cond: () => {} // }, // }, // }, // verification_trust: { // on: { // SUBMIT_VERIFICATION_TRUST: { // target: 'passport_submitted', // }, // }, // }, // beneficial_ownership: { // on: { // SUBMIT_BENEFICIAL_OWNERSHIP: { // target: 'authorized_signatories', // }, // }, // }, // authorized_signatories: { // on: { // SUBMIT_AUTHORIZED_SIGNATORIES: { // target: 'passport_submitted', // }, // }, // }, // passport_submitted: { // on: { // SUBMIT_PASSPORT_SUBMITTED: [ // { // target: 'tearsheet', // // cond: () => {}, // }, // // { // // target: 'SUBSCRIBE_FLOW', // // // cond: () => {}, // // }, // // { // // target: 'CREATE_PROVENANCE_WALLET', // // type: 'final', // // // cond: () => {} // // }, // ], // }, // }, // tearsheet: { // on: { // TEARSHEET_INVEST: { // target: 'commitment_amount', // }, // }, // }, // // INVESTMENT FLOW // commitment_amount: { // on: { // SUBMIT_COMMITMENT: { // target: 'eligibility_questions', // // cond: () => { // // // this is dynamic? // // } // }, // }, // }, // eligibility_questions: { // on: { // SUBMIT_ELIGIBILITY_QUESTIONS: { // target: 'closing_docs', // // cond: () => { // // // this is dynamic? // // } // }, // }, // }, // closing_docs: { // on: { // SUBMIT_CLOSING_DOCS: { // target: 'tax_forms', // // cond: () => { // // // this is dynamic? // // } // }, // }, // }, // tax_forms: { // on: { // SUBMIT_TAX_FORMS: { // target: 'security_questions_and_2fa', // // cond: () => { // // // this is dynamic? // // } // }, // }, // }, // security_questions_and_2fa: { // on: { // SECURITY_QUESTIONS_AND_2FA_SUBMIT: { // target: 'funding', // // cond: () => { // // // this is dynamic? // // } // }, // }, // }, // funding: { // on: { // ADDED_FUNDS: { // target: 'funds_added', // }, // }, // }, // funds_added: { // type: 'final', // }, // }, // });