Created
December 2, 2021 09:18
-
-
Save brunogarcia/4a85bbecbb8334a334e96e81e0849fc2 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 authorizationStepConfig = {}; | |
const selectingCardStepConfig = {}; | |
const cardLimitStepConfig = {}; | |
const personalInfoStepConfig = {}; | |
const employementInfoStepConfig = {}; | |
const accountInfoStepConfig = {}; | |
const additionalInfoStepConfig = {}; | |
const beneficialOwnerStepConfig = {}; | |
const processingFormStepConfig = {}; | |
const approvedStepConfig = {}; | |
const authorizationTechnicalErrorStepConfig = {}; | |
const age12ErrorStepConfig = {}; | |
const age18ErrorStepConfig = {}; | |
const authorizationErrorStepConfig = {}; | |
const contractErrorStepConfig = {}; | |
const selectingCardCreditStepConfig = {}; | |
const declinedStepConfig = {}; | |
const debitCardStepConfig = {}; | |
const creditCardGoldStepConfig = {}; | |
const fetchMachine = Machine( { | |
id: 'orderCard', | |
initial: 'open', | |
states: { | |
open: { | |
initial: 'authorization', | |
states: { | |
authorization: { | |
initial: 'pending', | |
states: { | |
pending: { | |
meta: { | |
...authorizationStepConfig, | |
}, | |
invoke: { | |
src: 'authorize', | |
onDone: [ | |
{ | |
target: 'contractError', | |
cond: 'authorizationContractBlock', | |
}, | |
{ | |
target: 'age12Error', | |
cond: 'authorizationAge12Block', | |
}, | |
{ | |
target: '#orderCard.open.selectCardType', | |
actions: 'saveAuthorizationResponse', | |
}, | |
], | |
onError: [ | |
{ | |
target: 'contractError', | |
cond: 'authorizationContractError', | |
}, | |
{ | |
target: 'technicalError', | |
}, | |
], | |
}, | |
}, | |
technicalError: { | |
entry: 'saveTechnicalErrorCode', | |
meta: { | |
...authorizationTechnicalErrorStepConfig, | |
}, | |
on: { | |
SECONDARY_ACTION: '#orderCard.closed', | |
PRIMARY_ACTION: 'pending', | |
CLOSE_FLOW: '#orderCard.closed', | |
}, | |
}, | |
age12Error: { | |
entry: 'saveAge12ErrorCode', | |
meta: { | |
...age12ErrorStepConfig, | |
}, | |
on: { | |
PRIMARY_ACTION: '#orderCard.closed', | |
CLOSE_FLOW: '#orderCard.closed', | |
}, | |
}, | |
age18Error: { | |
entry: 'saveAge18ErrorCode', | |
meta: { | |
...age18ErrorStepConfig, | |
}, | |
on: { | |
PRIMARY_ACTION: '#orderCard.closed', | |
CLOSE_FLOW: '#orderCard.closed', | |
PREVIOUS_STEP: '#orderCard.open.selectCardType', | |
}, | |
}, | |
authorizationError: { | |
entry: 'saveErrorCode', | |
meta: { | |
...authorizationErrorStepConfig, | |
}, | |
on: { | |
PRIMARY_ACTION: { actions: 'callServiceLine' }, | |
SECONDARY_ACTION: '#orderCard.closed', | |
CLOSE_FLOW: '#orderCard.closed', | |
PREVIOUS_STEP: '#orderCard.open.selectCardType', | |
}, | |
}, | |
contractError: { | |
entry: 'saveContractErrorCode', | |
meta: { | |
...contractErrorStepConfig, | |
}, | |
on: { | |
PRIMARY_ACTION: { actions: 'callServiceLine' }, | |
SECONDARY_ACTION: '#orderCard.closed', | |
CLOSE_FLOW: '#orderCard.closed', | |
}, | |
}, | |
}, | |
}, | |
selectCardType: { | |
initial: 'selecting', | |
on: { | |
CLOSE_FLOW: '#orderCard.closed', | |
}, | |
states: { | |
selecting: { | |
initial: 'idle', | |
meta: { | |
...selectingCardStepConfig, | |
}, | |
states: { | |
validationOk: { | |
on: { RESET_SNACKBAR: 'idle' }, | |
}, | |
idle: {}, | |
}, | |
on: { | |
SELECT_CREDIT: [ | |
{ | |
cond: 'authorizationAge18Block', | |
target: '#orderCard.open.authorization.age18Error', | |
}, | |
{ | |
cond: 'hasAuthorizationErrors', | |
target: | |
'#orderCard.open.authorization.authorizationError', | |
}, | |
{ | |
target: '#orderCard.open.selectCardType.credit', | |
}, | |
], | |
SELECT_DEBIT: 'debitUnavailable', | |
}, | |
}, | |
credit: { | |
meta: { | |
...selectingCardCreditStepConfig, | |
}, | |
on: { | |
SELECT_CREDIT_GOLD: 'creditGoldUnavailable', | |
SELECT_CREDIT_VISA_FREE: [ | |
{ | |
cond: 'disabledCreditVisaFree', | |
actions: 'redirectOrderCard', | |
}, | |
{ | |
target: '#orderCard.open.form.input', | |
}, | |
], | |
}, | |
}, | |
debitUnavailable: { | |
meta: { | |
...debitCardStepConfig, | |
}, | |
on: { | |
PREVIOUS_STEP: 'selecting', | |
}, | |
}, | |
creditGoldUnavailable: { | |
meta: { | |
...creditCardGoldStepConfig, | |
}, | |
on: { | |
PREVIOUS_STEP: 'credit', | |
}, | |
}, | |
}, | |
}, | |
form: { | |
type: 'parallel', | |
states: { | |
input: { | |
initial: 'cardLimitStep', | |
on: { | |
CLOSE_FLOW: '#orderCard.open.form.closeConfirmation.open', | |
UPDATE_FORM: { | |
actions: 'updateForm', | |
}, | |
}, | |
states: { | |
cardLimitStep: { | |
meta: { | |
...cardLimitStepConfig, | |
}, | |
on: { | |
NEXT_STEP: 'personalInfoStep', | |
PREVIOUS_STEP: | |
'#orderCard.open.selectCardType.selecting', | |
}, | |
}, | |
personalInfoStep: { | |
meta: { | |
...personalInfoStepConfig, | |
}, | |
on: { | |
PREVIOUS_STEP: 'cardLimitStep', | |
NEXT_STEP: 'employementInfoStep', | |
}, | |
}, | |
employementInfoStep: { | |
meta: { | |
...employementInfoStepConfig, | |
}, | |
on: { | |
PREVIOUS_STEP: 'personalInfoStep', | |
NEXT_STEP: 'accountInfoStep', | |
}, | |
}, | |
accountInfoStep: { | |
meta: { | |
...accountInfoStepConfig, | |
}, | |
on: { | |
PREVIOUS_STEP: 'employementInfoStep', | |
NEXT_STEP: 'additionalInfoStep', | |
}, | |
}, | |
additionalInfoStep: { | |
meta: { | |
...additionalInfoStepConfig, | |
}, | |
on: { | |
PREVIOUS_STEP: 'accountInfoStep', | |
NEXT_STEP: 'beneficialOwnerStep', | |
}, | |
}, | |
beneficialOwnerStep: { | |
initial: 'ok', | |
meta: { | |
...beneficialOwnerStepConfig, | |
}, | |
on: { | |
PREVIOUS_STEP: 'additionalInfoStep', | |
NEXT_STEP: '#orderCard.open.processing', | |
}, | |
states: { | |
ok: {}, | |
error: { | |
exit: 'resetRequestError', | |
on: { | |
RESET_SNACKBAR: 'ok', | |
}, | |
}, | |
}, | |
}, | |
}, | |
}, | |
closeConfirmation: { | |
initial: 'closed', | |
states: { | |
open: { | |
always: { | |
target: '#orderCard.closed', | |
cond: 'formPristine', | |
}, | |
on: { | |
CANCEL_CLOSE: 'closed', | |
CONFIRM_CLOSE: '#orderCard.closed', | |
}, | |
}, | |
closed: {}, | |
}, | |
}, | |
}, | |
}, | |
processing: { | |
meta: { | |
...processingFormStepConfig, | |
}, | |
on: { | |
NEXT_STEP: '#orderCard.open.form.input.beneficialOwnerStep', | |
}, | |
invoke: { | |
src: 'orderCard', | |
onDone: [ | |
{ | |
target: '#orderCard.open.declined', | |
cond: 'cardDeclined', | |
}, | |
{ | |
target: '#orderCard.open.approved', | |
cond: 'cardApproved', | |
actions: 'saveActivationUrl', | |
}, | |
{ | |
target: '#orderCard.open.approved', | |
actions: 'saveActivationUrl', | |
}, | |
], | |
onError: { | |
actions: assign({ | |
requestError: (context, event) => event.data.response.data, | |
}), | |
target: | |
'#orderCard.open.form.input.beneficialOwnerStep.error', | |
}, | |
}, | |
}, | |
approved: { | |
meta: { | |
...approvedStepConfig, | |
}, | |
on: { | |
NEXT_STEP: { actions: 'redirectToActivate' }, | |
CLOSE_FLOW: '#orderCard.closed', | |
}, | |
exit: 'resetActivationUrl', | |
}, | |
declined: { | |
meta: { | |
...declinedStepConfig, | |
}, | |
on: { | |
PRIMARY_ACTION: '#orderCard.closed', | |
CLOSE_FLOW: '#orderCard.closed', | |
}, | |
}, | |
}, | |
}, | |
closed: {}, | |
}, | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment