Last active
April 18, 2020 00:40
-
-
Save hosmelq/e94329abf9741d1101334a73cd41787c 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
const CourierOnboardingVerificationsItemState = { | |
IN_REVISION: `IN_REVISION`, | |
PENDING: `PENDING`, | |
VERIFIED: `VERIFIED`, | |
} | |
const CourierState = { | |
ACTIVE: `ACTIVE`, | |
BLOCKED: `BLOCKED`, | |
PENDING: `PENDING`, | |
REJECTED: `REJECTED`, | |
} | |
// | |
const emergencyContactMachine = Machine( | |
{ | |
id: `emergencyContact`, | |
initial: `unknown`, | |
context: { | |
message: null, | |
state: `PENDING`, | |
}, | |
states: { | |
unknown: { | |
on: { | |
'': [ | |
{cond: `isPending`, target: `pending`}, | |
{cond: `isVerified`, target: `verified`}, | |
], | |
}, | |
}, | |
pending: { | |
on: { | |
SUBMIT: `submitting`, | |
}, | |
}, | |
submitting: { | |
invoke: { | |
id: `update-information`, | |
src: `updateInformation`, | |
onDone: `verified`, | |
onError: { | |
target: `pending`, | |
actions: `handleGraphQLErrors`, | |
}, | |
}, | |
}, | |
verified: { | |
entry: `updateInformationSuccess`, | |
type: `final`, | |
}, | |
}, | |
}, | |
{ | |
guards: { | |
isPending: (ctx) => { | |
return ctx.state === CourierOnboardingVerificationsItemState.PENDING | |
}, | |
isVerified: (ctx) => { | |
return ctx.state === CourierOnboardingVerificationsItemState.VERIFIED | |
}, | |
}, | |
} | |
) | |
// | |
const checkMachine = Machine( | |
{ | |
id: `check`, | |
initial: `unknown`, | |
context: { | |
message: null, | |
state: null, | |
}, | |
states: { | |
unknown: { | |
on: { | |
'': [ | |
{cond: `isInRevision`, target: `inRevision`}, | |
{cond: `isPending`, target: `pending`}, | |
{cond: `isVerified`, target: `verified`}, | |
], | |
}, | |
}, | |
inRevision: {}, | |
pending: {}, | |
verified: {}, | |
}, | |
}, | |
{ | |
guards: { | |
isInRevision: (ctx) => { | |
return ctx.state === CourierOnboardingVerificationsItemState.IN_REVISION | |
}, | |
isPending: (ctx) => { | |
return ctx.state === CourierOnboardingVerificationsItemState.PENDING | |
}, | |
isVerified: (ctx) => { | |
return ctx.state === CourierOnboardingVerificationsItemState.VERIFIED | |
}, | |
}, | |
} | |
) | |
Machine( | |
{ | |
id: `onboard`, | |
initial: `initializing`, | |
context: { | |
state: null, | |
checks2: {}, | |
checks: { | |
emergencyContact: { | |
message: null, | |
state: 'PENDING', | |
}, | |
picture: { | |
message: null, | |
state: 'PENDING', | |
}, | |
vehicleInformation: { | |
message: null, | |
state: 'PENDING', | |
}, | |
}, | |
}, | |
states: { | |
initializing: { | |
entry: `initializeChecks`, | |
on: { | |
'': `unknown`, | |
}, | |
}, | |
initializeChecks: {}, | |
unknown: { | |
on: { | |
'': [ | |
{ | |
cond: `isActive`, | |
target: `active`, | |
}, | |
], | |
}, | |
}, | |
active: { | |
meta: { | |
title: `Activa`, | |
}, | |
}, | |
}, | |
}, | |
{ | |
actions: { | |
initializeChecks: assign({ | |
checks: (ctx) => { | |
return Object.keys(ctx.checks).map(key => ({ | |
...ctx.checks[key], | |
ref: spawn(checkMachine.withContext(ctx.checks[key])), | |
})); | |
}, | |
checks2: (ctx) => { | |
return { | |
...ctx.checks2, | |
emergencyContact: spawn(emergencyContactMachine, `emergencyContact`) | |
} | |
} | |
}) | |
}, | |
guards: { | |
isActive: (ctx) => ctx.state === CourierState.ACTIVE, | |
}, | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment