24 lines
759 B
TypeScript
24 lines
759 B
TypeScript
// ============================================================
|
|
// hooks پروژهها
|
|
// ============================================================
|
|
|
|
import { useMutation } from "@tanstack/react-query";
|
|
import type { Project } from "../lib/types";
|
|
import { api } from "../lib/api";
|
|
import { useAppStore } from "../store";
|
|
import { useInvalidateStore } from "./useStoreData";
|
|
|
|
export function useProjects(): Project[] {
|
|
return useAppStore((s) => s.projects);
|
|
}
|
|
|
|
export function useAddProject() {
|
|
const addProject = useAppStore((s) => s.addProject);
|
|
const invalidate = useInvalidateStore();
|
|
return useMutation({
|
|
mutationFn: (p: Project) => api.projects.create(p),
|
|
onMutate: (p) => addProject(p),
|
|
onSettled: () => invalidate(),
|
|
});
|
|
}
|