diff --git a/inventory/src/components/dashboard/TopReplenishProducts.tsx b/inventory/src/components/dashboard/TopReplenishProducts.tsx index dc50ab5..2f538cb 100644 --- a/inventory/src/components/dashboard/TopReplenishProducts.tsx +++ b/inventory/src/components/dashboard/TopReplenishProducts.tsx @@ -4,23 +4,29 @@ import { ScrollArea } from "@/components/ui/scroll-area" import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table" import config from "@/config" -interface Product { - pid: number; - sku: string; - title: string; - stock_quantity: number; - daily_sales_avg: string; - reorder_qty: number; - last_purchase_date: string | null; +interface ReplenishmentMetricsData { + productsToReplenish: number; + unitsToReplenish: number; + replenishmentCost: number; + replenishmentRetail: number; + topVariants: { + id: number; + title: string; + currentStock: number; + replenishQty: number; + replenishCost: number; + replenishRetail: number; + status: string; + }[]; } export function TopReplenishProducts() { - const { data } = useQuery({ - queryKey: ["top-replenish-products"], + const { data } = useQuery({ + queryKey: ["replenishment-metrics"], queryFn: async () => { - const response = await fetch(`${config.apiUrl}/dashboard/replenish/products?limit=50`) + const response = await fetch(`${config.apiUrl}/dashboard/replenishment/metrics`) if (!response.ok) { - throw new Error("Failed to fetch products to replenish") + throw new Error("Failed to fetch replenishment metrics") } return response.json() }, @@ -38,29 +44,28 @@ export function TopReplenishProducts() { Product Stock - Daily Sales Reorder Qty - Last Purchase + Cost + Status - {data?.map((product) => ( - + {data?.topVariants?.map((product) => ( + {product.title} -
{product.sku}
- {product.stock_quantity} - {Number(product.daily_sales_avg).toFixed(1)} - {product.reorder_qty} - {product.last_purchase_date ? product.last_purchase_date : '-'} + {product.currentStock} + {product.replenishQty} + ${product.replenishCost.toFixed(2)} + {product.status}
))}