refactor: menu wrapper에서 useQuery 제거

This commit is contained in:
2025-04-02 15:33:51 +09:00
parent a9739bdba5
commit 4e4bd82009
3 changed files with 13 additions and 16 deletions
+1 -4
View File
@@ -3,7 +3,6 @@
import { usePathname, useRouter } from "next/navigation";
import type { MenuItem } from "@common/components/api";
import { BaseLayout } from "@common/components/ui";
import { MenuWrapper } from "@/entities/menu";
import { useMenuStore } from "@/shared/lib";
import { PageLayout } from "@/shared/ui/page-layout";
@@ -23,9 +22,7 @@ export default function WithBaseLayout({
return (
<BaseLayout currentPath={pathname ?? ""} handleMenuClick={handleMenuClick}>
<MenuWrapper>
<PageLayout>{children}</PageLayout>
</MenuWrapper>
<PageLayout>{children}</PageLayout>
</BaseLayout>
);
}
+2 -1
View File
@@ -2,6 +2,7 @@
import { ConfirmProvider } from "@frontend-opensource/use-react-hooks";
import { AuthWrapper } from "@/entities/auth";
import { MenuWrapper } from "@/entities/menu";
import { StoreProvider } from "@/shared/providers";
import { AlertDialog } from "@/shared/ui/alert-dialog";
@@ -10,7 +11,7 @@ const AppProvider = ({ children }: Readonly<{ children: React.ReactNode }>) => {
<StoreProvider>
<ConfirmProvider>
<AuthWrapper>
{children}
<MenuWrapper>{children}</MenuWrapper>
<AlertDialog />
</AuthWrapper>
</ConfirmProvider>
+10 -11
View File
@@ -2,27 +2,26 @@
import { useEffect } from "react";
import { usePathname } from "next/navigation";
import { useQuery } from "@tanstack/react-query";
import { ENDPOINT, SITE_ID } from "@/shared/config";
import { SITE_ID } from "@/shared/config";
import { useMenuStore } from "@/shared/lib";
import { MenuApi } from "../api/menu-service";
import { getCurrentMenu } from "./utils";
const MenuWrapper = ({ children }: { children: React.ReactNode }) => {
const pathname = usePathname();
const { data: menuRoles } = useQuery({
queryKey: [ENDPOINT.CMS_SERVICE.MENU_ROLES],
queryFn: () => MenuApi.getMenuRoles(SITE_ID),
});
const { setCurrentMenuInfo } = useMenuStore((state) => state);
useEffect(() => {
if (!menuRoles) return;
const currentMenu = getCurrentMenu(menuRoles, pathname ?? "");
(async () => {
const menuRoles = await MenuApi.getMenuRoles(SITE_ID);
if (!menuRoles) return;
if (!currentMenu) return;
setCurrentMenuInfo(currentMenu);
}, [menuRoles]);
const currentMenu = getCurrentMenu(menuRoles, pathname ?? "");
if (!currentMenu) return;
setCurrentMenuInfo(currentMenu);
})();
}, []);
return <>{children}</>;
};