Created
November 6, 2019 14:18
-
-
Save gustavo-depaula/c4bcd39ae4473d6d17c6ab9ddbe18e31 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 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