Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const registrationMachine = Machine(
- {
- id: `registration`,
- initial: `codeEntry`,
- context: {
- user: undefined,
- },
- states: {
- codeEntry: {
- on: { SUBMIT: `submitting` },
- },
- captainEntry: {
- on: { SUBMIT: `submitting` },
- },
- teamEntry: {
- on: { SUBMIT: `submitting` },
- },
- photoEntry: {
- on: { SUBMIT: `submitting` },
- },
- submitting: {
- entry: [`clearError`],
- invoke: {
- id: `submitForm`,
- src: (context, event) => {
- return event.data.mutate(event.data.mutateProps);
- },
- onDone: [
- {
- target: `captainEntry`,
- cond: `userValid`,
- },
- {
- target: `error`,
- cond: `userNotValid`,
- },
- ],
- onError: {
- target: `error`,
- },
- },
- },
- error: {
- on: { SUBMIT: `submitting` },
- entry: [`setError`],
- },
- completed: {
- type: `final`,
- entry: [`redirectToDashboard`],
- },
- },
- },
- {
- actions: {
- redirectToDashboard: (context, event) => {
- window.FH.loggedin = true;
- const user = event.data.person;
- console.log(user);
- if (user.isSuperuser) window.FH.ut = `superuser`;
- else if (user.isManager) window.FH.ut = `manager`;
- else if (user.isStaff) window.FH.ut = `staff`;
- else window.FH.ut = `user`;
- history.push(Routes.CURRENT_HUNTS);
- },
- setError: (context, event) => {
- return setLoginError(event.data.error);
- },
- clearError: (context, event) => setLoginError(null),
- },
- guards: {
- userValid: (context, event) => {
- return event.data && event.data.person;
- },
- userNotValid: (context, event) => {
- return !event.data || !event.data.person;
- },
- },
- },
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement