From c68484e12499592436a8e711c9cd9bdbeb0f9340 Mon Sep 17 00:00:00 2001 From: carddev81 Date: Wed, 29 Jan 2025 22:38:01 -0600 Subject: [PATCH] fix: update side navigation for administrator and resident per #658 --- frontend/src/Components/Navbar.tsx | 130 ++++++++++++++--------------- frontend/src/useAuth.ts | 31 +++---- 2 files changed, 74 insertions(+), 87 deletions(-) diff --git a/frontend/src/Components/Navbar.tsx b/frontend/src/Components/Navbar.tsx index dc4a7fd29..2bbe68392 100644 --- a/frontend/src/Components/Navbar.tsx +++ b/frontend/src/Components/Navbar.tsx @@ -16,15 +16,11 @@ import { RssIcon, RectangleStackIcon, CogIcon, - LightBulbIcon + LightBulbIcon, + RocketLaunchIcon, + ArrowTrendingUpIcon } from '@heroicons/react/24/solid'; -import { - getDashboardLink, - handleLogout, - hasFeature, - isAdministrator, - useAuth -} from '@/useAuth'; +import { handleLogout, hasFeature, isAdministrator, useAuth } from '@/useAuth'; import Modal from '@/Components/Modal'; import ULIComponent from './ULIComponent'; import { Link } from 'react-router-dom'; @@ -52,12 +48,6 @@ export default function Navbar({ const confirmSeedModal = useRef(null); const [seedInProgress, setSeedInProgress] = useState(false); - const dashboardTitleStudent = new Map([ - ['/trending-content', 'Trending Content'], - ['/learning-path', 'Learning Path'], - ['/program-tracker', 'Program Tracker'] - ]); - const handleSeedDemoData = async () => { setSeedInProgress(true); const resp = await API.post(`auth/demo-seed`, {}); @@ -134,18 +124,29 @@ export default function Navbar({ Operational Insights + {hasFeature( + user, + FeatureAccess.OpenContentAccess + ) && ( +
  • + + + Knowledge Center + +
  • + )} {hasFeature(user, FeatureAccess.ProviderAccess) && ( <>
  • - + - Course Catalog + Learning Platforms
  • - + - Learning Platforms + Course Catalog
  • @@ -158,17 +159,6 @@ export default function Navbar({ )} - {hasFeature( - user, - FeatureAccess.OpenContentAccess - ) && ( -
  • - - - Knowledge Center - -
  • - )}
  • @@ -192,25 +182,54 @@ export default function Navbar({ ) : ( <> -
  • - - - {dashboardTitleStudent.get( - getDashboardLink(user) - ) ?? 'Home'} - -
  • - {hasFeature(user, FeatureAccess.ProviderAccess) && ( - <> - {getDashboardLink(user) !== - '/learning-path' && ( + {!hasFeature( + user, + FeatureAccess.OpenContentAccess + ) && + !hasFeature( + user, + FeatureAccess.ProviderAccess + ) && + !hasFeature( + user, + FeatureAccess.ProgramAccess + ) && ( + <>
  • - + - My Learning + Home
  • - )} + + )} + {hasFeature( + user, + FeatureAccess.OpenContentAccess + ) && ( + <> +
  • + + + Trending Content + +
  • +
  • + + + Knowledge Center + +
  • + + )} + {hasFeature(user, FeatureAccess.ProviderAccess) && ( + <> +
  • + + + Learning Path + +
  • )} - {hasFeature( - user, - FeatureAccess.OpenContentAccess - ) && ( - <> - {user.feature_access.length > 1 && ( -
  • - - - Trending Content - -
  • - )} -
  • - - - Knowledge Center - -
  • - - )} {hasFeature(user, FeatureAccess.ProgramAccess) && (
  • diff --git a/frontend/src/useAuth.ts b/frontend/src/useAuth.ts index 2f0ff30a4..5661bb214 100644 --- a/frontend/src/useAuth.ts +++ b/frontend/src/useAuth.ts @@ -153,30 +153,11 @@ export async function handleLogout(): Promise { } } -const accessValues = new Map([ - [FeatureAccess.OpenContentAccess, 1], - [FeatureAccess.ProviderAccess, 2], - [FeatureAccess.ProgramAccess, 3] -]); - -export const studentAccessLinks = [ - '/home', // temporary layer 0 until implemented - '/trending-content', - '/learning-path', // temporary until layer 3 is implemented - '/learning-path' // temporary until layer 3 is implemented -]; - export const getDashboardLink = (user?: User) => { if (!user) return '/'; - - const maxFeature = - user?.feature_access - .map((ax) => accessValues.get(ax) ?? 0) - .sort((a, b) => a - b) - .pop() ?? 0; return isAdministrator(user) ? getAdminLink(user) - : studentAccessLinks[maxFeature]; + : getResidentLink(user); }; const getAdminLink = (user: User): string => { @@ -187,4 +168,14 @@ const getAdminLink = (user: User): string => { return "/learning-insights"; } return "/operational-insights"; +}; + +const getResidentLink = (user: User): string => { + if (user.feature_access.includes(FeatureAccess.OpenContentAccess)) { + return "/trending-content"; + } + if (user.feature_access.includes(FeatureAccess.ProviderAccess)) { + return "/learning-path"; + } + return "/home"; }; \ No newline at end of file