diff --git a/apps/cs/app/(with-base-layout)/layout.tsx b/apps/cs/app/(with-base-layout)/layout.tsx index cbcaee847..dfb290abd 100644 --- a/apps/cs/app/(with-base-layout)/layout.tsx +++ b/apps/cs/app/(with-base-layout)/layout.tsx @@ -1,11 +1,18 @@ "use client"; +import { usePathname, useRouter } from "next/navigation"; import { BaseLayout } from "@common/components/ui"; - export default function WithBaseLayout({ children, }: { children: React.ReactNode; }) { - return {children}; + const router = useRouter(); + const pathname = usePathname(); + + return ( + + {children} + + ); } diff --git a/packages/common/components/src/ui/layout/base.tsx b/packages/common/components/src/ui/layout/base.tsx index 9dd778e03..b48e2d9d9 100644 --- a/packages/common/components/src/ui/layout/base.tsx +++ b/packages/common/components/src/ui/layout/base.tsx @@ -10,9 +10,13 @@ import type { QueryClient } from "@tanstack/react-query"; export function BaseLayout({ children, queryClient, + currentPath, + routeHandler, }: { children: React.ReactNode; queryClient?: QueryClient; + currentPath?: string; + routeHandler?: (path: string) => void; }) { return ( @@ -20,7 +24,7 @@ export function BaseLayout({
- +
{children} diff --git a/packages/common/components/src/ui/lnb/index.tsx b/packages/common/components/src/ui/lnb/index.tsx index b1a7fe094..197a44a9e 100644 --- a/packages/common/components/src/ui/lnb/index.tsx +++ b/packages/common/components/src/ui/lnb/index.tsx @@ -1,7 +1,7 @@ import { useState } from "react"; import { useQuery } from "@tanstack/react-query"; import { ChevronRight } from "lucide-react"; -import { cn } from "../../lib/utils"; +import { cn, setCookie } from "../../lib"; import { ENDPOINT, SITE_ID } from "../../config"; import { getMenuList, type MenuItem } from "../../api"; import { @@ -19,7 +19,15 @@ import { } from "../collapsible"; import { getParentIds } from "./lib"; -export function LNB({ viewOnly }: { viewOnly?: boolean }) { +export function LNB({ + viewOnly, + currentPath, + routeHandler, +}: { + viewOnly?: boolean; + currentPath?: string; + routeHandler?: (path: string) => void; +}) { const { data: menuList } = useQuery({ queryKey: [ENDPOINT.CMS_SERVICE.MENU_ROLES], queryFn: () => getMenuList(SITE_ID), @@ -28,14 +36,31 @@ export function LNB({ viewOnly }: { viewOnly?: boolean }) { const [openMenuIds, setOpenMenuIds] = useState([]); + function isPathMatched(path: string) { + return currentPath === path || currentPath?.startsWith(`${path}/`); + } + function MenuItem({ item }: { item: MenuItem }) { + const isMatched = isPathMatched(item.urlPath); + + const handleClick = () => { + setCookie("menu-code-key", item.menuCd.toString()); + routeHandler?.(item.urlPath); + }; + if (item.children) { return ; } return ( - + {item.menuKornNm} @@ -44,7 +69,11 @@ export function LNB({ viewOnly }: { viewOnly?: boolean }) { } function MenuGroup({ item }: { item: MenuItem }) { - const isOpen = openMenuIds.includes(item.menuCd); + const hasMatchedChild = item.children?.some((child) => + isPathMatched(child.urlPath), + ); + + const isOpen = openMenuIds.includes(item.menuCd) || hasMatchedChild; const handleOpenChange = (open: boolean) => { if (open) {