update project
This commit is contained in:
@@ -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],
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user