Created
May 20, 2022 13:58
-
-
Save rafaelmotta/947a2cb29452eb45346cb31e460064dd 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 States = { | |
emailIdentification: 'emailIdentification', | |
basicInformation: 'basicInformation', | |
phoneVerification: 'phoneVerification', | |
verificationSuccess: 'verificationSuccess', | |
phoneRegistration: 'phoneRegistration', | |
residentialAddress: 'residentialAddress', | |
ssn: 'ssn', | |
registrationSuccess: 'registrationSuccess', | |
} | |
const initialIdentificationContext = {}; | |
const initialRegistrationContext = {}; | |
const fetchMachine = Machine({ | |
id: 'bifrostMachine', | |
initial: 'emailIdentification', | |
context: { | |
identification: initialIdentificationContext, | |
registration: initialRegistrationContext, | |
}, | |
states: { | |
[States.emailIdentification]: { | |
on: { | |
USER_FOUND: { | |
target: States.phoneVerification, | |
actions: assign((context, { payload }) => ({ | |
...context, | |
identification: payload, | |
})), | |
}, | |
USER_NOT_FOUND: { | |
target: States.phoneRegistration, | |
actions: assign((context, { payload }) => { | |
context.registration.email = payload.email; | |
return context; | |
}), | |
}, | |
}, | |
}, | |
[States.phoneRegistration]: { | |
on: { | |
CHANGE_EMAIL: { | |
target: States.emailIdentification, | |
actions: assign(context => { | |
context.identification = initialIdentificationContext; | |
context.registration = initialRegistrationContext; | |
return context; | |
}), | |
}, | |
PHONE_SUBMITTED: { | |
target: States.emailIdentification, | |
}, | |
}, | |
}, | |
[States.phoneVerification]: { | |
on: { | |
USER_CREATED: { | |
target: 'registration', | |
}, | |
USER_INHERITED: { | |
target: States.verificationSuccess, | |
}, | |
}, | |
}, | |
registration: { | |
type: 'compound', | |
initial: 'basicInformation', | |
states: { | |
[States.basicInformation]: { | |
on: { | |
BASIC_INFORMATION_SUBMITTED: { | |
target: States.residentialAddress, | |
actions: assign((context, { payload }) => { | |
context.registration = { | |
...context.registration, | |
...payload.basicInformation, | |
}; | |
return context; | |
}), | |
}, | |
}, | |
}, | |
[States.residentialAddress]: { | |
on: { | |
RESIDENTIAL_ADDRESS_SUBMITTED: { | |
target: States.ssn, | |
actions: assign((context, { payload }) => { | |
context.registration = { | |
...context.registration, | |
...payload.residentialAddress, | |
}; | |
return context; | |
}), | |
}, | |
}, | |
}, | |
[States.ssn]: { | |
on: { | |
SSN_SUBMITTED: { | |
target: States.registrationSuccess, | |
actions: assign((context, { payload }) => { | |
context.registration.ssn = payload.ssn; | |
return context; | |
}), | |
}, | |
}, | |
}, | |
[States.registrationSuccess]: { | |
type: 'final', | |
}, | |
}, | |
}, | |
verificationSuccess: { | |
type: 'final', | |
}, | |
}, | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment