feat(frontend): add React UI — procurement office, wizard, suppliers, inventory panel (dash port), role-based login
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
// ============================================================
|
||||
// hooks تأمینکنندهها و دستهها
|
||||
// ============================================================
|
||||
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import type { Supplier } from "../lib/types";
|
||||
import { api } from "../lib/api";
|
||||
import { useAppStore } from "../store";
|
||||
import { useInvalidateStore } from "./useStoreData";
|
||||
|
||||
export function useSuppliers(): Supplier[] {
|
||||
return useAppStore((s) => s.suppliers);
|
||||
}
|
||||
|
||||
export function useAddSupplier() {
|
||||
const addSupplier = useAppStore((s) => s.addSupplier);
|
||||
const invalidate = useInvalidateStore();
|
||||
return useMutation({
|
||||
mutationFn: (s: Supplier) => api.suppliers.create(s),
|
||||
onMutate: (s) => addSupplier(s),
|
||||
onSettled: () => invalidate(),
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateSupplier() {
|
||||
const updateSupplier = useAppStore((s) => s.updateSupplier);
|
||||
const invalidate = useInvalidateStore();
|
||||
return useMutation({
|
||||
mutationFn: (args: { id: string; patch: Partial<Supplier> }) => api.suppliers.update(args.id, args.patch),
|
||||
onMutate: (args) => updateSupplier(args.id, args.patch),
|
||||
onSettled: () => invalidate(),
|
||||
});
|
||||
}
|
||||
|
||||
export function useRemoveSupplier() {
|
||||
const deleteSupplier = useAppStore((s) => s.deleteSupplier);
|
||||
const invalidate = useInvalidateStore();
|
||||
return useMutation({
|
||||
mutationFn: (id: string) => api.suppliers.delete(id),
|
||||
onMutate: (id) => deleteSupplier(id),
|
||||
onSettled: () => invalidate(),
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user