From 947bd076c9cb79b87e04d5c18ce0f8256f2f3683 Mon Sep 17 00:00:00 2001 From: Sacha Delanoue Date: Mon, 22 May 2023 19:39:22 +0200 Subject: [PATCH] Show knowledge page to JAV team members --- src/components/Navigation/MainMenu.tsx | 29 +++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/components/Navigation/MainMenu.tsx b/src/components/Navigation/MainMenu.tsx index 0f1416d..9e95ea4 100644 --- a/src/components/Navigation/MainMenu.tsx +++ b/src/components/Navigation/MainMenu.tsx @@ -1,9 +1,11 @@ -import { FC, useCallback, useState } from "react" +import { FC, useCallback, useState, useEffect, useMemo } from "react" import { useSelector } from "react-redux" import classnames from "classnames" -import { isUserConnected, routerSelector, selectUserRoles } from "../../store/auth" +import { isUserConnected, routerSelector, selectUserRoles, selectUserId } from "../../store/auth" import styles from "./styles.module.scss" import ROLES from "../../utils/roles.constants" +import useAction from "../../utils/useAction" +import { fetchVolunteerListIfNeed, selectVolunteerList } from "../../store/volunteerList" interface MenuItemProps { name: string @@ -29,6 +31,27 @@ const RestrictMenuItem: FC = ({ name, pathname, role }): return roles.includes(role) ? :
} +interface TeamMenuItemProps extends MenuItemProps { + team: number +} + +const TeamMenuItem: FC = ({ name, pathname, team }): JSX.Element => { + const fetch = useAction(fetchVolunteerListIfNeed) + const userId = useSelector(selectUserId) + useEffect(() => { + if (userId) fetch() + }, [userId, fetch]) + const volunteers = useSelector(selectVolunteerList) + const user = useMemo( + () => volunteers.find((volunteer) => volunteer.id === userId), + [volunteers, userId] + ) + return user?.team === team ? :
+} + +// Hardcoded value of the "Jeux à volonté" team +const TEAM_JAV = 2 + const MainMenu: FC = (): JSX.Element => { const connected = useSelector(isUserConnected) const [opened, setOpened] = useState(false) @@ -54,7 +77,7 @@ const MainMenu: FC = (): JSX.Element => { {/* */} - {/* */} +