import { useCallback, useEffect, useState } from 'react' import { Link, useSearchParams } from 'react-router-dom' import { ApiHttpError } from '../../api/http' import { fetchInventoryDashboard } from '../../api/inventory' import { INVENTORY_BOOK_BASE } from './inventoryPaths' /** * Inventory Dashboard — summary counts by type, low stock, out of stock, etc. * Backend: GET /api/v1/administrator/inventory/dashboard */ export function InventoryDashboardPage() { const [searchParams] = useSearchParams() const [data, setData] = useState>({}) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) const load = useCallback(() => { setLoading(true) fetchInventoryDashboard(searchParams) .then((res) => { if (res && typeof res === 'object') { setData(res as Record) } setError(null) }) .catch((e: unknown) => { setError(e instanceof ApiHttpError ? e.message : 'Unable to load dashboard.') }) .finally(() => setLoading(false)) }, [searchParams]) useEffect(() => { load() }, [load]) const byType = (data.by_type as Record) ?? {} const totalItems = Number(data.total_items ?? 0) const lowStockCount = Number(data.low_stock_count ?? 0) const outOfStockCount = Number(data.out_of_stock_count ?? 0) const needsRepairCount = Number(data.needs_repair_count ?? 0) const missingCount = Number(data.missing_count ?? 0) return (

Inventory Dashboard

Stock Status Back to Items
{error ?
{error}
: null} {loading ? (

Loading…

) : (
{/* Summary Cards */}
{totalItems}

Total Items

{lowStockCount}

Low Stock Items

{lowStockCount > 0 ? ( View Low Stock ) : null}
{outOfStockCount}

Out of Stock

{needsRepairCount}

Needs Repair

{missingCount}

Missing / Cannot Find

{/* Items by Type */}
Items by Type
{Object.keys(byType).length === 0 ? (

No items found.

) : (
{Object.entries(byType).map(([type, count]) => ( ))}
Type Count
{type} {Number(count).toLocaleString()}
)}
{/* Quick Links */}
Quick Actions
Classroom Equipment Books Office Supplies Kitchen Supplies Movements Summary Reorder Suggestions Low Stock
)}
) }