Fix some backend issues, get dashboard loading without crashing

This commit is contained in:
2025-01-17 17:09:26 -05:00
parent 118344b730
commit 6b7a62ffaf
4 changed files with 381 additions and 210 deletions

View File

@@ -14,10 +14,10 @@ import config from "@/config"
interface LowStockProduct {
product_id: number
sku: string
SKU: string
title: string
stock_quantity: number
reorder_point: number
reorder_qty: number
days_of_inventory: number
stock_status: "Critical" | "Reorder"
daily_sales_avg: number
@@ -27,7 +27,7 @@ export function LowStockAlerts() {
const { data: products } = useQuery<LowStockProduct[]>({
queryKey: ["low-stock"],
queryFn: async () => {
const response = await fetch(`${config.apiUrl}/dashboard/inventory/low-stock`)
const response = await fetch(`${config.apiUrl}/dashboard/low-stock/products`)
if (!response.ok) {
throw new Error("Failed to fetch low stock products")
}
@@ -54,10 +54,10 @@ export function LowStockAlerts() {
<TableBody>
{products?.map((product) => (
<TableRow key={product.product_id}>
<TableCell className="font-medium">{product.sku}</TableCell>
<TableCell className="font-medium">{product.SKU}</TableCell>
<TableCell>{product.title}</TableCell>
<TableCell className="text-right">
{product.stock_quantity} / {product.reorder_point}
{product.stock_quantity} / {product.reorder_qty}
</TableCell>
<TableCell className="text-right">
<Badge

View File

@@ -7,11 +7,11 @@ import { formatCurrency } from "@/lib/utils"
interface OverstockedProduct {
product_id: number
sku: string
SKU: string
title: string
overstocked_units: number
overstocked_cost: number
overstocked_retail: number
overstocked_amt: number
excess_cost: number
excess_retail: number
days_of_inventory: number
}
@@ -49,14 +49,14 @@ export function TopOverstockedProducts() {
<TableCell>
<div>
<p className="font-medium">{product.title}</p>
<p className="text-sm text-muted-foreground">{product.sku}</p>
<p className="text-sm text-muted-foreground">{product.SKU}</p>
</div>
</TableCell>
<TableCell className="text-right">
{product.overstocked_units.toLocaleString()}
{product.overstocked_amt.toLocaleString()}
</TableCell>
<TableCell className="text-right">
{formatCurrency(product.overstocked_cost)}
{formatCurrency(product.excess_cost)}
</TableCell>
<TableCell className="text-right">
{product.days_of_inventory}

View File

@@ -13,18 +13,19 @@ import config from "@/config"
interface VendorMetrics {
vendor: string
avg_lead_time_days: number
avg_lead_time: number
on_time_delivery_rate: number
order_fill_rate: number
avg_fill_rate: number
total_orders: number
total_late_orders: number
active_orders: number
overdue_orders: number
}
export function VendorPerformance() {
const { data: vendors } = useQuery<VendorMetrics[]>({
queryKey: ["vendor-metrics"],
queryFn: async () => {
const response = await fetch(`${config.apiUrl}/dashboard/vendors/metrics`)
const response = await fetch(`${config.apiUrl}/dashboard/vendor/performance`)
if (!response.ok) {
throw new Error("Failed to fetch vendor metrics")
}
@@ -66,7 +67,7 @@ export function VendorPerformance() {
</div>
</TableCell>
<TableCell className="text-right">
{vendor.order_fill_rate.toFixed(0)}%
{vendor.avg_fill_rate.toFixed(0)}%
</TableCell>
</TableRow>
))}