Advertisement
Guest User

Untitled

a guest
Sep 11th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. const registrationMachine = Machine(
  2. {
  3. id: `registration`,
  4. initial: `codeEntry`,
  5. context: {
  6. user: undefined,
  7. },
  8. states: {
  9. codeEntry: {
  10. on: { SUBMIT: `submitting` },
  11. },
  12. captainEntry: {
  13. on: { SUBMIT: `submitting` },
  14. },
  15. teamEntry: {
  16. on: { SUBMIT: `submitting` },
  17. },
  18. photoEntry: {
  19. on: { SUBMIT: `submitting` },
  20. },
  21. submitting: {
  22. entry: [`clearError`],
  23. invoke: {
  24. id: `submitForm`,
  25. src: (context, event) => {
  26. return event.data.mutate(event.data.mutateProps);
  27. },
  28. onDone: [
  29. {
  30. target: `captainEntry`,
  31. cond: `userValid`,
  32. },
  33. {
  34. target: `error`,
  35. cond: `userNotValid`,
  36. },
  37. ],
  38. onError: {
  39. target: `error`,
  40. },
  41. },
  42. },
  43. error: {
  44. on: { SUBMIT: `submitting` },
  45. entry: [`setError`],
  46. },
  47. completed: {
  48. type: `final`,
  49. entry: [`redirectToDashboard`],
  50. },
  51. },
  52. },
  53. {
  54. actions: {
  55. redirectToDashboard: (context, event) => {
  56. window.FH.loggedin = true;
  57.  
  58. const user = event.data.person;
  59. console.log(user);
  60.  
  61. if (user.isSuperuser) window.FH.ut = `superuser`;
  62. else if (user.isManager) window.FH.ut = `manager`;
  63. else if (user.isStaff) window.FH.ut = `staff`;
  64. else window.FH.ut = `user`;
  65.  
  66. history.push(Routes.CURRENT_HUNTS);
  67. },
  68. setError: (context, event) => {
  69. return setLoginError(event.data.error);
  70. },
  71. clearError: (context, event) => setLoginError(null),
  72. },
  73. guards: {
  74. userValid: (context, event) => {
  75. return event.data && event.data.person;
  76. },
  77. userNotValid: (context, event) => {
  78. return !event.data || !event.data.person;
  79. },
  80. },
  81. },
  82. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement