Skip to content

Instantly share code, notes, and snippets.

@duranmla
Last active September 9, 2020 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duranmla/50ecf807d3b9c049fc58cda690f90594 to your computer and use it in GitHub Desktop.
Save duranmla/50ecf807d3b9c049fc58cda690f90594 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 donationWizardMachine = Machine({
id: 'donation',
initial: 'amountForm',
states: {
amountForm: {
initial: 'donateOnce',
states: {
donateOnce: {
on: {
NEXT: '#donation.paymentForm',
'START.MONTHLY': 'donateMonthly'
}
},
donateMonthly: {
on: {
NEXT: '#donation.paymentForm',
'START.ONCE': 'donateOnce'
}
},
hist: {
type: 'history',
history: 'shallow'
}
}
},
paymentForm: {
initial: 'cardForm',
states: {
cardForm: {
on: {
NEXT: [{ target: 'addressForm', cond: 'paymentFormCompleted' }],
PREV: '#donation.amountForm.hist',
'START.ONCE': '#donation.amountForm.donateOnce',
'START.MONTHLY': '#donation.amountForm.donateMonthly'
}
},
addressForm: {
on: {
NEXT: [
{
target: '#donation.processDonation',
cond: 'addressFormCompleted'
}
],
PREV: 'cardForm',
'START.ONCE': '#donation.amountForm.donateOnce',
'START.MONTHLY': '#donation.amountForm.donateMonthly'
}
}
}
},
processDonation: {
invoke: {
id: 'submitDonation',
src: (context, event) => sendDonation(context.userId),
onDone: {
target: 'success',
actions: assign({ donation: (context, event) => event.data })
},
onError: {
target: 'failure',
actions: assign({ error: (context, event) => event.data })
}
}
},
success: {
type: 'final'
},
failure: {
on: {
RETRY: { target: '#donation.paymentForm.addressForm' }
}
}
}
},
{
guards: {
paymentFormCompleted: (context, event) => {
// this needs to be implemented
return true;
},
addressFormCompleted: (context, event) => {
// this needs to be implemented
return true
}
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment