Last active
March 20, 2020 07:57
-
-
Save sheminusminus/e543a0725ff8ab71d2f276a23b81debb 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
const billStates = { | |
initial: 'invalid', | |
states: { | |
invalid: {}, | |
valid: {}, | |
}, | |
}; | |
const stepStates = Machine({ | |
id: 'create-items', | |
initial: 'choose_vendor', | |
context: { | |
whatFor: null, | |
lineItems: [], | |
}, | |
states: { | |
choose_vendor: { | |
on: { | |
SET_VENDOR: 'create_or_select', | |
}, | |
}, | |
create_or_select: { | |
on: { | |
UNSET_VENDOR: 'choose_vendor', | |
SET_LINE_ITEMS: { | |
target: 'payment_details', | |
actions: assign({ | |
whatFor: () => 'lineItems', | |
lineItems: [{}], | |
}), | |
}, | |
SELECT_BILL: { | |
target: 'payment_details', | |
actions: assign({ | |
whatFor: () => 'bill', | |
}) | |
}, | |
}, | |
...billStates, | |
}, | |
payment_details: { | |
on: { | |
UNSET_VENDOR: 'choose_vendor', | |
DESELECT_BILL: { | |
target: 'create_or_select.invalid', | |
cond: ctx => ctx.whatFor === 'bill', | |
actions: assign({ | |
whatFor: () => null, | |
}), | |
}, | |
REMOVE_LINE_ITEMS: { | |
target: 'create_or_select.invalid', | |
cond: ctx => ctx.whatFor === 'lineItems', | |
actions: assign({ | |
whatFor: () => null, | |
lineItems: [], | |
}), | |
}, | |
SELECT_METHOD: 'can_submit', | |
}, | |
}, | |
can_submit: { | |
on: { | |
UNSET_VENDOR: 'choose_vendor', | |
DESELECT_METHOD: 'payment_details', | |
DESELECT_BILL: { | |
target: 'create_or_select.invalid', | |
cond: ctx => ctx.whatFor === 'bill', | |
actions: assign({ | |
whatFor: () => null, | |
}), | |
}, | |
REMOVE_LINE_ITEMS: { | |
target: 'create_or_select.invalid', | |
cond: ctx => ctx.whatFor === 'lineItems', | |
actions: assign({ | |
whatFor: () => null, | |
lineItems: [], | |
}), | |
}, | |
SUBMIT: 'submitting', | |
}, | |
}, | |
submitting: { | |
type: 'final', | |
} | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment