Merge pull request '261001_02_ENH: 재단 계정에 대한 메뉴 노출 수정 및 페이지 접근 수정' (#4) from develop into master
Reviewed-on: #4
This commit is contained in:
@@ -5,20 +5,20 @@ import { LogOut } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { KriHeader } from "@/components/layout/KriHeader";
|
||||
import type { LoginUser } from "@kri/common";
|
||||
import {TOP_MENUS} from "@/config/menu.data";
|
||||
import type { TopMenuItem } from "@/config/menu.type";
|
||||
import {SITE_TITLE} from "@/config/common.config";
|
||||
|
||||
interface AppHeaderProps {
|
||||
menus?: TopMenuItem[];
|
||||
menuOpen: boolean;
|
||||
showMenuButton: boolean;
|
||||
activeMenuId?: string;
|
||||
user?: LoginUser | null;
|
||||
isMonitoring?: boolean;
|
||||
onToggleMenu: () => void;
|
||||
onNavigate: (path: string) => void;
|
||||
}
|
||||
|
||||
export function AppHeader({ menuOpen, showMenuButton, activeMenuId, user, isMonitoring, onToggleMenu, onNavigate }: AppHeaderProps) {
|
||||
export function AppHeader({ menus, menuOpen, showMenuButton, activeMenuId, user, onToggleMenu, onNavigate }: AppHeaderProps) {
|
||||
const siteTitle = (
|
||||
<div
|
||||
className="pointer-events-none absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 hidden sm:inline">
|
||||
@@ -29,7 +29,7 @@ export function AppHeader({ menuOpen, showMenuButton, activeMenuId, user, isMoni
|
||||
return (
|
||||
<KriHeader
|
||||
logo={<Image src="/logo.svg" alt="로고" width={120} height={40} className="h-10 w-auto object-contain" priority />}
|
||||
menus={isMonitoring? undefined : TOP_MENUS}
|
||||
menus={menus}
|
||||
activeMenuId={activeMenuId}
|
||||
menuOpen={menuOpen}
|
||||
showMenuButton={showMenuButton}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
"use client";
|
||||
|
||||
import type { Route } from "next";
|
||||
import { useMemo, useState, type ReactNode } from "react";
|
||||
import { useEffect, useMemo, useState, type ReactNode } from "react";
|
||||
import { usePathname, useRouter } from "next/navigation";
|
||||
import { KriMainLayout } from "@/components/layout/KriMainLayout";
|
||||
import { AppHeader } from "./AppHeader";
|
||||
import { TOP_MENUS } from "@/config/menu.data";
|
||||
import { getVisibleTopMenus, isMenuPathBlockedForRole, TOP_MENUS } from "@/config/menu.data";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
|
||||
export function AppMainLayout({ children }: { children: ReactNode }) {
|
||||
@@ -14,12 +14,20 @@ export function AppMainLayout({ children }: { children: ReactNode }) {
|
||||
const { auth, isMonitoring } = useAuth();
|
||||
const [menuOpen, setMenuOpen] = useState(true);
|
||||
|
||||
const role = auth.user?.userRole;
|
||||
const visibleMenus = useMemo(() => (isMonitoring ? undefined : getVisibleTopMenus(role)), [isMonitoring, role]);
|
||||
const isAccessBlocked = useMemo(() => isMenuPathBlockedForRole(role, pathname), [role, pathname]);
|
||||
|
||||
const activeMenuId = useMemo(
|
||||
() => TOP_MENUS.find((item) => item.path && (pathname === item.path || pathname.startsWith(`${item.path}/`)))?.id,
|
||||
[pathname],
|
||||
);
|
||||
|
||||
// 접근 권한이 없는 경로에 진입하면 사업정보 페이지로 돌려보낸다.
|
||||
useEffect(() => {
|
||||
if (isAccessBlocked) router.replace("/performance" as Route);
|
||||
}, [isAccessBlocked, router]);
|
||||
|
||||
const navigate = (path: string) => router.push(path as Route);
|
||||
|
||||
return (
|
||||
@@ -28,17 +36,17 @@ export function AppMainLayout({ children }: { children: ReactNode }) {
|
||||
onSidebarOpenChange={setMenuOpen}
|
||||
header={
|
||||
<AppHeader
|
||||
menus={visibleMenus}
|
||||
menuOpen={menuOpen}
|
||||
showMenuButton={false}
|
||||
activeMenuId={activeMenuId}
|
||||
user={auth.user}
|
||||
isMonitoring={isMonitoring}
|
||||
onToggleMenu={() => setMenuOpen((current) => !current)}
|
||||
onNavigate={navigate}
|
||||
/>
|
||||
}
|
||||
>
|
||||
{children}
|
||||
{isAccessBlocked ? null : children}
|
||||
</KriMainLayout>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -10,4 +10,7 @@ export const TOP_MENU_PATH_MAP: Record<string, string> = {
|
||||
"performance-list": "/performance",
|
||||
"user-list": "/user",
|
||||
"assign": "/assign",
|
||||
};
|
||||
};
|
||||
|
||||
// 재단(2011) 계정에서 숨기고 접근을 차단하는 상단 메뉴
|
||||
export const FOUNDATION_HIDDEN_MENU_IDS = ["user-list", "assign"] as const;
|
||||
@@ -1,5 +1,6 @@
|
||||
import {TopMenuItem} from "@/config/menu.type";
|
||||
import {TOP_MENU_KEY_MAP, TOP_MENU_PATH_MAP} from "@/config/common.config";
|
||||
import {FOUNDATION_HIDDEN_MENU_IDS, TOP_MENU_KEY_MAP, TOP_MENU_PATH_MAP} from "@/config/common.config";
|
||||
import {isFoundationRole} from "@/lib/kmusical/view";
|
||||
|
||||
export const TOP_MENUS: TopMenuItem[] = Object.entries(TOP_MENU_KEY_MAP).map(
|
||||
([key, value]) => {
|
||||
@@ -12,4 +13,20 @@ export const TOP_MENUS: TopMenuItem[] = Object.entries(TOP_MENU_KEY_MAP).map(
|
||||
match: (pathname: string) => pathname === path,
|
||||
};
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
const foundationHiddenMenuIdSet = new Set<string>(FOUNDATION_HIDDEN_MENU_IDS);
|
||||
|
||||
// 역할에 따라 노출 가능한 상단 메뉴만 반환한다. 재단(2011)은 계정관리·평가위원 배정을 숨긴다.
|
||||
export const getVisibleTopMenus = (role?: number | null): TopMenuItem[] =>
|
||||
isFoundationRole(role) ? TOP_MENUS.filter((menu) => !foundationHiddenMenuIdSet.has(menu.id)) : TOP_MENUS;
|
||||
|
||||
// 해당 역할이 접근할 수 없는 경로인지 판단한다(숨긴 메뉴의 경로 직접 접근 차단용).
|
||||
export const isMenuPathBlockedForRole = (role: number | null | undefined, pathname: string): boolean => {
|
||||
if (!isFoundationRole(role)) return false;
|
||||
|
||||
return FOUNDATION_HIDDEN_MENU_IDS.some((id) => {
|
||||
const path = `/${TOP_MENU_PATH_MAP[id].replace(/^\/+/, "")}`;
|
||||
return pathname === path || pathname.startsWith(`${path}/`);
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user