From 82e931ef42d25911c9398e32457a78cf311a198c Mon Sep 17 00:00:00 2001 From: chavda-bhavik Date: Wed, 23 Oct 2024 19:19:56 +0530 Subject: [PATCH] feat: Closed project modal on creation --- apps/web/hooks/useProject.tsx | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/apps/web/hooks/useProject.tsx b/apps/web/hooks/useProject.tsx index bfa83fb1..276e002f 100644 --- a/apps/web/hooks/useProject.tsx +++ b/apps/web/hooks/useProject.tsx @@ -44,23 +44,6 @@ export function useProject() { }, }); - const onSubmit = (data: ICreateProjectData) => { - if (data.name.trim()) { - createProject( - { name: data.name.trim() }, - { - onSuccess: () => { - queryClient.invalidateQueries([API_KEYS.PROJECTS_LIST]); - reset(); - }, - onError: () => {}, - } - ); - } else { - setError('name', { type: 'manual', message: 'Project name is required' }); - } - }; - const { data: projects, isLoading: isProjectsLoading } = useQuery( [API_KEYS.PROJECTS_LIST], () => commonApi(API_KEYS.PROJECTS_LIST as any, {}) @@ -83,10 +66,12 @@ export function useProject() { ICreateProjectData >([API_KEYS.PROJECT_CREATE], (data) => commonApi(API_KEYS.PROJECT_CREATE as any, { body: data }), { onSuccess: ({ project }) => { + reset(); queryClient.setQueryData([API_KEYS.PROJECTS_LIST], () => [...(projects || []), project]); track({ name: 'PROJECT CREATE', properties: { duringOnboard: false } }); replace(ROUTES.HOME); refetchMeData(); + modals.close(MODAL_KEYS.MANAGE_PROJECT_MODAL); notify(NOTIFICATION_KEYS.PROJECT_CREATED, { title: 'Project created', message: `Project ${project.name} created successfully`, @@ -187,6 +172,14 @@ export function useProject() { } }; + const onSubmit = (data: ICreateProjectData) => { + if (data.name.trim()) { + createProject({ name: data.name.trim() }); + } else { + setError('name', { type: 'manual', message: 'Project name is required' }); + } + }; + return { register, handleSubmit,