diff --git a/apps/portal/src/app/layouts/PortalLayout.tsx b/apps/portal/src/app/layouts/PortalLayout.tsx index 7564afeec..ca8e4aa49 100644 --- a/apps/portal/src/app/layouts/PortalLayout.tsx +++ b/apps/portal/src/app/layouts/PortalLayout.tsx @@ -158,8 +158,11 @@ const NAV_ITEMS: (NavItem & { i18nKey: string })[] = [ ]; // ── Sidebar visibility rules ────────────────────────────────────────────── -// Edit these lists to change what each user type sees. Values are the `to` -// paths from NAV_ITEMS above. '*' means every item. +// Edit these lists to change what each profession sees. Each key is matched +// case-insensitively as a substring against the user's profession name +// (state.auth.currentProfile.profession.name.en) — e.g. the key "cadet" +// matches a profession named "Deck Cadet". Values are the `to` paths from +// NAV_ITEMS above. '*' means every item. const ALWAYS_VISIBLE = ['/notifications', '/profile', '/support']; @@ -194,7 +197,7 @@ const NAV_ACCESS: Record = { ], }; -// Used when userType is missing or unrecognized. Set to '*' to show everything. +// Used when profession is missing or matches no key above. Set to '*' to show everything. const FALLBACK_ACCESS: string[] | '*' = ['/dashboard']; const PAGE_META: Record = { @@ -229,7 +232,12 @@ export function PortalLayout() { const location = useLocation(); const dispatch = useDispatch(); const user = useAppSelector((state) => state.auth.user); - const allowed = NAV_ACCESS[user?.userType ?? ''] ?? FALLBACK_ACCESS; + const currentProfile = useAppSelector((state) => state.auth.currentProfile); + const professionName = (currentProfile?.profession?.name?.en ?? "").toLowerCase(); + const matchedKey = Object.keys(NAV_ACCESS).find((key) => + professionName.includes(key), + ); + const allowed = (matchedKey ? NAV_ACCESS[matchedKey] : undefined) ?? FALLBACK_ACCESS; const visibleNavItems = allowed === '*' ? NAV_ITEMS @@ -315,7 +323,7 @@ export function PortalLayout() { }} > ({ + navItems={visibleNavItems.map(({ i18nKey, ...rest }) => ({ ...rest, label: t(i18nKey), }))}