Last active
March 31, 2020 17:32
-
-
Save rjdestigter/4bf836c8e96f2fbe88bf4718f97f9997 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or 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 goToEvents = { | |
goToProfileInformation: 'fillOutProfileInformation', | |
goToProductsBrands: 'productsAndBrands', | |
goToServiceAreas: 'serviceAreas', | |
goToScheduleAvailability: 'scheduleAvailability', | |
goToSetUpTechnicians: 'setUpTechnicians' | |
} | |
const M = Machine({ | |
id: 'sbxui', | |
initial: '_', | |
context: { | |
authenticated: false, | |
signedUp: false, | |
}, | |
on: { | |
linkToTermsAndConditions: '', | |
linkToPrivacyPolicy: '', | |
clickLogoutButton: { | |
target: 'landingPage', | |
cond: ctx => ctx.authenticated, | |
actions: assign({authenticated: false}) | |
} | |
}, | |
states: { | |
_: { | |
on: { | |
'Navigate to landing page': 'landingPage', | |
'Navigate to login page': 'login', | |
'Invite via email for existing SPs': 'login', | |
'Navigate to sign-up': 'fillOutProfileInformation', | |
'Link via authenticated SB.com session': 'singleClickSigup', | |
'Link via authenticated SB.com session for user with BMS/Self-dispatch': {target: 'productsAndBrands', actions: assign({signedUp: true})} | |
}, | |
}, | |
landingPage: { | |
on: { | |
goToLogin: 'login', | |
goToSignUp: 'fillOutProfileInformation' | |
} | |
}, | |
login: { | |
on: { | |
clickSignUpButton: 'fillOutProfileInformation', | |
}, | |
initial: 'fillOutForm', | |
states: { | |
fillOutForm: { | |
on: { | |
submitLoginButton: 'busyAuthenticating' | |
} | |
}, | |
busyAuthenticating: { | |
on: { | |
authenticatedAsReturningBmsUser: { | |
target: '#sbxui.productsAndBrands', | |
actions: assign({ authenticated: true, signedUp: true }) | |
}, | |
authenticatedAsServiceProviderWithNoBMS: { | |
target: '#sbxui.singleClickSigup', | |
actions: assign({ authenticated: true }) | |
} | |
} | |
}, | |
} | |
}, | |
fillOutProfileInformation: { | |
initial: 'accountInformation', | |
on: { | |
CONTINUE: [ | |
{ target: 'acceptEula', cond: ctx => !ctx.signedUp }, | |
{ target: 'premiumServices' }, | |
], | |
}, | |
states: { | |
accountInformation: { | |
on: { | |
'': { | |
target: 'securityQuestions', | |
cond: ctx => ctx.authenticated, | |
}, | |
goToSecurityQuestions: 'securityQuestions', | |
goToContactInformation: 'contactInformation', | |
goToCompanyAddres: 'companyAddress' | |
} | |
}, | |
securityQuestions: { | |
on: { | |
goToAccountInformation: { | |
target: 'accountInformation', | |
cond: ctx => !ctx.authenticated, | |
}, | |
goToContactInformation: 'contactInformation', | |
goToCompanyAddres: 'companyAddress' | |
} | |
}, | |
contactInformation: { | |
on: { | |
goToAccountInformation: { | |
target: 'accountInformation', | |
cond: ctx => !ctx.authenticated, | |
}, | |
goToSecurityQuestions: 'securityQuestions', | |
goToCompanyAddres: 'companyAddress' | |
} | |
}, | |
companyAddress: { | |
on: { | |
goToAccountInformation: { | |
target: 'accountInformation', | |
cond: ctx => !ctx.authenticated, | |
}, | |
goToSecurityQuestions: 'securityQuestions', | |
goToContactInformation: 'contactInformation' | |
} | |
}, | |
} | |
}, | |
singleClickSigup: { | |
on: { | |
YES: 'acceptEula', | |
NO: 'productsAndBrands' | |
} | |
}, | |
acceptEula: { | |
on: { | |
ACCEPT: { | |
target: 'premiumServices', | |
actions: assign({ | |
signedUp: true, | |
authenticated: true | |
}) | |
}, | |
DECLINE: 'declinedEULA' | |
} | |
}, | |
premiumServices: { | |
on: goToEvents, | |
}, | |
productsAndBrands: { | |
on: goToEvents, | |
}, | |
serviceAreas: { | |
on: goToEvents, | |
}, | |
scheduleAvailability: { | |
on: goToEvents, | |
}, | |
setUpTechnicians: { | |
on: goToEvents, | |
}, | |
confirmationPage: {}, | |
declinedEULA: { | |
after: { | |
1000: { | |
actions: send('clickLogoutButton') | |
} | |
} | |
}, | |
}, | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment