You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AppRoutes.js 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import React, { useEffect } from "react";
  2. import { Redirect, Route, Switch } from "react-router-dom";
  3. import { useDispatch } from "react-redux";
  4. import { refreshUserToken } from "./store/actions/login/loginActions";
  5. import { useLocation } from "react-router-dom";
  6. import {
  7. ADS_PAGE,
  8. AD_DETAILS_PAGE,
  9. FORGOT_PASSWORD_PAGE,
  10. FORGOT_PASSWORD_CONFIRMATION_PAGE,
  11. NOT_FOUND_PAGE,
  12. ERROR_PAGE,
  13. BASE_PAGE,
  14. RESET_PASSWORD_PAGE,
  15. USERS_PAGE,
  16. CANDIDATES_PAGE,
  17. USER_DETAILS_PAGE,
  18. CANDIDATES_DETAILS_PAGE,
  19. SELECTION_PROCESS_PAGE,
  20. SELECTION_PROCESS_OF_APPLICANT_PAGE,
  21. PATTERNS_PAGE,
  22. PATTERN_DETAILS_PAGE,
  23. SCHEDULE_PAGE,
  24. STATS_PAGE,
  25. REGISTER_PAGE,
  26. CREATE_AD_PAGE,
  27. FILES_PAGE,
  28. FILES_VIEW_PAGE,
  29. } from "./constants/pages";
  30. import LoginPage from "./pages/LoginPage/LoginPageMUI";
  31. import AdsPage from "./pages/AdsPage/AdsPage";
  32. import NotFoundPage from "./pages/ErrorPages/NotFoundPage";
  33. import ErrorPage from "./pages/ErrorPages/ErrorPage";
  34. import ForgotPasswordPage from "./pages/ForgotPasswordPage/ForgotPasswordPageMUI";
  35. import PrivateRoute from "./components/Router/PrivateRoute";
  36. import ForgotPasswordConfirmationPage from "./pages/ForgotPasswordPage/ForgotPasswordConfirmationPageMUI";
  37. import ResetPasswordPage from "./pages/ForgotPasswordPage/ResetPasswordPageMUI";
  38. import UsersPage from "./pages/UsersPage/UsersPage";
  39. import CandidatesPage from "./pages/CandidatesPage/CandidatesPage";
  40. import AdDetailsPage from "./pages/AdsPage/AdDetailsPage";
  41. import UserDetails from "./pages/UsersPage/UserDetails";
  42. import CandidateDetailsPage from "./pages/CandidatesPage/CandidateDetailsPage";
  43. import SelectionProcessPage from "./pages/SelectionProcessPage/SelectionProcessPage";
  44. import SelectionProcessOfApplicantPage from "./pages/SelectionProcessPage/SelectionProcessOfApplicantPage";
  45. import PatternsPage from "./pages/PatternsPage/PatternsPage";
  46. import PatternDetailsPage from "./pages/PatternsPage/PatternDetailsPage";
  47. import SchedulePage from "./pages/SchedulePage/SchedulePage";
  48. import StatsPage from "./pages/StatsPage/StatsPage";
  49. import RegisterPage from "./pages/RegisterPage/RegisterPage";
  50. import CreateAdPage from "./pages/AdsPage/CreateAdPage";
  51. import FilesPage from "./pages/FilesPage/FilesPage";
  52. import FilesViewPage from "./pages/FilesPage/FilesViewPage";
  53. const AppRoutes = () => {
  54. const dispatch = useDispatch();
  55. const location = useLocation();
  56. useEffect(() => {
  57. if (location.pathname === BASE_PAGE) {
  58. return;
  59. }
  60. dispatch(refreshUserToken());
  61. }, [location]);
  62. return (
  63. <Switch>
  64. <Route exact path={FILES_VIEW_PAGE} component={FilesViewPage} />
  65. <Route exact path={BASE_PAGE} component={LoginPage} />
  66. <Route path={NOT_FOUND_PAGE} component={NotFoundPage} />
  67. {/* <Route path={USERS_PAGE} component={UsersPage} /> */}
  68. <Route path={ERROR_PAGE} component={ErrorPage} />
  69. <Route path={FORGOT_PASSWORD_PAGE} component={ForgotPasswordPage} />
  70. <Route
  71. path={FORGOT_PASSWORD_CONFIRMATION_PAGE}
  72. component={ForgotPasswordConfirmationPage}
  73. />
  74. <Route exact path={REGISTER_PAGE} component={RegisterPage} />
  75. <Route path={RESET_PASSWORD_PAGE} component={ResetPasswordPage} />
  76. <PrivateRoute exact path={ADS_PAGE} component={AdsPage} />
  77. <PrivateRoute exact path={AD_DETAILS_PAGE} component={AdDetailsPage} />
  78. <PrivateRoute exact path={USER_DETAILS_PAGE} component={UserDetails} />
  79. <PrivateRoute exact path={USERS_PAGE} component={UsersPage} />
  80. <PrivateRoute exact path={CANDIDATES_PAGE} component={CandidatesPage} />
  81. <PrivateRoute exact path={CREATE_AD_PAGE} component={CreateAdPage} />
  82. <PrivateRoute exact path={FILES_PAGE} component={FilesPage} />
  83. <PrivateRoute
  84. exact
  85. path={CANDIDATES_DETAILS_PAGE}
  86. component={CandidateDetailsPage}
  87. />
  88. <PrivateRoute
  89. exact
  90. path={SELECTION_PROCESS_PAGE}
  91. component={SelectionProcessPage}
  92. />
  93. <PrivateRoute
  94. exact
  95. path={SELECTION_PROCESS_OF_APPLICANT_PAGE}
  96. component={SelectionProcessOfApplicantPage}
  97. />
  98. <PrivateRoute
  99. exact
  100. path={PATTERN_DETAILS_PAGE}
  101. component={PatternDetailsPage}
  102. />
  103. <PrivateRoute exact path={PATTERNS_PAGE} component={PatternsPage} />
  104. <PrivateRoute exact path={SCHEDULE_PAGE} component={SchedulePage} />
  105. <PrivateRoute exact path={STATS_PAGE} component={StatsPage} />
  106. <Redirect from="*" to={NOT_FOUND_PAGE} />
  107. </Switch>
  108. );
  109. };
  110. export default AppRoutes;