Skip to content

Instantly share code, notes, and snippets.

@jjenzz
Created October 4, 2019 08:30
Show Gist options
  • Save jjenzz/15fcc540ccad052c2423814a8bf0bb24 to your computer and use it in GitHub Desktop.
Save jjenzz/15fcc540ccad052c2423814a8bf0bb24 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const dismissMachine = Machine(
{
id: 'dismissMachine',
initial: 'load',
context: {
resolutions: [],
selectedRisksCount: 1,
resolutionId: undefined,
reason: undefined,
},
states: {
load: {
invoke: {
src: 'getResolutions',
onDone: [
{
cond: 'hasResponseError',
target: 'error.serverError',
},
{
cond: 'hasResolutions',
actions: ['setResolutions'],
target: 'form',
},
{
target: 'error.emptyResolutions',
},
],
onError: 'error.serverError',
},
on: {
CLICK_CANCEL: 'close',
CLICK_OUTSIDE: 'close',
},
},
form: {
on: {
CLICK_CANCEL: 'close',
CLICK_OUTSIDE: 'close',
INPUT_RESOLUTION: {
actions: ['setResolutionId'],
},
INPUT_REASON: {
actions: ['setReason'],
},
SUBMIT_FORM: [
{
cond: 'isValid',
target: 'save',
},
],
},
},
save: {
invoke: {
src: 'dismiss',
onDone: 'success',
onError: 'error.saveFailed',
},
},
success: {
invoke: {
src: 'getSelectedRisksCount',
onDone: {
actions: ['setSelectedRisksCount', 'handleSaveSuccess'],
},
},
on: { CLICK_CONFIRM: 'close' },
/* $FlowFixMe: Non-string literal property keys not supported. */
after: { 3000: 'close' },
},
error: {
on: {
CLICK_CANCEL: 'close',
CLICK_OUTSIDE: 'close',
},
states: {
emptyResolutions: {
meta: {
message: 'There are no resolution options available.',
},
},
serverError: {
meta: {
message: 'There was a problem loading resolutions.',
},
},
saveFailed: {
meta: {
message: 'There was a problem dismissing the risk.',
},
},
},
},
close: {
entry: 'handleClose',
type: 'final',
},
},
},
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment