From cd5acbab768cd067b1344a755d7e75d8ecff03a5 Mon Sep 17 00:00:00 2001 From: "Kalana B. Thilakarathna" Date: Sat, 29 Aug 2026 20:36:01 +0530 Subject: [PATCH] fix(dashboard): handle null responses in widget data fetching --- .../components/dashboard/widgets/active-rides-widget.tsx | 4 ++-- .../components/dashboard/widgets/loading-sheets-widget.tsx | 4 ++-- .../components/dashboard/widgets/pending-pos-widget.tsx | 4 ++-- .../components/dashboard/widgets/recent-orders-widget.tsx | 2 +- .../components/dashboard/widgets/stock-alerts-widget.tsx | 2 +- .../components/dashboard/widgets/today-sales-widget.tsx | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/distribution_fe/components/dashboard/widgets/active-rides-widget.tsx b/distribution_fe/components/dashboard/widgets/active-rides-widget.tsx index 60a5056..9e8f305 100644 --- a/distribution_fe/components/dashboard/widgets/active-rides-widget.tsx +++ b/distribution_fe/components/dashboard/widgets/active-rides-widget.tsx @@ -15,8 +15,8 @@ export function ActiveRidesWidget() { setLoading(true) try { const res = await rides.list({ status: 'Active', pageSize: 5, page: 1 }) - setData(res.items) - setTotal(res.total) + setData(res.items ?? []) + setTotal(res.total ?? 0) } catch { // silent — widget shows empty state } finally { diff --git a/distribution_fe/components/dashboard/widgets/loading-sheets-widget.tsx b/distribution_fe/components/dashboard/widgets/loading-sheets-widget.tsx index 0a5686b..c342630 100644 --- a/distribution_fe/components/dashboard/widgets/loading-sheets-widget.tsx +++ b/distribution_fe/components/dashboard/widgets/loading-sheets-widget.tsx @@ -31,8 +31,8 @@ export function LoadingSheetsWidget() { setLoading(true) try { const res = await loadingSheets.list({ status: 'Pending', pageSize: 5, page: 1 }) - setData(res.items) - setTotal(res.total) + setData(res.items ?? []) + setTotal(res.total ?? 0) } catch { // silent } finally { diff --git a/distribution_fe/components/dashboard/widgets/pending-pos-widget.tsx b/distribution_fe/components/dashboard/widgets/pending-pos-widget.tsx index b72c94b..17861a8 100644 --- a/distribution_fe/components/dashboard/widgets/pending-pos-widget.tsx +++ b/distribution_fe/components/dashboard/widgets/pending-pos-widget.tsx @@ -14,8 +14,8 @@ export function PendingPOsWidget() { setLoading(true) try { const res = await purchaseOrders.list({ status: 'Issued', pageSize: 5, page: 1 }) - setData(res.items) - setTotal(res.total) + setData(res.items ?? []) + setTotal(res.total ?? 0) } catch { // silent } finally { diff --git a/distribution_fe/components/dashboard/widgets/recent-orders-widget.tsx b/distribution_fe/components/dashboard/widgets/recent-orders-widget.tsx index 2c8d12a..126cd73 100644 --- a/distribution_fe/components/dashboard/widgets/recent-orders-widget.tsx +++ b/distribution_fe/components/dashboard/widgets/recent-orders-widget.tsx @@ -21,7 +21,7 @@ export function RecentOrdersWidget() { setLoading(true) try { const res = await orders.list({ pageSize: 6, page: 1 }) - setData(res.items) + setData(res.items ?? []) } catch { // silent } finally { diff --git a/distribution_fe/components/dashboard/widgets/stock-alerts-widget.tsx b/distribution_fe/components/dashboard/widgets/stock-alerts-widget.tsx index ee009b0..40566ef 100644 --- a/distribution_fe/components/dashboard/widgets/stock-alerts-widget.tsx +++ b/distribution_fe/components/dashboard/widgets/stock-alerts-widget.tsx @@ -16,7 +16,7 @@ export function StockAlertsWidget() { setLoading(true) try { const res = await stock.balances({ pageSize: 100, page: 1 }) - const low = res.items.filter(b => b.quantity <= LOW_STOCK_THRESHOLD) + const low = (res.items ?? []).filter(b => b.quantity <= LOW_STOCK_THRESHOLD) setAlerts(low) } catch { // silent diff --git a/distribution_fe/components/dashboard/widgets/today-sales-widget.tsx b/distribution_fe/components/dashboard/widgets/today-sales-widget.tsx index cddc5d2..bfec0bb 100644 --- a/distribution_fe/components/dashboard/widgets/today-sales-widget.tsx +++ b/distribution_fe/components/dashboard/widgets/today-sales-widget.tsx @@ -15,8 +15,8 @@ export function TodaySalesWidget() { const today = new Date().toISOString().split('T')[0] try { const res = await sales.list({ from: today, to: today, pageSize: 50, page: 1 }) - setItems(res.items) - setTotal(res.total) + setItems(res.items ?? []) + setTotal(res.total ?? 0) } catch { // silent } finally {