[apps/cs] feat: 임시저장 메뉴 미리보기 기능 작업
This commit is contained in:
@@ -1,7 +1,15 @@
|
|||||||
|
import { useState } from "react";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import type { UseFormReturn } from "react-hook-form";
|
import type { UseFormReturn } from "react-hook-form";
|
||||||
import { useConfirm } from "@frontend-opensource/use-react-hooks";
|
import { useConfirm } from "@frontend-opensource/use-react-hooks";
|
||||||
import { Button } from "@common/components";
|
import {
|
||||||
|
Button,
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
LNB,
|
||||||
|
} from "@common/components";
|
||||||
import { MenuApi, menuFormSchema, type MenuFormData } from "@/entities/menu";
|
import { MenuApi, menuFormSchema, type MenuFormData } from "@/entities/menu";
|
||||||
import { ManagementAuthorityDialog } from "@/entities/menu-authority";
|
import { ManagementAuthorityDialog } from "@/entities/menu-authority";
|
||||||
import { Form } from "@/shared/ui/form";
|
import { Form } from "@/shared/ui/form";
|
||||||
@@ -33,7 +41,7 @@ function MenuForm({
|
|||||||
handleDelete,
|
handleDelete,
|
||||||
}: MenuFormProps) {
|
}: MenuFormProps) {
|
||||||
const isModifyMode = !!menuCd;
|
const isModifyMode = !!menuCd;
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
const { confirm } = useConfirm();
|
const { confirm } = useConfirm();
|
||||||
const alert = useAlertStore((state) => state.setMessage);
|
const alert = useAlertStore((state) => state.setMessage);
|
||||||
|
|
||||||
@@ -96,55 +104,82 @@ function MenuForm({
|
|||||||
const isSubmitDisabled = !form.watch("siteId");
|
const isSubmitDisabled = !form.watch("siteId");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form {...form}>
|
<>
|
||||||
<form onSubmit={form.handleSubmit(onSubmit)}>
|
<Form {...form}>
|
||||||
<div className="card card-border">
|
<form onSubmit={form.handleSubmit(onSubmit)}>
|
||||||
<div className="card-header">
|
<div className="card card-border">
|
||||||
<h3 className="text-2xl font-medium text-label">
|
<div className="card-header">
|
||||||
{isModifyMode ? "메뉴 수정" : "메뉴 등록"}
|
<h3 className="text-2xl font-medium text-label">
|
||||||
</h3>
|
{isModifyMode ? "메뉴 수정" : "메뉴 등록"}
|
||||||
<div className="flex items-center gap-2">
|
</h3>
|
||||||
<MenuHistoryDialog menuCd={menuCd} />
|
<div className="flex items-center gap-2">
|
||||||
<ManagementAuthorityDialog menuCd={menuCd} />
|
<MenuHistoryDialog menuCd={menuCd} />
|
||||||
|
<ManagementAuthorityDialog menuCd={menuCd} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="card">
|
||||||
|
<BaseMenuForm form={form} menuCd={menuCd} />
|
||||||
|
<TypeMenuForm form={form} menuType={menuType} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="card">
|
<div className="flex justify-center gap-4 pb-12 pt-10">
|
||||||
<BaseMenuForm form={form} menuCd={menuCd} />
|
{isModifyMode && (
|
||||||
<TypeMenuForm form={form} menuType={menuType} />
|
<Button
|
||||||
|
size="lg"
|
||||||
|
color="white"
|
||||||
|
type="button"
|
||||||
|
onClick={handleLoadTemporaryData}
|
||||||
|
>
|
||||||
|
불러오기
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
{isModifyMode && (
|
||||||
|
<Button
|
||||||
|
size="lg"
|
||||||
|
color="gray"
|
||||||
|
type="button"
|
||||||
|
onClick={handleMenuTemporaryStorage}
|
||||||
|
>
|
||||||
|
임시저장
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
{isModifyMode && (
|
||||||
|
<Button
|
||||||
|
size="lg"
|
||||||
|
color="emerald"
|
||||||
|
type="button"
|
||||||
|
onClick={() => setOpen(true)}
|
||||||
|
>
|
||||||
|
미리보기
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
<Button size="lg" type="submit" disabled={isSubmitDisabled}>
|
||||||
|
저장
|
||||||
|
</Button>
|
||||||
|
{isModifyMode && (
|
||||||
|
<Button size="lg" color="red" type="button" onClick={onDelete}>
|
||||||
|
삭제
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</form>
|
||||||
<div className="flex justify-center gap-4 pb-12 pt-10">
|
</Form>
|
||||||
{isModifyMode && (
|
<Dialog open={open} onOpenChange={setOpen}>
|
||||||
<Button
|
<DialogContent className="max-h-[90vh]">
|
||||||
size="lg"
|
<DialogHeader>
|
||||||
color="white"
|
<DialogTitle>메뉴 미리보기</DialogTitle>
|
||||||
type="button"
|
</DialogHeader>
|
||||||
onClick={handleLoadTemporaryData}
|
<div className="flex h-full min-h-[60vh] flex-col gap-4">
|
||||||
>
|
<LNB
|
||||||
불러오기
|
currentPath={form.watch("urlPath") ?? ""}
|
||||||
</Button>
|
propSiteId={form.watch("siteId")}
|
||||||
)}
|
previewMode
|
||||||
{isModifyMode && (
|
classNames={{ wrapper: "static h-full border-none p-0" }}
|
||||||
<Button
|
/>
|
||||||
size="lg"
|
</div>
|
||||||
color="gray"
|
</DialogContent>
|
||||||
type="button"
|
</Dialog>
|
||||||
onClick={handleMenuTemporaryStorage}
|
</>
|
||||||
>
|
|
||||||
임시저장
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
<Button size="lg" type="submit" disabled={isSubmitDisabled}>
|
|
||||||
저장
|
|
||||||
</Button>
|
|
||||||
{isModifyMode && (
|
|
||||||
<Button size="lg" color="red" type="button" onClick={onDelete}>
|
|
||||||
삭제
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</Form>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,10 @@ export interface MenuItem {
|
|||||||
requiredUrlPath: boolean;
|
requiredUrlPath: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface TreeMenu extends MenuItem {
|
||||||
|
menuHlpCn: string;
|
||||||
|
}
|
||||||
|
|
||||||
const client = getApiClient();
|
const client = getApiClient();
|
||||||
|
|
||||||
export const getMenuList = async (siteId: string) => {
|
export const getMenuList = async (siteId: string) => {
|
||||||
@@ -29,3 +33,10 @@ export const getMenuList = async (siteId: string) => {
|
|||||||
);
|
);
|
||||||
return response.data;
|
return response.data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getPreviewTreeMenuList = async (siteId: string) => {
|
||||||
|
const response = await client.get<TreeMenu[]>(
|
||||||
|
`${ENDPOINT.CMS_SERVICE.MENUS}/${siteId}/tree/preview`,
|
||||||
|
);
|
||||||
|
return response.data;
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
export const ENDPOINT = {
|
export const ENDPOINT = {
|
||||||
CMS_SERVICE: {
|
CMS_SERVICE: {
|
||||||
|
MENUS: "/cms-service/api/v1/menus",
|
||||||
MENU_ROLES: "/cms-service/api/v1/menu-roles",
|
MENU_ROLES: "/cms-service/api/v1/menu-roles",
|
||||||
SITES: "/cms-service/api/v1/sites",
|
SITES: "/cms-service/api/v1/sites",
|
||||||
POPUPS: "/cms-service/api/v1/popups",
|
POPUPS: "/cms-service/api/v1/popups",
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ export * from "./icon-finder";
|
|||||||
export * from "./input";
|
export * from "./input";
|
||||||
export * from "./label";
|
export * from "./label";
|
||||||
export * from "./layout";
|
export * from "./layout";
|
||||||
|
export * from "./lnb";
|
||||||
export * from "./loading";
|
export * from "./loading";
|
||||||
export * from "./page-title";
|
export * from "./page-title";
|
||||||
export * from "./popover";
|
export * from "./popover";
|
||||||
|
|||||||
@@ -3,9 +3,7 @@
|
|||||||
import { useState, useEffect, useRef } from "react";
|
import { useState, useEffect, useRef } from "react";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import { ChevronRight } from "lucide-react";
|
import { ChevronRight } from "lucide-react";
|
||||||
import { ENDPOINT } from "../../config";
|
import { getParentIds } from "./lib";
|
||||||
import { cn, setCookie } from "../../lib";
|
|
||||||
import { getMenuList, type MenuItem } from "../../api";
|
|
||||||
import {
|
import {
|
||||||
Sidebar,
|
Sidebar,
|
||||||
SidebarContent,
|
SidebarContent,
|
||||||
@@ -22,29 +20,47 @@ import {
|
|||||||
CollapsibleContent,
|
CollapsibleContent,
|
||||||
CollapsibleTrigger,
|
CollapsibleTrigger,
|
||||||
} from "../collapsible";
|
} from "../collapsible";
|
||||||
import { getParentIds } from "./lib";
|
import { ENDPOINT } from "../../config";
|
||||||
import { getCookie } from "../../lib";
|
import { cn, getCookie, setCookie } from "../../lib";
|
||||||
|
import { getMenuList, getPreviewTreeMenuList, type MenuItem } from "../../api";
|
||||||
const siteId = getCookie("site-id-key") ?? "";
|
|
||||||
|
|
||||||
export function LNB({
|
export function LNB({
|
||||||
viewOnly,
|
viewOnly,
|
||||||
currentPath,
|
currentPath,
|
||||||
|
propSiteId,
|
||||||
|
previewMode,
|
||||||
|
classNames,
|
||||||
handleMenuClick,
|
handleMenuClick,
|
||||||
}: {
|
}: {
|
||||||
viewOnly?: boolean;
|
viewOnly?: boolean;
|
||||||
currentPath?: string;
|
currentPath?: string;
|
||||||
|
propSiteId?: string;
|
||||||
|
previewMode?: boolean;
|
||||||
|
classNames?: {
|
||||||
|
wrapper?: string;
|
||||||
|
};
|
||||||
handleMenuClick?: (item: MenuItem) => void;
|
handleMenuClick?: (item: MenuItem) => void;
|
||||||
}) {
|
}) {
|
||||||
const { data: menuList } = useQuery({
|
|
||||||
queryKey: [ENDPOINT.CMS_SERVICE.MENU_ROLES],
|
|
||||||
queryFn: () => getMenuList(siteId),
|
|
||||||
enabled: !viewOnly,
|
|
||||||
});
|
|
||||||
|
|
||||||
const [defaultOpenMenuIds, setDefaultOpenMenuIds] = useState<number[]>([]);
|
const [defaultOpenMenuIds, setDefaultOpenMenuIds] = useState<number[]>([]);
|
||||||
const prevPathRef = useRef(currentPath);
|
const prevPathRef = useRef(currentPath);
|
||||||
|
|
||||||
|
const cookieSiteId = getCookie("site-id-key") ?? "";
|
||||||
|
const siteId = propSiteId ?? cookieSiteId;
|
||||||
|
|
||||||
|
const { data: menuListData } = useQuery({
|
||||||
|
queryKey: [ENDPOINT.CMS_SERVICE.MENU_ROLES],
|
||||||
|
queryFn: () => getMenuList(siteId),
|
||||||
|
enabled: !viewOnly && !previewMode,
|
||||||
|
});
|
||||||
|
|
||||||
|
const { data: previewTreeMenuListData } = useQuery({
|
||||||
|
queryKey: [ENDPOINT.CMS_SERVICE.MENUS, siteId, "preview"],
|
||||||
|
queryFn: () => getPreviewTreeMenuList(siteId),
|
||||||
|
enabled: previewMode,
|
||||||
|
});
|
||||||
|
|
||||||
|
const menuList = previewMode ? previewTreeMenuListData : menuListData;
|
||||||
|
|
||||||
function isPathMatched(path: string) {
|
function isPathMatched(path: string) {
|
||||||
if (!path) return false;
|
if (!path) return false;
|
||||||
return currentPath?.startsWith(path);
|
return currentPath?.startsWith(path);
|
||||||
@@ -191,7 +207,10 @@ export function LNB({
|
|||||||
return (
|
return (
|
||||||
<Sidebar
|
<Sidebar
|
||||||
collapsible="icon"
|
collapsible="icon"
|
||||||
className="border-border bg-background px-4 py-[6rem]"
|
className={cn(
|
||||||
|
"border-border bg-background px-4 py-[6rem]",
|
||||||
|
classNames?.wrapper,
|
||||||
|
)}
|
||||||
>
|
>
|
||||||
<SidebarContent className="bg-background">
|
<SidebarContent className="bg-background">
|
||||||
<SidebarMenu className="gap-0">
|
<SidebarMenu className="gap-0">
|
||||||
|
|||||||
Reference in New Issue
Block a user