diff --git a/client/src/app/projects/preview/page.tsx b/client/src/app/projects/preview/page.tsx index abcd7163..69fc3a1d 100644 --- a/client/src/app/projects/preview/page.tsx +++ b/client/src/app/projects/preview/page.tsx @@ -4,22 +4,10 @@ import { QueryClient, } from "@tanstack/react-query"; -import mockResponse from "@/app/projects/preview/mock-response"; - import CustomProject from "@/containers/projects/custom-project"; -export const CUSTOM_PROJECT_MOCK_QUERYKEY = ["custom-project-mock-data"]; export default function CustomProjectPreviewPage() { - /** - * - * Mimic queryCache from createCustomProject response - * - * This is only for testing purpose with the current mock data, - * and should be replaced when the complete user flow is done - */ - const queryClient = new QueryClient(); - queryClient.setQueryData(CUSTOM_PROJECT_MOCK_QUERYKEY, mockResponse); return ( diff --git a/client/src/containers/projects/new/header.tsx b/client/src/containers/projects/new/header.tsx index 4ee2e6d3..daf76934 100644 --- a/client/src/containers/projects/new/header.tsx +++ b/client/src/containers/projects/new/header.tsx @@ -2,6 +2,8 @@ import { useFormContext } from "react-hook-form"; +import { useRouter } from "next/navigation"; + import { CreateCustomProjectForm } from "@/containers/projects/form/setup"; import { Button } from "@/components/ui/button"; @@ -11,6 +13,7 @@ import { onSubmit } from "./index"; export default function Header() { const methods = useFormContext(); + const router = useRouter(); return (
@@ -22,7 +25,10 @@ export default function Header() { diff --git a/client/src/containers/projects/new/index.tsx b/client/src/containers/projects/new/index.tsx index d5d9c0d5..1e064679 100644 --- a/client/src/containers/projects/new/index.tsx +++ b/client/src/containers/projects/new/index.tsx @@ -28,7 +28,7 @@ import ProjectSidebar from "@/containers/projects/new/sidebar"; import { ScrollArea } from "@/components/ui/scroll-area"; -export const onSubmit = (data: CreateCustomProjectForm) => { +export const onSubmit = async (data: CreateCustomProjectForm) => { const queryClient = getQueryClient(); const originalValues = { ...data }; @@ -97,7 +97,12 @@ export const onSubmit = (data: CreateCustomProjectForm) => { }, }; - client.customProjects.createCustomProject.mutation({ body: data }); + const { status, body } = + await client.customProjects.createCustomProject.mutation({ body: data }); + + if (status === 201) { + queryClient.setQueryData(queryKeys.customProjects.cached.queryKey, body); + } }; export default function CreateCustomProject() { diff --git a/client/src/hooks/use-get-custom-project.ts b/client/src/hooks/use-get-custom-project.ts index f4d12dc7..e445984d 100644 --- a/client/src/hooks/use-get-custom-project.ts +++ b/client/src/hooks/use-get-custom-project.ts @@ -10,13 +10,11 @@ import { client } from "@/lib/query-client"; import { queryKeys } from "@/lib/query-keys"; import { getAuthHeader } from "@/lib/utils"; -import { CUSTOM_PROJECT_MOCK_QUERYKEY } from "@/app/projects/preview/page"; - export function useGetCustomProject(id?: string) { const { data: session } = useSession(); const queryCache = useQueryClient().getQueryData<{ data: InstanceType; - }>(CUSTOM_PROJECT_MOCK_QUERYKEY); + }>(queryKeys.customProjects.cached.queryKey); const getCustomProjectQuery = client.customProjects.getCustomProject.useQuery( queryKeys.customProjects.one(id || "").queryKey, { diff --git a/client/src/lib/query-keys.ts b/client/src/lib/query-keys.ts index fcdcc635..9960e5bf 100644 --- a/client/src/lib/query-keys.ts +++ b/client/src/lib/query-keys.ts @@ -44,6 +44,7 @@ export const tableKeys = createQueryKeys("tables", { }); export const customProjectKeys = createQueryKeys("customProjects", { + cached: null, countries: null, one: (id: string) => [id], assumptions: ({