Files
ERP/frontend/src/hooks/useMaterials.ts
T

24 lines
828 B
TypeScript

// ============================================================
// hooks مواد (کالاها) — دسته‌ی جدید هم یک material است
// ============================================================
import { useMutation } from "@tanstack/react-query";
import type { Material } from "../lib/types";
import { api } from "../lib/api";
import { useAppStore } from "../store";
import { useInvalidateStore } from "./useStoreData";
export function useMaterials(): Material[] {
return useAppStore((s) => s.materials);
}
export function useAddMaterial() {
const addMaterial = useAppStore((s) => s.addMaterial);
const invalidate = useInvalidateStore();
return useMutation({
mutationFn: (m: Material) => api.materials.create(m),
onMutate: (m) => addMaterial(m),
onSettled: () => invalidate(),
});
}