Skip to content

Instantly share code, notes, and snippets.

@PatrickJS
Created March 16, 2022 07:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PatrickJS/2e9af3404220d4e16fae860a05496cb2 to your computer and use it in GitHub Desktop.
Save PatrickJS/2e9af3404220d4e16fae860a05496cb2 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const routes = {
auth: {
login: "/auth/login",
reset: "/auth/reset-password"
},
apply: {
documents: "/apply/upload-docs",
income: "/apply/income",
name: "/apply/name",
review: "/apply/review",
start: "/apply",
success: "/apply/success",
}
};
// Conditions for some of our transitions
const guards = {
hasJobIncome: (context) => context.has_job_income === true
}
const routingMachine = Machine({
// Initial state is mostly useful for visualizations, for our purposes.
initial: routes.auth.login,
states: {
[routes.auth.login]: {
on: {
LOG_IN: routes.apply.start,
FORGOT_PASSWORD: routes.auth.reset,
}
},
[routes.auth.reset]: {
on: {
RESET: routes.auth.login
}
},
[routes.apply.start]: {
on: {
CONTINUE: routes.apply.name
}
},
[routes.apply.name]: {
on: {
CONTINUE: routes.apply.income
}
},
[routes.apply.income]: {
on: {
CONTINUE: [
{
cond: "hasJobIncome",
target: routes.apply.documents
},
{ target: routes.apply.review }
]
}
},
[routes.apply.documents]: {
on: {
CONTINUE: routes.apply.review
}
},
[routes.apply.review]: {
on: {
CONTINUE: routes.apply.success
}
},
[routes.apply.success]: {},
},
guards
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment