Skip to content

Instantly share code, notes, and snippets.

@davidlav
Last active February 6, 2020 18:20
Show Gist options
  • Save davidlav/e72442e4b133e5b4074f390ced1a57b3 to your computer and use it in GitHub Desktop.
Save davidlav/e72442e4b133e5b4074f390ced1a57b3 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
Machine({
id: 'registrationStateMachine',
initial: 'newRegistrationForm',
context: {
isApprovedBySponsor: false,
isApprovedBySysops: false,
isCertified: false,
registrationCancellationReason: '',
},
states: {
newRegistrationForm: {
on: {
REGISTRATION_FORM_SUBMITTED: {
target: 'awaitingSponsorApproval',
actions: 'sendComplianceCertificationForm',
},
},
},
awaitingSponsorApproval: {
entry: 'emailSponsor',
on: {
SPONSOR_APPROVES: {
target: 'awaitingSysopsApproval',
actions: 'setSponsorApproval',
},
SPONSOR_DISAPPROVES: {
target: 'registrationCanceled',
actions: 'setRegistrationCancellationReason',
},
},
},
awaitingSysopsApproval: {
entry: 'emailSysops',
on: {
SYSOPS_APPROVES: {
target: 'awaitingCertification',
actions: 'setSysopsApproval',
},
SYSOPS_DISAPPROVES: {
target: 'registrationCanceled',
actions: 'setRegistrationCancellationReason',
},
},
},
awaitingCertification: {
on: {
'': {
target: 'generateIPAAccount',
cond: 'certified',
},
},
},
generateIPAAccount: {
type: 'final',
entry: [
'emailNewUserInfo',
'send2FASMS',
],
},
registrationCanceled: {
type: 'final',
},
},
on: {
COMPLIANCE_CERTIFIED: {
actions: 'setCertifiedTrue',
},
COMPLIANCE_REJECTED: {
target: 'registrationCanceled',
actions: 'setRegistrationCancellationReason',
},
},
}, {
actions: {
setSponsorApproval: assign({
isApprovedBySponsor: true,
}),
setSysopsApproval: assign({
isApprovedBySysops: true,
}),
setCertifiedTrue: assign({
isCertified: true,
}),
setRegistrationCancellationReason: assign({
registrationCancellationReason: (ctx, event) => event.type,
}),
sendComplianceCertificationForm: () => console.log('Send compliance certification form'),
emailSponsor: () => {
console.log('Email sponsor');
},
emailSysops: () => {
console.log('Email sysops');
},
emailNewUserInfo: () => console.log('Email new user info'),
send2FASMS: () => console.log('Send 2FA SMS'),
},
guards: {
certified: ctx => ctx.isCertified,
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment