Last active
January 13, 2021 21:48
-
-
Save dburrows/b3590bfd6a62e6935716ea14de91d0ac 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 fetchMachine = Machine({ | |
id: 'bulk-payment-upload', | |
initial: 'loadPrerequisiteData', | |
context: {}, | |
states: { | |
loadPrerequisiteData: { | |
on: { | |
LOADED: { | |
target: 'showUploadInterface', | |
actions: 'setAccountInfo' | |
} | |
} | |
}, | |
showUploadInterface: { | |
on: { | |
UPLOAD: { | |
target: 'validationLoading', | |
actions: 'updateFile' | |
} | |
} | |
}, | |
validationLoading: { | |
invoke: { | |
id: 'validateBulkPayment', | |
src: 'submitValidation', | |
onDone: { | |
target: 'showValidationResult', | |
actions: 'updateValidationResult' | |
}, | |
onError: { | |
target: 'showValidationError', | |
actions: ['updateError', 'logoutIfNotAuthorised'] | |
} | |
} | |
}, | |
showValidationError: { | |
// send error log via redux | |
on: { | |
RESUBMIT: 'validationLoading', | |
RESTART: 'showUploadInterface' | |
} | |
}, | |
showValidationResult: { | |
on: { | |
UPLOAD: 'showUploadInterface', | |
SUBMIT: { | |
target: 'submitSave', | |
actions: 'updateFormValues' | |
} | |
} | |
}, | |
submitSave: { | |
invoke: { | |
id: 'createBulkPayment', | |
src: 'submitSave', | |
onDone: [ | |
// multiple guarded transitions: https://xstate.js.org/docs/guides/guards.html#multiple-guards | |
// will test each one in sequence and do the first matched | |
{ | |
target: 'submitAuthorisation', | |
actions: 'saveBulkPaymentUid', | |
cond: 'isNotDraft' | |
}, | |
{ | |
target: 'navigateToSaved', | |
actions: 'saveBulkPaymentUid' | |
} | |
], | |
onError: { | |
target: 'showSaveError', | |
actions: ['updateError', 'logoutIfNotAuthorised'] | |
} | |
} | |
}, | |
showSaveError: { | |
// send error log via redux | |
on: { | |
RESUBMIT: 'submitSave', | |
RESTART: 'showUploadInterface' | |
} | |
}, | |
submitAuthorisation: { | |
invoke: { | |
id: 'authoriseBulkPayment', | |
src: 'submitAuthorisation', | |
onDone: { | |
target: 'navigateToSaved', | |
actions: 'saveConsentInformation' | |
}, | |
onError: { | |
target: 'showAuthorisationError', | |
actions: ['updateError', 'logoutIfNotAuthorised'] | |
} | |
} | |
}, | |
showAuthorisationError: { | |
on: { | |
RESUBMIT: 'submitAuthorisation', | |
RESTART: 'showUploadInterface' | |
} | |
}, | |
navigateToSaved: { | |
type: 'final' | |
} | |
} | |
},{ | |
guards: { | |
isNotDraft: () => true | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment