Skip to content

Instantly share code, notes, and snippets.

@omofolarin
Last active December 19, 2019 10:55
Show Gist options
  • Save omofolarin/8f57134c66982bc85287a09376676125 to your computer and use it in GitHub Desktop.
Save omofolarin/8f57134c66982bc85287a09376676125 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 submitPhone = (whatsappNo) => {
return true;
}
const toggleMachine = Machine({
context: {
error: null,
isVerified: false,
phoneSubmitStatus: null
},
id: 'whatsAppVerifyModal',
initial: 'enterPhone',
states: {
enterPhone: {
initial: 'idle',
states: {
idle: {
on: { SUMIT: 'submit' }
},
error:{},
loading:{},
submit:{
on: { start: 'loading'},
invoke: {
id: 'submitWhatsAppNo',
onDone: {
actions: assign({
error: null,
phoneSubmitStatus: 'successful'
}),
on: { type: 'TOGGLE_VERIFY_PHONE' }
},
onError: {
actions: assign({ phoneSubmitStatus: 'failed', error: (context, event) => event.data }),
target: 'error'
},
src: (context, event) => {
return submitPhone(event.whatsappNo);
}
}
}
}
},
verifyPhone: {
}
},
on: {
TOGGLE_PHONE_ENTRY: { target: '.enterPhone', internal:false },
TOGGLE_VERIFY_PHONE: { target: '.verifyPhone', internal: false }
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment