diff --git a/apps/cs/middleware.ts b/apps/cs/middleware.ts index 4d6d816a7..c9284d69b 100644 --- a/apps/cs/middleware.ts +++ b/apps/cs/middleware.ts @@ -8,10 +8,12 @@ export function middleware(req: NextRequest) { const searchParams = req.nextUrl.searchParams; if (pathname.startsWith("/server")) { - const newUrl = new URL( - `${serverApiUrl}${pathname.replace("/server", "")}?${searchParams.toString() ?? ""}`, - ); - return NextResponse.rewrite(newUrl); + const queryParams = searchParams.toString(); + const newUrl = `${serverApiUrl}${pathname.replace("/server", "")}${ + queryParams ? `?${queryParams}` : "" + }`; + console.log("Rewriting to: ", newUrl); + return NextResponse.rewrite(new URL(newUrl)); } return NextResponse.next(); diff --git a/apps/cs/src/app/providers/app-provider.tsx b/apps/cs/src/app/providers/app-provider.tsx index caf3b98f7..b14c3dc96 100644 --- a/apps/cs/src/app/providers/app-provider.tsx +++ b/apps/cs/src/app/providers/app-provider.tsx @@ -2,20 +2,18 @@ import { ConfirmProvider } from "@frontend-opensource/use-react-hooks"; import { AuthWrapper } from "@/entities/auth"; -import { QueryProvider, StoreProvider } from "@/shared/providers"; +import { StoreProvider } from "@/shared/providers"; import { AlertDialog } from "@/shared/ui/alert-dialog"; const AppProvider = ({ children }: Readonly<{ children: React.ReactNode }>) => { return ( - - - - {children} - - - - + + + {children} + + + ); }; diff --git a/apps/cs/src/pages/site/ui/modify-page.tsx b/apps/cs/src/pages/site/ui/modify-page.tsx index d73d79ef6..6cb394eae 100644 --- a/apps/cs/src/pages/site/ui/modify-page.tsx +++ b/apps/cs/src/pages/site/ui/modify-page.tsx @@ -2,7 +2,7 @@ import { useRouter } from "next/navigation"; import { useForm } from "react-hook-form"; -import { useMutation, useQuery } from "@tanstack/react-query"; +import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { zodResolver } from "@hookform/resolvers/zod"; import { ENDPOINT } from "@/shared/config"; import { useAlertStore } from "@/shared/lib/use-alert-store"; @@ -15,6 +15,7 @@ function ModifyPage({ siteId }: { siteId: string }) { const isModifyMode = !!siteId; const router = useRouter(); + const queryClient = useQueryClient(); const { setMessage: alert } = useAlertStore((state) => state); const { data: siteDetail } = useQuery({ queryKey: [ENDPOINT.CMS_SERVICE.SITES, siteId], @@ -36,14 +37,23 @@ function ModifyPage({ siteId }: { siteId: string }) { const { mutateAsync: modifySite } = useMutation({ mutationFn: (data: SiteFormData) => SiteApi.modifySite(siteId, data), onSuccess: () => { - alert("수정되었습니다."); + alert("수정되었습니다.", () => { + queryClient.invalidateQueries({ + queryKey: [ENDPOINT.CMS_SERVICE.SITES], + }); + }); }, }); const { mutateAsync: deleteSite } = useMutation({ mutationFn: () => SiteApi.deleteSite(siteId), onSuccess: () => { - alert("삭제되었습니다.", router.back); + alert("삭제되었습니다.", () => { + queryClient.invalidateQueries({ + queryKey: [ENDPOINT.CMS_SERVICE.SITES], + }); + router.back(); + }); }, }); diff --git a/apps/cs/src/shared/providers/index.ts b/apps/cs/src/shared/providers/index.ts index 5d9f096a3..f2e092170 100644 --- a/apps/cs/src/shared/providers/index.ts +++ b/apps/cs/src/shared/providers/index.ts @@ -1,2 +1 @@ -export { QueryProvider } from "./query-provider"; export { StoreProvider } from "./store-provider"; diff --git a/apps/cs/src/shared/providers/query-provider.tsx b/packages/common/components/src/provider/query-provider.tsx similarity index 50% rename from apps/cs/src/shared/providers/query-provider.tsx rename to packages/common/components/src/provider/query-provider.tsx index f16c42072..5781919f1 100644 --- a/apps/cs/src/shared/providers/query-provider.tsx +++ b/packages/common/components/src/provider/query-provider.tsx @@ -1,9 +1,14 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; -const queryClient = new QueryClient(); - -export const QueryProvider = ({ children }: { children: React.ReactNode }) => { +export function QueryProvider({ + children, + client, +}: { + children: React.ReactNode; + client?: QueryClient; +}) { + const queryClient = client ?? new QueryClient(); return ( {children} ); -}; +} diff --git a/packages/common/components/src/ui/layout/base.tsx b/packages/common/components/src/ui/layout/base.tsx index 1f2ad58a3..9dd778e03 100644 --- a/packages/common/components/src/ui/layout/base.tsx +++ b/packages/common/components/src/ui/layout/base.tsx @@ -1,17 +1,21 @@ -import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; - +import { QueryProvider } from "../../provider/query-provider"; import { SidebarProvider } from "../sidebar"; import { LNB } from "../lnb"; import { Header } from "../header"; import { Footer } from "./footer"; import "./common.css"; +import type { QueryClient } from "@tanstack/react-query"; -const queryClient = new QueryClient(); - -export function BaseLayout({ children }: { children: React.ReactNode }) { +export function BaseLayout({ + children, + queryClient, +}: { + children: React.ReactNode; + queryClient?: QueryClient; +}) { return ( - +
@@ -26,6 +30,6 @@ export function BaseLayout({ children }: { children: React.ReactNode }) {
-
+ ); } diff --git a/packages/common/components/src/ui/layout/vbase.tsx b/packages/common/components/src/ui/layout/vbase.tsx index 43d3fdf1d..63c4e6d27 100644 --- a/packages/common/components/src/ui/layout/vbase.tsx +++ b/packages/common/components/src/ui/layout/vbase.tsx @@ -1,28 +1,35 @@ -import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; - +import { QueryProvider } from "../../provider/query-provider"; +import { SidebarProvider } from "../sidebar"; import { LNB } from "../lnb"; import { Header } from "../header"; import { Footer } from "./footer"; import "./common.css"; +import type { QueryClient } from "@tanstack/react-query"; -const queryClient = new QueryClient(); - -export function VBaseLayout({ children }: { children: React.ReactNode }) { +export function BaseLayout({ + children, + queryClient, +}: { + children: React.ReactNode; + queryClient?: QueryClient; +}) { return ( - -
-
-
- -
-
- {children} + + +
+
+
+ +
+
+ {children} +
+
-
-
- + + ); }