mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-08-26 19:12:50 +00:00
feat: implement user type-based navigation visibility in PortalLayout
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ export interface AuthUser {
|
||||
en: string;
|
||||
};
|
||||
status: string;
|
||||
userType?: string;
|
||||
sharepointId: string | null;
|
||||
hasSetPassword: boolean;
|
||||
hasFinishedRegistration: boolean;
|
||||
|
||||
Reference in New Issue
Block a user