Skip to content

Instantly share code, notes, and snippets.

@grncdr
Last active May 5, 2020 15:44
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save grncdr/98c64cfe26be90a058c8d70a2665a778 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine({
id: 'Order',
type: 'parallel',
context: {
has_bank_info: false
},
states: {
payment: {
initial: 'estimated',
states: {
estimated: {
on: {
ENTER_BANK_INFO: {
target: 'estimated',
actions: ['save_bank_info']
},
RECEIVE: {
target: 'invoice_sent',
actions: [
'create_invoice',
'send_invoice'
]
}
},
},
invoice_sent: {
on: {
'': {
target: 'payment_created',
cond: 'has_bank_info',
actions: ['submit_sepa_cct']
},
PAY_PAL_RECEIVED: {
target: 'payment_created'
},
ENTER_BANK_INFO: {
target: 'invoice_sent',
actions: ['save_bank_info']
}
}
},
payment_created: {
final: true
}
},
},
shipment: {
initial: 'none',
states: {
none: {
on: {
REQUEST_PICK_UP: 'pick_up_pending',
PRINT_LABEL: 'shipment_pending',
},
},
pick_up_pending: {
on: {
PICK_UP: 'picked_up',
},
},
shipment_pending: {
on: {
CARRIER_RECEIVED: 'shipped',
},
},
picked_up: {
on: {
RECEIVE: 'in_production',
},
},
shipped: {
on: {
RECEIVE: 'in_production',
},
},
in_production: {
initial: 'awaiting_payment',
states: {
awaiting_payment: {
on: {
PAYMENT_CREATED: 'processing',
},
},
processing: {
on: {
SCAN_FINISHED: 'scanning_complete',
},
},
scanning_complete: {
on: {
RETURN_VIA_DROP_OFF: '#Order.shipment.drop_off_pending',
RETURN_VIA_POST: '#Order.shipment.return_shipment_pending',
ARCHIVE: '#Order.shipment.archived',
DESTROY: '#Order.shipment.destroyed',
},
},
},
},
destroyed: {
final: true,
},
archived: {
on: {
READY_FOR_DROP_OFF: 'drop_off_pending',
READY_FOR_RETURN: 'return_shipment_pending',
},
},
drop_off_pending: {
on: {
PICK_UP: 'out_for_drop_off',
},
},
return_shipment_pending: {
on: {
CARRIER_PICK_UP: 'shipped_back',
},
},
out_for_drop_off: {
on: {
TRY_AGAIN: 'drop_off_pending',
DROP_OFF: 'dropped_off',
},
},
shipped_back: {
final: true,
},
dropped_off: {
final: true,
},
},
},
},
}, {
actions: {
save_bank_info: assign({
bank_info: () => true
})
},
guards: {
has_bank_info: (context) => context.bank_info
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment