[common/features] refactor: PageLayout menuPaths 쿼리 데이터로 수정
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useMenuStore } from "@/shared/lib";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import { MenuApi } from "@/entities/menu";
|
||||||
|
import { ENDPOINT } from "@/shared/config";
|
||||||
|
import { getCookie, useMenuStore } from "@/shared/lib";
|
||||||
import { PageLayout } from "@/shared/ui/page-layout";
|
import { PageLayout } from "@/shared/ui/page-layout";
|
||||||
|
|
||||||
export default function PostLayout({
|
export default function PostLayout({
|
||||||
@@ -8,13 +11,19 @@ export default function PostLayout({
|
|||||||
}: {
|
}: {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
}) {
|
}) {
|
||||||
|
const menuCd = getCookie("menu-code-key");
|
||||||
const bbsInfo = useMenuStore((state) => state.bbsInfo);
|
const bbsInfo = useMenuStore((state) => state.bbsInfo);
|
||||||
|
|
||||||
|
const { data } = useQuery({
|
||||||
|
queryKey: [ENDPOINT.CMS_SERVICE.MENUS, menuCd],
|
||||||
|
queryFn: () => MenuApi.getMenuInfo(menuCd!),
|
||||||
|
enabled: !!menuCd,
|
||||||
|
});
|
||||||
|
|
||||||
|
const menuPaths = data?.menuPath?.split(">").map((path) => path.trim());
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageLayout
|
<PageLayout title={bbsInfo?.bbsNm ?? ""} menuPaths={menuPaths ?? []}>
|
||||||
title={bbsInfo?.bbsNm ?? ""}
|
|
||||||
menuPaths={["서비스관리", "게시판관리"]}
|
|
||||||
>
|
|
||||||
{children}
|
{children}
|
||||||
</PageLayout>
|
</PageLayout>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,14 +1,21 @@
|
|||||||
import { client } from "@/shared/api";
|
import { client } from "@/shared/api";
|
||||||
import { ENDPOINT } from "@/shared/config";
|
import { ENDPOINT } from "@/shared/config";
|
||||||
import type { MenuItem, MenuService } from "../model/menu-interface";
|
import type { MenuInfo, MenuRole, MenuService } from "../model/menu-interface";
|
||||||
|
|
||||||
export class MenuApiService implements MenuService {
|
export class MenuApiService implements MenuService {
|
||||||
async getMenuRoles(siteId: string): Promise<MenuItem[]> {
|
async getMenuRoles(siteId: string): Promise<MenuRole[]> {
|
||||||
const response = await client.get<MenuItem[]>(
|
const response = await client.get<MenuRole[]>(
|
||||||
`${ENDPOINT.CMS_SERVICE.MENU_ROLES}/${siteId}`,
|
`${ENDPOINT.CMS_SERVICE.MENU_ROLES}/${siteId}`,
|
||||||
);
|
);
|
||||||
return response.data;
|
return response.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getMenuInfo(menuCd: string): Promise<MenuInfo> {
|
||||||
|
const response = await client.get<MenuInfo>(
|
||||||
|
`${ENDPOINT.CMS_SERVICE.MENUS}/${menuCd}`,
|
||||||
|
);
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const MenuApi = new MenuApiService();
|
export const MenuApi = new MenuApiService();
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
|
export { MenuApi } from "./api/menu-service";
|
||||||
export { MenuWrapper } from "./lib/menu-wrapper";
|
export { MenuWrapper } from "./lib/menu-wrapper";
|
||||||
export type { MenuItem } from "./model/menu-interface";
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import type { MenuItem } from "../model/menu-interface";
|
import type { MenuRole } from "../model/menu-interface";
|
||||||
|
|
||||||
export const getCurrentMenu = (
|
export const getCurrentMenu = (
|
||||||
menus: MenuItem[],
|
menus: MenuRole[],
|
||||||
pathname: string,
|
pathname: string,
|
||||||
): MenuItem | null => {
|
): MenuRole | null => {
|
||||||
for (const menu of menus) {
|
for (const menu of menus) {
|
||||||
if (
|
if (
|
||||||
menu.urlPath !== "" &&
|
menu.urlPath !== "" &&
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
export interface MenuItem {
|
interface Menu {
|
||||||
menuCd: number;
|
menuCd: number;
|
||||||
menuKornNm: string;
|
menuKornNm: string;
|
||||||
menuEngNm: string;
|
menuEngNm: string;
|
||||||
parentId: number | null;
|
|
||||||
sortSeq: number;
|
sortSeq: number;
|
||||||
iconNm?: string;
|
|
||||||
children: MenuItem[] | null;
|
|
||||||
levelNo: number;
|
levelNo: number;
|
||||||
urlPath: string;
|
urlPath: string;
|
||||||
menuLnkgTypeCd: string;
|
menuLnkgTypeCd: string;
|
||||||
@@ -15,9 +12,30 @@ export interface MenuItem {
|
|||||||
useYn: string;
|
useYn: string;
|
||||||
otptYn: string;
|
otptYn: string;
|
||||||
newWndwYn: string;
|
newWndwYn: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface MenuRole extends Menu {
|
||||||
|
parentId: number | null;
|
||||||
|
iconNm?: string;
|
||||||
|
children: MenuRole[] | null;
|
||||||
requiredUrlPath: boolean;
|
requiredUrlPath: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MenuService {
|
export interface MenuInfo extends Menu {
|
||||||
getMenuRoles(siteId: string): Promise<MenuItem[]>;
|
siteId: string;
|
||||||
|
menuSubKornNm: string;
|
||||||
|
menuSubEngNm: string;
|
||||||
|
iconName: string;
|
||||||
|
menuLnkgTypeCdNm: string;
|
||||||
|
prntMenuCd: number;
|
||||||
|
evlUseYn: string;
|
||||||
|
menuLnkgSnNm: string;
|
||||||
|
menuPicUserUnqId: string;
|
||||||
|
menuPicUserUnqIdNm: string;
|
||||||
|
menuPicDsgnYmd: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface MenuService {
|
||||||
|
getMenuRoles(siteId: string): Promise<MenuRole[]>;
|
||||||
|
getMenuInfo(menuCd: string): Promise<MenuInfo>;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user