update project

This commit is contained in:
hamid zarghami
2026-07-11 11:01:01 +03:30
parent 47691a649f
commit 1618b5fb57
7 changed files with 306 additions and 7 deletions
@@ -1,6 +1,6 @@
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import * as api from "../service/ProjectService";
import { CreateProjectType } from "../types/ProjectTypes";
import { CreateProjectType, UpdateProjectType } from "../types/ProjectTypes";
export const useGetProjectsByWorkspace = (workspaceId: string) => {
return useQuery({
@@ -10,6 +10,14 @@ export const useGetProjectsByWorkspace = (workspaceId: string) => {
});
};
export const useGetProjectDetail = (id: string) => {
return useQuery({
queryKey: ["project-detail", id],
queryFn: () => api.getProjectDetail(id),
enabled: !!id,
});
};
export const useCreateProject = () => {
const queryClient = useQueryClient();
@@ -22,3 +30,23 @@ export const useCreateProject = () => {
},
});
};
export const useUpdateProject = () => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: ({
id,
params,
}: {
id: string;
params: UpdateProjectType;
}) => api.updateProject(id, params),
onSuccess: (_data, variables) => {
queryClient.invalidateQueries({ queryKey: ["projects"] });
queryClient.invalidateQueries({
queryKey: ["project-detail", variables.id],
});
},
});
};