49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
"use client";
|
|
|
|
import { usePathname, useRouter } from "next/navigation";
|
|
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
import { BaseLayout } from "@common/components";
|
|
import { MenuApi, type MenuRole } from "@/entities/menu";
|
|
import { ENDPOINT } from "@/shared/config";
|
|
import { getCookie, useMenuStore } from "@/shared/lib";
|
|
import { PageLayout } from "@/shared/ui/page-layout";
|
|
|
|
export default function WithBaseLayout({
|
|
children,
|
|
}: {
|
|
children: React.ReactNode;
|
|
}) {
|
|
const router = useRouter();
|
|
const pathname = usePathname();
|
|
const queryClient = useQueryClient();
|
|
const bbsInfo = useMenuStore((state) => state.bbsInfo);
|
|
|
|
const menuCd = getCookie("menu-code-key");
|
|
const { data } = useQuery({
|
|
queryKey: [ENDPOINT.CMS_SERVICE.MENUS, menuCd],
|
|
queryFn: () => MenuApi.getMenuInfo(menuCd!),
|
|
enabled: !!menuCd,
|
|
});
|
|
|
|
const menuPaths = data?.menuPath?.split(">").map((path) => path.trim());
|
|
|
|
const setCurrentMenuInfo = useMenuStore((state) => state.setCurrentMenuInfo);
|
|
|
|
const handleMenuClick = (item: MenuRole) => {
|
|
setCurrentMenuInfo(item);
|
|
router.push(item.urlPath);
|
|
};
|
|
|
|
return (
|
|
<BaseLayout
|
|
queryClient={queryClient}
|
|
currentPath={pathname ?? ""}
|
|
handleMenuClick={handleMenuClick}
|
|
>
|
|
<PageLayout title={bbsInfo?.bbsNm ?? ""} menuPaths={menuPaths ?? []}>
|
|
{children}
|
|
</PageLayout>
|
|
</BaseLayout>
|
|
);
|
|
}
|