Skip to content

Instantly share code, notes, and snippets.

@grncdr
Last active August 6, 2019 15:46
Show Gist options
  • Save grncdr/a27aa9e9790879034a69877b061bef35 to your computer and use it in GitHub Desktop.
Save grncdr/a27aa9e9790879034a69877b061bef35 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const invoiceMachine = Machine({
id: 'invoice',
initial: 'open',
states: {
open: {
on: {
CLOSE: {
target: 'closed',
actions: [
'open_next_invoice',
'send_email'
]
}
}
},
closed: {
on: {
ADD_POSITION: 'closed',
},
initial: 'unassociated',
states: {
unassociated: {
on: {
AWAIT_MANUAL_PAYMENT: 'awaiting_manual_payment',
ADD_TO_CDD: 'associated'
}
},
associated: {
on: {
CDD_UPLOADED: '#invoice.frozen',
REMOVE_FROM_CDD: 'unassociated'
}
},
awaiting_manual_payment: {
on: {
PAYMENT: [{
target: '#invoice.frozen.successful',
cond: 'paid_in_full'
}, {
target: '#invoice.frozen.payable'
}]
}
}
}
},
frozen: {
initial: 'payable',
entry: ['send_email'],
states: {
payable: {
on: {
PAYMENT: {
target: 'successful',
cond: 'paid_in_full'
},
PAYMENT_REVERSED: {
target: 'failed'
},
WRITE_OFF: {
target: 'written_off'
}
}
},
failed: {
on: {
PAYMENT: {
target: 'successful',
cond: 'paid_in_full'
},
ADD_TO_CDD: 'failed',
WRITE_OFF: {
target: 'written_off'
}
}
},
successful: {
on: {
PAYMENT_REVERSED: {
target: 'failed'
}
}
},
written_off: {
on: {
PAYMENT: {
target: 'successful',
cond: 'paid_in_full'
},
ADD_TO_CDD: 'written_off',
}
}
}
}
}
}, {
guards: {
paid_in_full: () => true
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment