mirror of
https://github.com/andwati/cymelle.git
synced 2026-11-03 23:42:15 +00:00
23 lines
757 B
TypeScript
23 lines
757 B
TypeScript
import {getInventory, getLowStockInventory} from "#/api/inventory";
|
|
import {useQuery} from "@tanstack/react-query";
|
|
|
|
export const inventoryQueryKeys = {
|
|
all: ["inventory"] as const,
|
|
list: () => [...inventoryQueryKeys.all, "list"] as const,
|
|
lowStock: (threshold?: number) =>
|
|
[...inventoryQueryKeys.all, "low-stock", threshold ?? "default"] as const,
|
|
};
|
|
|
|
export function useInventory() {
|
|
return useQuery({
|
|
queryKey: inventoryQueryKeys.list(),
|
|
queryFn: ({signal}) => getInventory(signal),
|
|
});
|
|
}
|
|
|
|
export function useLowStockInventory(threshold?: number) {
|
|
return useQuery({
|
|
queryKey: inventoryQueryKeys.lowStock(threshold),
|
|
queryFn: ({signal}) => getLowStockInventory(threshold, signal),
|
|
});
|
|
} |