import { useEffect, useState } from 'react' import { useQuery, useQueryClient } from '@tanstack/react-query' import { Boxes } from 'lucide-react' import { getStores, getStoreInventory, toggleStoreInventory, adjustStoreInventory } from '../api/client' export default function Inventory() { const qc = useQueryClient() const [storeId, setStoreId] = useState(0) const { data: stores } = useQuery({ queryKey: ['inv-stores'], queryFn: () => getStores(false) }) useEffect(() => { if (!storeId && stores?.length) setStoreId(stores[0].id) }, [stores]) const { data: inv } = useQuery({ queryKey: ['store-inv', storeId], queryFn: () => getStoreInventory(storeId), enabled: !!storeId }) const toggle = async (pid: number, available: boolean) => { await toggleStoreInventory(storeId, pid, !available).catch(() => {}); qc.invalidateQueries({ queryKey: ['store-inv', storeId] }) } const adjust = async (pid: number, delta: number) => { await adjustStoreInventory(storeId, pid, delta).catch(() => {}); qc.invalidateQueries({ queryKey: ['store-inv', storeId] }) } return (

Store Inventory (ON/OFF)

Switching to OFF immediately marks the item as out of stock in that store's area.

{(inv || []).map((r: any) => { const available = r.available !== false return ( ) })} {!(inv || []).length && }
ProductStockAdjustSale
{r.productName || `Product #${r.productId}`} {r.stock ?? r.quantity ?? '-'}
No inventory items found.
) }