Skip to content

Commit

Permalink
feat: Closed project modal on creation
Browse files Browse the repository at this point in the history
  • Loading branch information
chavda-bhavik committed Oct 23, 2024
1 parent 86d516d commit 82e931e
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions apps/web/hooks/useProject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<IProjectPayload[], IErrorObject>(
[API_KEYS.PROJECTS_LIST],
() => commonApi<IProjectPayload[]>(API_KEYS.PROJECTS_LIST as any, {})
Expand All @@ -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<IProjectPayload[]>([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`,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 82e931e

Please sign in to comment.