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.

AdminHomePage.js 3.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import React, { useMemo } from "react";
  2. import PropTypes from "prop-types";
  3. // import MarketPlace from "../../components/MarketPlace/MarketPlace";
  4. // import useOffers from "../../hooks/useOffers/useOffers";
  5. import Sidebar from "../../components/Admin/Sidebar/Sidebar";
  6. import { useSelector } from "react-redux";
  7. // import { selectIsLoadingByActionType } from "../../store/selectors/loadingSelectors";
  8. // import { OFFERS_SCOPE } from "../../store/actions/offers/offersActionConstants";
  9. import AdminUsersPage from "./AdminUsersPage/AdminUsersPage";
  10. import { selectMineProfile } from "../../store/selectors/profileSelectors";
  11. import { Switch, useHistory } from "react-router-dom";
  12. import {
  13. ADMIN_CATEGORIES_PAGE,
  14. ADMIN_ITEM_DETAILS_PAGE,
  15. ADMIN_LOCATIONS_PAGE,
  16. ADMIN_PAYMENT_PAGE,
  17. ADMIN_SINGLE_USER_PAGE,
  18. ADMIN_SUBCATEGORIES_PAGE,
  19. ADMIN_USERS_PAGE,
  20. HOME_PAGE,
  21. } from "../../constants/pages";
  22. import { selectUserId } from "../../store/selectors/loginSelectors";
  23. import AdminCategoriesPage from "./AdminCategoriesPage/AdminCategoriesPage";
  24. import AdminRoute from "../../components/Router/AdminRoute";
  25. import AdminSubcategoriesPage from "./AdminSubcategoriesPage/AdminSubcategoriesPage";
  26. import AdminLocationsPage from "./AdminLocationsPage/AdminLocationsPage";
  27. import AdminPaymentPage from "./AdminPaymentPage/AdminPaymentPage";
  28. import AdminSingleUserPage from "./AdminUsersPage/AdminSingleUserPage/AdminSingleUserPage";
  29. import { AdminLayoutHomePage } from "./AdminHomePage.styled";
  30. import AdminItemDetailsPage from "./AdminItemDetailsPage/AdminItemDetailsPage";
  31. const AdminHomePage = () => {
  32. const profile = useSelector(selectMineProfile);
  33. const userId = useSelector(selectUserId);
  34. const history = useHistory();
  35. const isUserLogin = useMemo(() => {
  36. if (userId?.length === 0) return false;
  37. return true;
  38. }, [userId]);
  39. if (!profile.roles.includes("Admin") || !isUserLogin) {
  40. history.push(HOME_PAGE);
  41. }
  42. return (
  43. <AdminLayoutHomePage
  44. leftCard={<Sidebar />}
  45. content={
  46. <Switch>
  47. <AdminRoute
  48. exact
  49. path={ADMIN_USERS_PAGE}
  50. component={AdminUsersPage}
  51. />
  52. <AdminRoute
  53. exact
  54. path={ADMIN_CATEGORIES_PAGE}
  55. component={AdminCategoriesPage}
  56. />
  57. <AdminRoute
  58. exact
  59. path={ADMIN_SINGLE_USER_PAGE}
  60. component={AdminSingleUserPage}
  61. />
  62. <AdminRoute
  63. path={ADMIN_ITEM_DETAILS_PAGE}
  64. component={AdminItemDetailsPage}
  65. />
  66. <AdminRoute
  67. path={ADMIN_SUBCATEGORIES_PAGE}
  68. component={AdminSubcategoriesPage}
  69. />
  70. <AdminRoute
  71. path={ADMIN_LOCATIONS_PAGE}
  72. component={AdminLocationsPage}
  73. />
  74. <AdminRoute path={ADMIN_PAYMENT_PAGE} component={AdminPaymentPage} />
  75. <AdminRoute
  76. path={ADMIN_SUBCATEGORIES_PAGE}
  77. component={AdminSubcategoriesPage}
  78. />
  79. <AdminRoute component={AdminUsersPage} />
  80. </Switch>
  81. }
  82. />
  83. );
  84. };
  85. AdminHomePage.propTypes = {
  86. children: PropTypes.node,
  87. };
  88. export default AdminHomePage;