Skip to content

Instantly share code, notes, and snippets.

@eliseumds
Created February 11, 2021 16:18
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 eliseumds/bea0004ed57dcfd20a8b7864ec55eae5 to your computer and use it in GitHub Desktop.
Save eliseumds/bea0004ed57dcfd20a8b7864ec55eae5 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const machine = Machine({
id: 'subscriptionFlow',
initial: 'pickingBrand',
context: {
value: 'pickingBrand',
},
states: {
pickingBrand: {
on: {
PICK_BRAND: 'loadingBrand',
},
},
loadingBrand: {
entry: 'syncBrandSlugWithUrlParams',
invoke: {
src: 'loadBrand',
onDone: {
target: 'pickingPlan',
actions: assign({ brand: (context, event) => event.data }),
},
onError: {
target: 'pickingBrand',
actions: assign({ loadBrandError: (context, event) => event.data }),
},
},
},
pickingPlan: {
on: {
PICK_PLAN: 'pickingPayment',
},
},
pickingPayment: {
on: {
PICK_PAYMENT: 'viewingSummary',
},
},
viewingSummary: {
on: {
INITIATE_SUBSCRIPTION: 'initiatingSubscription',
},
},
initiatingSubscription: {
invoke: {
src: 'dispatchInitiateSubscription',
onDone: {
target: 'success',
},
onError: {
target: 'failure',
actions: assign({
initiateSubscriptionError: (context, event) => event.data,
}),
},
},
},
failure: {},
success: {
entry: 'redirectToBrandDashboard',
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment