Skip to content

Instantly share code, notes, and snippets.

@rjdestigter
Created March 11, 2020 19:20
Show Gist options
  • Save rjdestigter/cd864ad98804afd367bd69d0d4893dfc to your computer and use it in GitHub Desktop.
Save rjdestigter/cd864ad98804afd367bd69d0d4893dfc to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const fetchMachine = Machine({
id: 'bmsEnable',
initial: 'loginForm',
context: {
retries: 0
},
states: {
loginForm: {
initial: 'emptyForm',
states: {
emptyForm: {
on: {
FILLOUT: 'filledOutForm',
},
},
filledOutForm: {
on: {
SUBMIT: '#bmsEnable.submitting'
}
},
}
},
submitting: {
on: {
AUTHENTICATED: 'signUp',
BAD_USERNAME_OR_PASSWORD: 'loginForm',
NO_CONNECTION: 'failed',
API_BUG: 'failed',
SERVER_DOWN: 'failed',
NOT_A_SP_FOR_WHIRLPOOL: 'notAllowed',
ALREADY_HAS_BMS: 'notAllowed',
ACCOUNT_IS_NOT_A_SP: 'notAllowed',
}
},
failed: {
on: {
TRY_AGAIN: 'loginForm'
},
after: {
5000: 'loginForm'
}
},
notAllowed: {
after: {
2500: 'loginForm'
}
},
signUp: {
initial: 'signUpButton',
states: {
signUpButton: {
on: {
YES: 'signingUp',
NO: '#bmsEnable.loginForm'
}
},
signingUp: {
on: {
NO_CONNECTION: 'failedToSignUp',
API_BUG: 'failedToSignUp',
SERVER_DOWN: 'failedToSignUp',
SIGNED_UP: 'confirmationPage'
}
},
failedToSignUp: {
on: {
TRY_AGAIN: 'signingUp',
CANCEL: '#bmsEnable.loginForm'
}
},
confirmationPage: {
after: {
2500: '#bmsEnable.loginForm',
},
},
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment