Skip to content

Instantly share code, notes, and snippets.

@andieromero
Last active March 1, 2022 17:56
Show Gist options
  • Select an option

  • Save andieromero/dfa1b8104b9a46f20600524f97767bcf to your computer and use it in GitHub Desktop.

Select an option

Save andieromero/dfa1b8104b9a46f20600524f97767bcf to your computer and use it in GitHub Desktop.

Revisions

  1. andieromero revised this gist Mar 1, 2022. 1 changed file with 461 additions and 183 deletions.
    644 changes: 461 additions & 183 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -10,235 +10,513 @@
    // - actions
    // - XState (all XState exports)

    const fetchMachine = Machine({
    id: 'fetch',
    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',
    context: {
    retries: 0
    },
    actions: {

    },
    states: {
    idle: {
    on: {
    BROWSE: {
    target: 'browsing',
    },
    CAPTURE_INTEREST: {
    target: 'intro_accreditation',
    actions: assign({
    steps: (context) => {
    console.log(context)
    return context;
    },
    }),
    idle: {
    on: {
    BROWSE: {
    target: 'browsing',
    },
    CAPTURE_INTEREST: {
    target: 'intro_accreditation',
    actions: ['onCaptureInterest'],
    // invoke: 'getCurrentStep',
    },
    },
    exit: ['saveToSessionStorage'],
    },
    },
    browsing: {
    on: {
    CAPTURE_INTEREST: {
    target: 'intro_accreditation',
    browsing: {
    on: {
    CAPTURE_INTEREST: {
    target: 'intro_accreditation',
    actions: ['saveToSessionStorage'],
    },
    },
    },
    },
    intro_accreditation: {
    on: {
    SUBMIT_INTRO_ACCREDITATION: 'identification',
    intro_accreditation: {
    on: {
    SUBMIT_INTRO_ACCREDITATION: {
    target: 'identification',
    actions: ['saveToSessionStorage'],
    },
    },
    },
    },
    identification: {
    on: {
    SUBMIT_IDENTIFICATION: [
    {
    target: 'accreditation',
    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: () => {
    // // check condition
    // return true;
    // },
    },
    {
    target: 'passport_submitted',
    SET_ACCREDITATION_FIRM_OR_FUND: {
    target: 'accreditation_firm_or_fund',
    // cond: () => {
    // },
    },
    SET_ACCREDITATION_TRUST: {
    target: 'accreditation_trust',
    // 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_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_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',
    accreditation_trust: {
    on: {
    SUBMIT_ACCREDITATION_TRUST: {
    target: 'verification_trust',
    },
    PASSPORT_SUBMITTED: {
    target: 'passport_submitted',
    },
    },
    },
    },
    verification_individual: {
    on: {
    SUBMIT_VERIFICATION_INDIVIDUAL: {
    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_firm_or_fund: {
    on: {
    SUBMIT_VERIFICATION_FIRM_OR_FUND: {
    target: 'beneficial_ownership',
    // cond: () => {}
    },
    },
    },
    },
    verification_trust: {
    on: {
    SUBMIT_VERIFICATION_TRUST: {
    target: 'passport_submitted',
    verification_trust: {
    on: {
    SUBMIT_VERIFICATION_TRUST: {
    target: 'passport_submitted',
    },
    },
    },
    },
    beneficial_ownership: {
    on: {
    SUBMIT_BENEFICIAL_OWNERSHIP: {
    target: 'authorized_signatories',
    beneficial_ownership: {
    on: {
    SUBMIT_BENEFICIAL_OWNERSHIP: {
    target: 'authorized_signatories',
    },
    },
    },
    },
    authorized_signatories: {
    on: {
    SUBMIT_AUTHORIZED_SIGNATORIES: {
    target: 'passport_submitted',
    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: () => {}
    // },
    ],
    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',
    tearsheet: {
    on: {
    TEARSHEET_INVEST: {
    target: 'commitment_amount',
    },
    },
    },
    },
    // INVESTMENT FLOW
    commitment_amount: {
    on: {
    SUBMIT_COMMITMENT: {
    target: 'eligibility_questions',
    // cond: () => {
    // // this is dynamic?
    // }
    // 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?
    // }
    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?
    // }
    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?
    // }
    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?
    // }
    security_questions_and_2fa: {
    on: {
    SECURITY_QUESTIONS_AND_2FA_SUBMIT: {
    target: 'funding',
    // cond: () => {
    // // this is dynamic?
    // }
    },
    },
    },
    },
    funding: {
    on: {
    ADDED_FUNDS: {
    target: 'funds_added',
    funding: {
    on: {
    ADDED_FUNDS: {
    target: 'funds_added',
    },
    },
    },
    },
    funds_added: {
    type: 'final',
    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',
    // },
    // },
    // });

  2. andieromero revised this gist Feb 24, 2022. 1 changed file with 18 additions and 2 deletions.
    20 changes: 18 additions & 2 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -15,16 +15,32 @@
    initial: 'idle',
    context: {
    retries: 0
    },
    actions: {

    },
    states: {
    idle: {
    on: {
    BROWSE: 'browsing',
    BROWSE: {
    target: 'browsing',
    },
    CAPTURE_INTEREST: {
    target: 'intro_accreditation',
    actions: assign({
    steps: (context) => {
    console.log(context)
    return context;
    },
    }),
    },
    },
    },
    browsing: {
    on: {
    CAPTURE_INTEREST: 'intro_accreditation',
    CAPTURE_INTEREST: {
    target: 'intro_accreditation',
    },
    },
    },
    intro_accreditation: {
  3. andieromero revised this gist Feb 24, 2022. 1 changed file with 121 additions and 20 deletions.
    141 changes: 121 additions & 20 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -70,12 +70,77 @@
    },
    },
    },
    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: 'final',
    // target: 'TEARSHEET',
    target: 'tearsheet',
    // cond: () => {},
    },
    // {
    @@ -90,36 +155,72 @@
    ],
    },
    },
    accreditation_individual: {
    tearsheet: {
    on: {
    SUBMIT_ACCREDITATION_INDIVIDUAL: {
    // target: 'verification_individual',
    target: 'final',
    TEARSHEET_INVEST: {
    target: 'commitment_amount',
    },
    },
    },
    accreditation_firm_or_fund: {
    // INVESTMENT FLOW
    commitment_amount: {
    on: {
    SUBMIT_ACCREDITATION_FIRM_OR_FUND: {
    // target: 'verification_firm_or_fund',
    target: 'final',
    SUBMIT_COMMITMENT: {
    target: 'eligibility_questions',
    // cond: () => {
    // // this is dynamic?
    // }
    },
    },
    },
    accreditation_trust: {
    eligibility_questions: {
    on: {
    SUBMIT_ACCREDITATION_TRUST: {
    // target: 'verification_trust',
    target: 'final',
    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',
    },
    },
    },
    // verification_individual: {
    // on: {
    // SUBMIT
    // }
    // },
    final: {
    funds_added: {
    type: 'final',
    },
    },
  4. andieromero revised this gist Feb 24, 2022. 1 changed file with 99 additions and 40 deletions.
    139 changes: 99 additions & 40 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -17,52 +17,111 @@
    retries: 0
    },
    states: {
    idle: {
    on: {
    BROWSE: 'browsing'
    }
    idle: {
    on: {
    BROWSE: 'browsing',
    },
    browsing: {
    on: {
    CAPTURE_INTEREST: 'intro_accreditation'
    }
    },
    intro_accreditation: {
    on: {
    SUBMIT_INTRO_ACCREDITATION: 'identification'
    }
    },
    browsing: {
    on: {
    CAPTURE_INTEREST: 'intro_accreditation',
    },
    identification: {
    on: {
    SUBMIT_IDENTIFICATION: [
    {
    target: 'accreditation',
    cond: () => {
    // check condition
    }
    },
    {
    target: 'passport_submitted',
    cond: () => {
    // check condition
    }
    }
    ]
    }
    },
    intro_accreditation: {
    on: {
    SUBMIT_INTRO_ACCREDITATION: 'identification',
    },
    acreditation: {
    on: {
    SET_ACCREDITATION_INDIVIDUAL: {
    target: 'accreditation_individual'
    },
    identification: {
    on: {
    SUBMIT_IDENTIFICATION: [
    {
    target: 'accreditation',
    // cond: () => {
    // // check condition
    // return true;
    // },
    },
    SET_ACCREDITATION_FIRM_OR_FUND: {
    target: 'accreditation_firm_or_fund'
    {
    target: 'passport_submitted',
    // cond: () => {
    // // check condition
    // },
    },
    SET_ACCREDITATION_TRUST: {
    target: 'accreditation_trust'
    ],
    },
    },
    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: () => {
    // },
    },
    },
    },
    passport_submitted: {
    on: {
    SUBMIT_PASSPORT_SUBMITTED: [
    {
    target: 'final',
    // target: 'TEARSHEET',
    // cond: () => {},
    },
    }
    // {
    // target: 'SUBSCRIBE_FLOW',
    // // cond: () => {},
    // },
    // {
    // target: 'CREATE_PROVENANCE_WALLET',
    // type: 'final',
    // // cond: () => {}
    // },
    ],
    },
    }
    },
    accreditation_individual: {
    on: {
    SUBMIT_ACCREDITATION_INDIVIDUAL: {
    // target: 'verification_individual',
    target: 'final',
    },
    },
    },
    accreditation_firm_or_fund: {
    on: {
    SUBMIT_ACCREDITATION_FIRM_OR_FUND: {
    // target: 'verification_firm_or_fund',
    target: 'final',
    },
    },
    },
    accreditation_trust: {
    on: {
    SUBMIT_ACCREDITATION_TRUST: {
    // target: 'verification_trust',
    target: 'final',
    },
    },
    },
    // verification_individual: {
    // on: {
    // SUBMIT
    // }
    // },
    final: {
    type: 'final',
    },
    },
    });

  5. andieromero revised this gist Feb 24, 2022. 1 changed file with 14 additions and 1 deletion.
    15 changes: 14 additions & 1 deletion machine.js
    Original file line number Diff line number Diff line change
    @@ -49,7 +49,20 @@
    }
    ]
    }
    }
    },
    acreditation: {
    on: {
    SET_ACCREDITATION_INDIVIDUAL: {
    target: 'accreditation_individual'
    },
    SET_ACCREDITATION_FIRM_OR_FUND: {
    target: 'accreditation_firm_or_fund'
    },
    SET_ACCREDITATION_TRUST: {
    target: 'accreditation_trust'
    },
    }
    },
    }
    });

  6. andieromero revised this gist Feb 24, 2022. 1 changed file with 19 additions and 9 deletions.
    28 changes: 19 additions & 9 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -27,17 +27,27 @@
    CAPTURE_INTEREST: 'intro_accreditation'
    }
    },
    success: {
    type: 'final'
    intro_accreditation: {
    on: {
    SUBMIT_INTRO_ACCREDITATION: 'identification'
    }
    },
    failure: {
    identification: {
    on: {
    RETRY: {
    target: 'loading',
    actions: assign({
    retries: (context, event) => context.retries + 1
    })
    }
    SUBMIT_IDENTIFICATION: [
    {
    target: 'accreditation',
    cond: () => {
    // check condition
    }
    },
    {
    target: 'passport_submitted',
    cond: () => {
    // check condition
    }
    }
    ]
    }
    }
    }
  7. andieromero revised this gist Feb 22, 2022. 1 changed file with 3 additions and 4 deletions.
    7 changes: 3 additions & 4 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -19,13 +19,12 @@
    states: {
    idle: {
    on: {
    FETCH: 'loading'
    BROWSE: 'browsing'
    }
    },
    loading: {
    browsing: {
    on: {
    RESOLVE: 'success',
    REJECT: 'failure'
    CAPTURE_INTEREST: 'intro_accreditation'
    }
    },
    success: {
  8. andieromero created this gist Feb 17, 2022.
    46 changes: 46 additions & 0 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@

    // Available variables:
    // - Machine
    // - interpret
    // - assign
    // - send
    // - sendParent
    // - spawn
    // - raise
    // - actions
    // - XState (all XState exports)

    const fetchMachine = Machine({
    id: 'fetch',
    initial: 'idle',
    context: {
    retries: 0
    },
    states: {
    idle: {
    on: {
    FETCH: 'loading'
    }
    },
    loading: {
    on: {
    RESOLVE: 'success',
    REJECT: 'failure'
    }
    },
    success: {
    type: 'final'
    },
    failure: {
    on: {
    RETRY: {
    target: 'loading',
    actions: assign({
    retries: (context, event) => context.retries + 1
    })
    }
    }
    }
    }
    });