From a10b83174408e65091fb9da24e4dd5d4ac4a646c Mon Sep 17 00:00:00 2001 From: Daniel Cojocea Date: Wed, 24 Jul 2024 14:46:49 -0400 Subject: [PATCH 1/2] Hide team panel for users --- Client/src/Components/NavBar/index.jsx | 5 ++++- Client/src/Pages/Account/index.jsx | 9 ++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Client/src/Components/NavBar/index.jsx b/Client/src/Components/NavBar/index.jsx index f99ad14b6..e58ec7dac 100644 --- a/Client/src/Components/NavBar/index.jsx +++ b/Client/src/Components/NavBar/index.jsx @@ -25,7 +25,6 @@ import LogoutSvg from "../../assets/icons/logout.svg?react"; import BWULogo from "../../assets/Images/bwl-logo.svg?react"; -const settings = ["Profile", "Password", "Team", "Logout"]; const icons = { Profile: , Team: , @@ -51,6 +50,10 @@ function NavBar() { const navigate = useNavigate(); const authState = useSelector((state) => state.auth); + let settings = ["Profile", "Password", "Team", "Logout"]; + if (authState.user.role[0] !== "admin") + settings = ["Profile", "Password", "Logout"]; + /** * Handles opening the user menu. * diff --git a/Client/src/Pages/Account/index.jsx b/Client/src/Pages/Account/index.jsx index 391cf3940..24514da60 100644 --- a/Client/src/Pages/Account/index.jsx +++ b/Client/src/Pages/Account/index.jsx @@ -8,6 +8,7 @@ import ProfilePanel from "../../Components/TabPanels/Account/ProfilePanel"; import PasswordPanel from "../../Components/TabPanels/Account/PasswordPanel"; import TeamPanel from "../../Components/TabPanels/Account/TeamPanel"; import { useNavigate } from "react-router"; +import { useSelector } from "react-redux"; /** * Account component renders a settings page with tabs for Profile, Password, and Team settings. @@ -15,8 +16,6 @@ import { useNavigate } from "react-router"; * @returns {JSX.Element} */ -const tabList = ["Profile", "Password", "Team"]; - const Account = ({ open = "profile" }) => { const theme = useTheme(); const navigate = useNavigate(); @@ -25,6 +24,10 @@ const Account = ({ open = "profile" }) => { navigate(`/account/${newTab}`); }; + let tabList = ["Profile", "Password", "Team"]; + const { user } = useSelector((state) => state.auth); + if (user.role[0] !== "admin") tabList = ["Profile", "Password"]; + return ( { - + { user.role[0] === "admin" && } ); From e2b5ad2524646eb29769396cf2e38442c20ea828 Mon Sep 17 00:00:00 2001 From: Daniel Cojocea Date: Wed, 24 Jul 2024 15:07:00 -0400 Subject: [PATCH 2/2] Added fix to searching for admin role --- Client/src/Components/NavBar/index.jsx | 4 ++-- Client/src/Pages/Account/index.jsx | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Client/src/Components/NavBar/index.jsx b/Client/src/Components/NavBar/index.jsx index e58ec7dac..e1501ea48 100644 --- a/Client/src/Components/NavBar/index.jsx +++ b/Client/src/Components/NavBar/index.jsx @@ -51,9 +51,9 @@ function NavBar() { const authState = useSelector((state) => state.auth); let settings = ["Profile", "Password", "Team", "Logout"]; - if (authState.user.role[0] !== "admin") + if (!authState.user.role.includes("admin")) settings = ["Profile", "Password", "Logout"]; - + /** * Handles opening the user menu. * diff --git a/Client/src/Pages/Account/index.jsx b/Client/src/Pages/Account/index.jsx index 24514da60..ad5acf53a 100644 --- a/Client/src/Pages/Account/index.jsx +++ b/Client/src/Pages/Account/index.jsx @@ -26,7 +26,7 @@ const Account = ({ open = "profile" }) => { let tabList = ["Profile", "Password", "Team"]; const { user } = useSelector((state) => state.auth); - if (user.role[0] !== "admin") tabList = ["Profile", "Password"]; + if (!user.role.includes("admin")) tabList = ["Profile", "Password"]; return ( { - { user.role[0] === "admin" && } + { user.role.includes("admin") && } );