Skip to content

Instantly share code, notes, and snippets.

@DaveHudson
Last active August 18, 2020 18:30
Show Gist options
  • Save DaveHudson/b818e164caed65554fecdc1f8f70a3ee to your computer and use it in GitHub Desktop.
Save DaveHudson/b818e164caed65554fecdc1f8f70a3ee 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 orderMachine = Machine({
id: 'payment',
initial: 'getPrintfulProducts',
context: {
printfulProducts: [],
cartValid: false
},
states: {
getPrintfulProducts: {
invoke: {
src: 'fetchPrintfulProducts',
onDone: {
target: 'validateCart',
actions: ['setProductsContext'],
},
onError: 'failure',
},
},
validateCart: {
invoke: {
src: 'validateShoppingCart',
onDone: {
target: 'requestPayment',
actions: ['setCartValidContext'],
},
onError: 'failure',
},
},
requestPayment: {
invoke: {
src: 'APIPaymentIntent',
onDone: {
target: 'createPrintfulOrder',
actions: ['setPaymentIntentContext'],
},
onError: 'failure',
},
},
createPrintfulOrder: {
invoke: {
src: 'updateOrderStatus',
onDone: {
target: 'updateOrderStatus',
actions: ['setPrintfulOrderContext']
},
onError: 'failure'
}
},
updateOrderStatus: {
invoke: {
src: 'APIUpdateOrder',
onDone: {
target: 'sendOrderConfirmation',
actions: ['setOrderContext']
},
onError: 'failure'
}
},
sendOrderConfirmation: {
invoke: {
src: 'APISendEmailConfirmation',
onDone: {
target: 'success',
actions: ['setEmailContext']
},
onError: 'failure'
}
},
success: {
type: 'final'
},
failure: {
type: 'final'
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment