Last active
February 15, 2021 13:23
-
-
Save cervmi/ddfc1a903e9d153dd40e5ffea63cdc69 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const MetrakContainerOrderWithCOD = Machine({ | |
id: "MetrakContainerOrderWithCOD", | |
initial: "Initial", | |
context: { | |
orderContent: { | |
cod: false, | |
orderContentState: 'initial' | |
}, | |
supplier: { | |
substituteSupplierId: 3, | |
autoApproveOrders: false | |
} | |
}, | |
states: { | |
Initial: { | |
on: { | |
NEW: [ | |
{ | |
target: 'ForSupplierToConfirm', | |
cond: 'isCODAndAutoApprove', | |
actions: ['createProformaInvoice', 'orderSummaryEmailToClient', 'orderSummaryEmailToAdmin', 'orderOfferEmailToSupplier'], | |
}, | |
{ | |
target: 'ForAdminToApprove', | |
cond: 'isCOD', | |
actions: ['createProformaInvoice', 'orderSummaryEmailToClient', 'orderApprovalEmailToAdmin'], | |
}, | |
{ | |
target: 'WaitingForPayment', | |
actions: ['orderSummaryEmailToClient', 'orderSummaryEmailToAdmin'], | |
} | |
] | |
} | |
}, | |
WaitingForPayment: { | |
on: { | |
PAY: [ | |
{ | |
target: 'ForSupplierToConfirm', | |
cond: 'isAutoApprove', | |
actions: ['createFullInvoice', 'paymentConfirmationEmailToClient', 'orderOfferEmailToSupplier'], | |
}, | |
{ | |
target: 'ForAdminToApprove', | |
actions: ['createFullInvoice', 'paymentConfirmationEmailToClient', 'orderApprovalEmailToAdmin'], | |
} | |
], | |
CANCEL_BY_ADMIN: { | |
target: 'Cancelled', | |
actions: ['orderCancelledEmailToClient'], | |
} | |
} | |
}, | |
ForAdminToApprove: { | |
on: { | |
CANCEL_BY_ADMIN: { | |
target: 'Cancelled', | |
actions: ['deleteInvoice', 'orderCancelledEmailToClient'], | |
}, | |
APPROVE: { | |
target: 'ForSupplierToConfirm', | |
actions: ['orderOfferEmailToSupplier', 'setApprovedByColumn'], | |
}, | |
} | |
}, | |
ForSupplierToConfirm: { | |
on: { | |
CANCEL_BY_SUPPLIER: [{ | |
target: 'ForSubstituteSupplierToConfirm', | |
cond: 'hasSubstituteSupplier', | |
actions: ['setOrderContentReason', 'switchSupplierToSubstituteOnOrder', 'orderOfferEmailToSupplier'] | |
}, | |
{ | |
target: 'RefusedBySupplier', | |
actions: ['setOrderContentReason', 'sendRefusedBySupplierEmailToAdmin'] | |
}], | |
CANCEL_BY_ADMIN: { | |
target: 'Cancelled', | |
actions: ['deleteInvoice', 'orderCancelledEmailToClient', 'orderCancelledEmailToSupplier'], | |
}, | |
CONFIRM: { | |
target: 'ConfirmedBySupplier', | |
actions: ['sendSupplierConfirmedToClient'] | |
} | |
} | |
}, | |
ForSubstituteSupplierToConfirm: { | |
on: { | |
CANCEL_BY_SUPPLIER: [ | |
{ | |
target: 'RefusedBySubstituteSupplier', | |
actions: ['setOrderContentReason', 'sendRefusedBySupplierEmailToAdmin'] | |
}], | |
CANCEL_BY_ADMIN: { | |
target: 'Cancelled', | |
actions: ['deleteInvoice', 'orderCancelledEmailToClient', 'orderCancelledEmailToSupplier'], | |
}, | |
CONFIRM: { | |
target: 'ConfirmedBySupplier', | |
actions: ['sendSupplierConfirmedToClient'] | |
} | |
} | |
}, | |
RefusedBySupplier: { | |
on: { | |
CANCEL_BY_ADMIN: [ | |
{ | |
target: 'Cancelled', | |
actions: ['deleteInvoice', 'orderCancelledEmailToClient'] | |
}], | |
APPROVE: { | |
target: 'ForSupplierToConfirm', | |
actions: ['orderOfferEmailToSupplier'] | |
} | |
} | |
}, | |
RefusedBySubstituteSupplier: { | |
on: { | |
CANCEL_BY_ADMIN: [ | |
{ | |
target: 'Cancelled', | |
actions: ['deleteInvoice', 'orderCancelledEmailToClient'] | |
}], | |
APPROVE: { | |
target: 'ForSupplierToConfirm', | |
actions: ['orderOfferEmailToSupplier'] | |
} | |
} | |
}, | |
ConfirmedBySupplier: { | |
on: { | |
CONTAINER_ARRIVE: { | |
target: 'ContainerArrived', | |
actions: ['sendContainerArrivedToClient'] | |
}, | |
CANCEL_BY_ADMIN: { | |
target: 'Cancelled', | |
actions: ['deleteInvoice', 'orderCancelledEmailToClient', 'orderCancelledEmailToSupplier'], | |
}, | |
CANCEL_BY_SUPPLIER: { | |
target: 'RefusedBySupplier', | |
actions: ['setOrderContentReason', 'sendRefusedBySupplierEmailToAdmin'] | |
} | |
} | |
}, | |
ContainerArrived: { | |
on: { | |
CONTAINER_TAKE: [ | |
{ | |
target: 'ContainerTakenBack', | |
cond: 'isCOD', | |
actions: ['updateInvoiceFromProformaToFull', 'sendContainerTakenBackToClient'] | |
}, | |
{ | |
target: 'ContainerTakenBack', | |
actions: ['sendContainerTakenBackToClient'] | |
} | |
], | |
CANCEL_BY_ADMIN: { | |
target: 'Cancelled', | |
actions: ['deleteInvoice', 'orderCancelledEmailToClient', 'orderCancelledEmailToSupplier'], | |
}, | |
CANCEL_BY_SUPPLIER: { | |
target: 'RefusedBySupplier', | |
actions: ['setOrderContentReason', 'sendRefusedBySupplierEmailToAdmin'] | |
} | |
} | |
}, | |
ContainerTakenBack: { | |
on: { | |
CONTAINER_FINISHED: { | |
target: 'ContainerFinishedBySupplier', | |
actions: ['sendContainerFinishedBySupplier'] | |
}, | |
CANCEL_BY_ADMIN: { | |
target: 'Cancelled', | |
actions: ['deleteInvoice', 'orderCancelledEmailToClient', 'orderCancelledEmailToSupplier'], | |
}, | |
CANCEL_BY_SUPPLIER: { | |
target: 'RefusedBySupplier', | |
actions: ['setOrderContentReason', 'sendRefusedBySupplierEmailToAdmin'] | |
} | |
} | |
}, | |
ContainerFinishedBySupplier: { | |
on: { | |
CONTAINER_CHARGED_BY_ADMIN: { | |
target: 'ContainerChargedByAdmin', | |
} | |
} | |
}, | |
ContainerChargedByAdmin: { | |
type: "final" | |
}, | |
Cancelled: { | |
type: "final" | |
}, | |
} | |
} | |
, | |
{ | |
guards: { | |
'isCOD': (context, event) => { | |
return context.orderContent.cod | |
}, | |
'isCODAndAutoApprove': (context, event) => { | |
return context.orderContent.cod && context.supplier.autoApproveOrders | |
}, | |
'supplierAutoApprove': (context, event) => { | |
return context.supplier.autoApproveOrders | |
}, | |
'hasSubstituteSupplier': (context, event) => { | |
return !!context.supplier.substituteSupplierId | |
} | |
} | |
} | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment