feat: implement user type-based navigation visibility in PortalLayout

This commit is contained in:
estifanos
2026-07-29 07:27:46 +00:00
parent 5ceb5da3c2
commit 27a5968b79
2 changed files with 49 additions and 0 deletions

View File

@@ -157,6 +157,46 @@ 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.
const ALWAYS_VISIBLE = ['/notifications', '/profile', '/support'];
const NAV_ACCESS: Record<string, string[] | '*'> = {
individual: '*',
cadet: [
'/dashboard',
'/seafarer-registry',
'/seaman-book',
'/certificates',
'/endorsements',
'/documents',
],
registration: [
'/vessel-registration-dashboard',
'/vessel-registration',
'/vessel-registration/transfer',
],
transfer: [
'/vessel-registration-dashboard',
'/vessel-registration',
'/vessel-registration/transfer',
],
logistics: [
'/logistics-dashboard',
'/freight-forwarder-license',
'/shipping-agent-license',
'/combined-license',
'/joint-investment-license',
'/mto-license',
'/waiver',
],
};
// Used when userType is missing or unrecognized. Set to '*' to show everything.
const FALLBACK_ACCESS: string[] | '*' = ['/dashboard'];
const PAGE_META: Record<string, { i18nKey: string }> = {
"/dashboard": { i18nKey: "nav.dashboard" },
"/vessel-registration-dashboard": {
@@ -189,6 +229,14 @@ 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 visibleNavItems =
allowed === '*'
? NAV_ITEMS
: NAV_ITEMS.filter(
(item) =>
ALWAYS_VISIBLE.includes(item.to ?? '') || allowed.includes(item.to ?? ''),
);
const [navOpened, { toggle: toggleNav, close: closeNav }] = useDisclosure();
const [sidebarCollapsed, { toggle: toggleSidebar }] = useDisclosure(false);

View File

@@ -8,6 +8,7 @@ export interface AuthUser {
en: string;
};
status: string;
userType?: string;
sharepointId: string | null;
hasSetPassword: boolean;
hasFinishedRegistration: boolean;