This commit is contained in:
Estifo77
2026-07-29 12:08:36 +03:00
parent a9638afa27
commit 0c3d817ee1
2 changed files with 33 additions and 27 deletions

View File

@@ -164,41 +164,42 @@ const NAV_ITEMS: (NavItem & { i18nKey: string })[] = [
// matches a profession named "Deck Cadet". Values are the `to` paths from
// NAV_ITEMS above. '*' means every item.
const ALWAYS_VISIBLE = ['/notifications', '/profile', '/support'];
const ALWAYS_VISIBLE = ["/notifications", "/profile", "/support"];
const NAV_ACCESS: Record<string, string[] | '*'> = {
individual: '*',
const NAV_ACCESS: Record<string, string[] | "*"> = {
null: "*",
individual: "*",
cadet: [
'/dashboard',
'/seafarer-registry',
'/seaman-book',
'/certificates',
'/endorsements',
'/documents',
"/dashboard",
"/seafarer-registry",
"/seaman-book",
"/certificates",
"/endorsements",
"/documents",
],
registration: [
'/vessel-registration-dashboard',
'/vessel-registration',
'/vessel-registration/transfer',
"/vessel-registration-dashboard",
"/vessel-registration",
"/vessel-registration/transfer",
],
transfer: [
'/vessel-registration-dashboard',
'/vessel-registration',
'/vessel-registration/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',
"/logistics-dashboard",
"/freight-forwarder-license",
"/shipping-agent-license",
"/combined-license",
"/joint-investment-license",
"/mto-license",
"/waiver",
],
};
// Used when profession is missing or matches no key above. Set to '*' to show everything.
const FALLBACK_ACCESS: string[] | '*' = ['/dashboard'];
const FALLBACK_ACCESS: string[] | "*" = ["/dashboard"];
const PAGE_META: Record<string, { i18nKey: string }> = {
"/dashboard": { i18nKey: "nav.dashboard" },
@@ -233,17 +234,21 @@ export function PortalLayout() {
const dispatch = useDispatch();
const user = useAppSelector((state) => state.auth.user);
const currentProfile = useAppSelector((state) => state.auth.currentProfile);
const professionName = (currentProfile?.profession?.name?.en ?? "").toLowerCase();
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 allowed =
(matchedKey ? NAV_ACCESS[matchedKey] : undefined) ?? FALLBACK_ACCESS;
const visibleNavItems =
allowed === '*'
allowed === "*"
? NAV_ITEMS
: NAV_ITEMS.filter(
(item) =>
ALWAYS_VISIBLE.includes(item.to ?? '') || allowed.includes(item.to ?? ''),
ALWAYS_VISIBLE.includes(item.to ?? "") ||
allowed.includes(item.to ?? ""),
);
const [navOpened, { toggle: toggleNav, close: closeNav }] = useDisclosure();
const [sidebarCollapsed, { toggle: toggleSidebar }] = useDisclosure(false);

View File

@@ -42,6 +42,7 @@ const authSlice = createSlice({
state.isAuthenticated = false;
state.currentProfile = null;
authStorage.clear();
clearCurrentProfile();
},
setToken(state, action: PayloadAction<string>) {
state.token = action.payload;