const CourierOnboardingVerificationsItemState = { IN_REVISION: `IN_REVISION`, PENDING: `PENDING`, VERIFIED: `VERIFIED`, } const CourierState = { ACTIVE: `ACTIVE`, BLOCKED: `BLOCKED`, PENDING: `PENDING`, REJECTED: `REJECTED`, } 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, 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])), })); } }) }, guards: { isActive: (ctx) => ctx.state === CourierState.ACTIVE, }, } )