project list
This commit is contained in:
@@ -1,15 +1,23 @@
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import * as api from "../service/ProjectService";
|
||||
import { CreateProjectType } from "../types/ProjectTypes";
|
||||
|
||||
export const useGetProjectsByWorkspace = (workspaceId: string) => {
|
||||
return useQuery({
|
||||
queryKey: ["projects", workspaceId],
|
||||
queryFn: () => api.getProjectsByWorkspace(workspaceId),
|
||||
enabled: !!workspaceId,
|
||||
});
|
||||
};
|
||||
|
||||
export const useCreateProject = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (variables: CreateProjectType) => api.createProject(variables),
|
||||
onSuccess: () => {
|
||||
onSuccess: (_data, variables) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ["projects"],
|
||||
queryKey: ["projects", variables.workspaceId],
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user