From eb274e62c4345c885bde412817abb3a462d287f0 Mon Sep 17 00:00:00 2001 From: Dhananjaya99 <152056742+ashanruu@users.noreply.github.com> Date: Wed, 14 Oct 2026 17:22:19 +0530 Subject: [PATCH] Remove sample trend data and update chart rendering logic for better handling of empty trends --- Frontend/erp-system/app/dashboard/page.tsx | 33 +++++++++------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/Frontend/erp-system/app/dashboard/page.tsx b/Frontend/erp-system/app/dashboard/page.tsx index f00c9e9..33625f4 100644 --- a/Frontend/erp-system/app/dashboard/page.tsx +++ b/Frontend/erp-system/app/dashboard/page.tsx @@ -41,11 +41,6 @@ function isoDate(d: Date) { return d.toISOString().slice(0, 10) } -// Shown only when the last TREND_DAYS days have no real ledger activity, so the -// chart isn't a flat zero line before there's any real movement to plot. -const SAMPLE_TREND_IN = [42, 58, 35, 70, 64, 30, 20, 85, 46, 55, 38, 62, 48, 72] -const SAMPLE_TREND_OUT = [30, 40, 45, 38, 50, 22, 15, 60, 33, 47, 28, 44, 36, 58] - export default function DashboardPage() { const { activeBranchId, branchingEnabled } = useAuth() @@ -98,13 +93,9 @@ export default function DashboardPage() { const labels = days.map((d) => new Date(d).toLocaleDateString(undefined, { day: "numeric", month: "short" })) - if (!trend || trend.length === 0) { - return { labels, inData: SAMPLE_TREND_IN, outData: SAMPLE_TREND_OUT } - } - const inByDay = new Map(days.map((d) => [d, 0])) const outByDay = new Map(days.map((d) => [d, 0])) - for (const entry of trend) { + for (const entry of trend ?? []) { const day = entry.createdAt.slice(0, 10) const bucket = entry.direction === "In" ? inByDay : outByDay if (bucket.has(day)) bucket.set(day, (bucket.get(day) ?? 0) + entry.qtyBase) @@ -213,15 +204,19 @@ export default function DashboardPage() { {loaded ? ( -
- -
+ movementTrend.inData.some((v) => v > 0) || movementTrend.outData.some((v) => v > 0) ? ( +
+ +
+ ) : ( +

No stock movement in the last {TREND_DAYS} days.

+ ) ) : ( !error && )}