Last active
June 27, 2021 17:52
-
-
Save sawyerh/0fa11f317c50c86bd5a058253124414e 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 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