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.

SidebarNavigation.js 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import React from "react";
  2. import PropTypes from "prop-types";
  3. import {
  4. SidebarNavigationContainer,
  5. SidebarNavigationItem,
  6. SidebarNavigationItemIcon,
  7. SidebarNavigationListContainer,
  8. SidebarNavigationTitle,
  9. } from "./SidebarNavigation.styled";
  10. import { useTranslation } from "react-i18next";
  11. import { isInRoute, routeMatches } from "../../../../util/helpers/routeHelpers";
  12. import { ADMIN_HOME_PAGE, ADMIN_USERS_PAGE } from "../../../../constants/pages";
  13. import { ADMIN_NAVIGATION } from "../../../../constants/adminNavigation";
  14. const SidebarNavigation = () => {
  15. const { t } = useTranslation();
  16. const goToRoute = (route) => {
  17. history.push(route);
  18. };
  19. return (
  20. <SidebarNavigationContainer>
  21. <SidebarNavigationTitle>
  22. {t("admin.navigation.menu")}
  23. </SidebarNavigationTitle>
  24. <SidebarNavigationListContainer>
  25. {ADMIN_NAVIGATION.map((value) => {
  26. let isRouteActive = isInRoute(value.route);
  27. if (
  28. routeMatches(ADMIN_HOME_PAGE) &&
  29. routeMatches(ADMIN_USERS_PAGE, value.route)
  30. )
  31. isRouteActive = true;
  32. return (
  33. <SidebarNavigationItem
  34. active={isRouteActive}
  35. key={value.text}
  36. onClick={() => goToRoute(value.route)}
  37. >
  38. <SidebarNavigationItemIcon active={isRouteActive}>
  39. {value.icon}
  40. </SidebarNavigationItemIcon>
  41. {value.text}
  42. </SidebarNavigationItem>
  43. );
  44. })}
  45. </SidebarNavigationListContainer>
  46. </SidebarNavigationContainer>
  47. );
  48. };
  49. SidebarNavigation.propTypes = {
  50. children: PropTypes.node,
  51. };
  52. export default SidebarNavigation;