Skip to content

Instantly share code, notes, and snippets.

@gustavo-depaula
Created November 6, 2019 14:18
Show Gist options
  • Save gustavo-depaula/c4bcd39ae4473d6d17c6ab9ddbe18e31 to your computer and use it in GitHub Desktop.
Save gustavo-depaula/c4bcd39ae4473d6d17c6ab9ddbe18e31 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const driverInfoMachine = Machine({
id: 'driverInfo',
initial: 'invalid',
context: {
fields: {
name: '',
cpf: '',
email: '',
emailConfirmation: '',
phone: '',
city: ''
},
notificationMessage: '',
fieldErrors: {}
},
states: {
invalid: {
on: {
SUBMIT: 'loading'
}
},
loading: {
invoke: {
id: 'sendInfo',
src: (context) => sendInfo(context),
onDone: {
actions: send('SUCCESS')
},
onError: {
actions: send('ERROR')
}
},
on: {
SUCCESS: {
actions: [sendParent('SUCCESS')]
},
ERROR: {
target: 'invalid',
actions: []
}
}
}
}
})
const phoneVerificationMachine = Machine({
id: 'phoneVerification',
initial: 'invalid',
context: {
fields: {
verificationCode: ''
},
}
})
const driverSignup = Machine({
id: 'driverSignup',
initial: 'driverInfo',
context: {
driverInfo: null,
driverInfoMachineRef: null
},
states: {
driverInfo: {
entry: [assign({
driverInfoMachineRef: () => spawn(driverInfoMachine)
})],
on: {
SUCCESS: 'phoneVerification'
}
},
phoneVerification: {
on: {
BACK: 'driverInfo',
SUBMIT: '',
NEXT: 'dgd',
RESEND: {
actions: ['resendSMS']
}
}
},
dgd: {
on: {
INDICATE: '',
NEXT: 'terms'
}
},
terms: {
on: {
BACK: {
target: 'dgd',
cond: 'canGoBackToDGD'
},
ACCEPT: 'registred'
},
},
registred: {
type: 'final'
}
}
}, {
guards: {
canGoBackToDGD: (context) => { !context.referralCode }
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment