import { useQuery } from "@tanstack/react-query"; import { jsonQuery } from "../../lib/apiAdapter"; interface Batch { id: number; quantity: number; unit_price: number; received_at: string; is_consumed: boolean; } interface BatchesResponse { batches: Batch[]; total_stock: number; reserved_quantity: number; available_quantity: number; } interface BatchPickerProps { itemId: number | null; value: number | null; onChange: (batchId: number, unitPrice: number) => void; } export default function BatchPicker({ itemId, value, onChange, }: BatchPickerProps) { const { data: response } = useQuery({ queryKey: ["warehouse", "batches", itemId], queryFn: () => jsonQuery( `/api/admin/warehouse/items/${itemId}/batches`, ), enabled: !!itemId, }); const batches = response?.batches ?? []; return (
{response && response.reserved_quantity > 0 && (
Dostupné: {response.available_quantity} ks (z toho rezervováno:{" "} {response.reserved_quantity} ks)
)}
); }