Created
May 20, 2022 09:01
-
-
Save rafaelmotta/ef45cb3025b08b930f2d12349abce0e5 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains 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
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const fetchMachine = Machine({ | |
id: 'bifrostMachine', | |
initial: 'emailIdentification', | |
context: { | |
identification: {}, | |
registration: {}, | |
}, | |
states: { | |
emailIdentification: { | |
on: { | |
USER_FOUND: { | |
target: 'phoneVerification', | |
actions: assign((context, { phoneLastTwoDigits }) => { | |
context.identification.phoneLastTwoDigits = phoneLastTwoDigits; | |
return context; | |
}), | |
}, | |
USER_NOT_FOUND: { | |
target: 'phoneRegistration', | |
actions: assign((context, { email }) => { | |
context.registration.email = email; | |
return context; | |
}), | |
}, | |
}, | |
}, | |
phoneRegistration: { | |
on: { | |
CHANGE_EMAIL: { | |
target: 'emailIdentification', | |
actions: assign(context => { | |
context.identification = {}; | |
context.registration = {}; | |
return context; | |
}), | |
}, | |
PHONE_SUBMITTED: { | |
target: 'emailIdentification', | |
}, | |
}, | |
}, | |
phoneVerification: { | |
on: { | |
USER_CREATED: { | |
target: 'registration', | |
}, | |
USER_INHERITED: { | |
target: 'verificationSuccess', | |
}, | |
}, | |
}, | |
registration: { | |
type: 'compound', | |
initial: 'basicInformation', | |
states: { | |
basicInformation: { | |
on: { | |
BASIC_INFORMATION_SUBMITTED: { | |
target: 'residentialAddress', | |
actions: assign((context, { basicInformation }) => { | |
context.registration = { | |
...context.registration, | |
...basicInformation, | |
}; | |
return context; | |
}), | |
}, | |
}, | |
}, | |
residentialAddress: { | |
on: { | |
RESIDENTIAL_ADDRESS_SUBMITTED: { | |
target: 'ssn', | |
actions: assign((context, { residentialAddress }) => { | |
context.registration = { | |
...context.registration, | |
...residentialAddress, | |
}; | |
return context; | |
}), | |
}, | |
}, | |
}, | |
ssn: { | |
on: { | |
SSN_SUBMITTED: { | |
target: 'registrationSuccess', | |
actions: assign((context, { ssn }) => { | |
context.registration.ssn = ssn; | |
return context; | |
}), | |
}, | |
}, | |
}, | |
registrationSuccess: { | |
type: 'final', | |
}, | |
}, | |
}, | |
verificationSuccess: { | |
type: 'final', | |
}, | |
}, | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment