Last active
December 4, 2020 20:11
-
-
Save nahumt/ec4a8d0a958c41cffea544b8475fb821 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: 'checkout', | |
initial: 'Mexico', | |
context: { | |
user: '', | |
paymentType: 'online', | |
}, | |
states: { | |
'Mexico': { | |
on: { | |
GUEST: 'Method', | |
LOGIN: { | |
target: 'Method', | |
actions: 'onLogin', | |
} | |
}, | |
meta: { | |
message: 'Loading' | |
} | |
}, | |
'Method': { | |
on:{ | |
CARD: 'paymentSection.Stripeform', | |
PAYPAL: 'paymentSection.PaypalButton', | |
CASH: { | |
target: 'paymentSection.Conekta', | |
actions: 'setOffline', | |
} | |
}, | |
}, | |
paymentSection:{ | |
initial: 'Stripeform', | |
states: { | |
Stripeform: '', | |
PaypalButton: '', | |
Conekta: { | |
initial: 'OXXO', | |
states: { | |
OXXO: {}, | |
SPEI: {}, | |
} | |
}, | |
}, | |
onDone: 'processing', | |
}, | |
processing: { | |
on: { | |
SUCCESS: 'checkingAuth', | |
FAILED: 'rejected', | |
} | |
}, | |
checkingAuth: { | |
on: { | |
'': [ | |
{ | |
cond: 'isOnlineLogged', | |
target: 'Thanks', | |
}, | |
{ | |
cond: 'isOflineLogged', | |
target: 'payOrder' | |
}, | |
{ | |
target: 'CheckoutActivation', | |
}, | |
], | |
}, | |
}, | |
CheckoutActivation: { | |
on: { | |
SIGNUP: 'checkingMethod', | |
LOGIN: 'checkingMethod' | |
} | |
}, | |
checkingMethod: { | |
on: { | |
'': [ | |
{ | |
cond: 'isOnline', | |
target: 'Thanks' | |
}, | |
{ | |
target: 'payOrder' | |
} | |
] | |
} | |
}, | |
Thanks: { | |
type: 'final' | |
}, | |
payOrder: { | |
type: 'final' | |
}, | |
rejected: { | |
type: 'final' | |
}, | |
}}, { | |
guards: { | |
isOnlineLogged: (context) => { | |
return !!context.user && context.paymentType === 'online'; | |
}, | |
isOflineLogged: (context) => { | |
return !!context.user && context.paymentType === 'offline'; | |
}, | |
isOnline: (context) => { | |
return context.paymentType === 'online' | |
} | |
}, | |
actions: { | |
setOffline: assign({ | |
paymentType: 'offline' | |
}), | |
onLogin: assign({ | |
user: 'Lucas' | |
}) | |
}, | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment