import { useCallback, useEffect, useState } from 'react' import { Link } from 'react-router-dom' import { ApiHttpError } from '../../api/http' import { fetchLowStock } from '../../api/inventory' import { INVENTORY_BOOK_BASE } from './inventoryPaths' /** * Low Stock Items — items where quantity <= reorder_point. * Backend: GET /api/v1/administrator/inventory/low-stock */ export function InventoryLowStockPage() { const [items, setItems] = useState[]>([]) const [count, setCount] = useState(0) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) const load = useCallback(() => { setLoading(true) fetchLowStock() .then((res) => { if (res && typeof res === 'object') { const o = res as Record const arr = Array.isArray(o.items) ? (o.items as Record[]) : [] setItems(arr) setCount(Number(o.count ?? arr.length)) } setError(null) }) .catch((e: unknown) => { setError(e instanceof ApiHttpError ? e.message : 'Unable to load low stock items.') }) .finally(() => setLoading(false)) }, []) useEffect(() => { load() }, [load]) return (

Low Stock Items ({count})

Reorder Suggestions Back to Items
{error ?
{error}
: null} {loading ? (

Loading…

) : items.length === 0 ? (
All stocked up! No items are below their reorder point.
) : (
{items.map((item) => { const i = item as Record const supplier = i.preferred_supplier as Record | null return ( ) })}
Name Type Category Current Qty Reorder Point Reorder Qty Lead Time (Days) Preferred Supplier Actions
{String(i.name ?? '')} {String(i.type ?? '')} {String((i.category as Record)?.name ?? i.category ?? '')} {Number(i.quantity ?? 0).toLocaleString()} {Number(i.reorder_point ?? 0).toLocaleString()} {Number(i.reorder_quantity ?? 0).toLocaleString() || '—'} {Number(i.lead_time_days ?? 0) || '—'} {supplier ? String(supplier.name ?? '') : '—'} Adjust Stock
)}
) }