diff --git a/dashboard/src/components/dashboard/MiniSalesChart.jsx b/dashboard/src/components/dashboard/MiniSalesChart.jsx index 3ed14b2..a7a18be 100644 --- a/dashboard/src/components/dashboard/MiniSalesChart.jsx +++ b/dashboard/src/components/dashboard/MiniSalesChart.jsx @@ -67,9 +67,16 @@ const MiniStatCard = memo(({ background, previousValue, trend, - trendValue + trendValue, + onClick, + active = true }) => ( - + {title} @@ -118,6 +125,10 @@ const MiniSalesChart = ({ className = "" }) => { const [data, setData] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); + const [visibleMetrics, setVisibleMetrics] = useState({ + revenue: true, + orders: true + }); const [summaryStats, setSummaryStats] = useState({ totalRevenue: 0, totalOrders: 0, @@ -201,6 +212,13 @@ const MiniSalesChart = ({ className = "" }) => { }); }; + const toggleMetric = (metric) => { + setVisibleMetrics(prev => ({ + ...prev, + [metric]: !prev[metric] + })); + }; + if (error) { return ( @@ -212,7 +230,7 @@ const MiniSalesChart = ({ className = "" }) => { } return ( -
+
{/* Stat Cards */}
{ iconColor="text-emerald-900" iconBackground="bg-emerald-300" background="bg-gradient-to-br from-emerald-900 to-emerald-800" + onClick={() => toggleMetric('revenue')} + active={visibleMetrics.revenue} /> { iconColor="text-blue-900" iconBackground="bg-blue-300" background="bg-gradient-to-br from-blue-900 to-blue-800" + onClick={() => toggleMetric('orders')} + active={visibleMetrics.orders} />
- {/* Chart */} - {loading ? ( - - ) : !data.length ? ( -
-
- -
No sales data available
-
-
- ) : ( -
- - - - - formatCurrency(value, false)} - className="text-[10px] text-gray-300" - tick={{ fill: "currentColor" }} - /> - value.toLocaleString()} - className="text-[10px] text-gray-300" - tick={{ fill: "currentColor" }} - /> - } /> - - - - -
- )} + {/* Chart Card */} + + {loading ? ( + + + + ) : !data.length ? ( + +
+
+ +
No sales data available
+
+
+
+ ) : ( + +
+ + + + + {visibleMetrics.revenue && ( + formatCurrency(value, false)} + className="text-[10px]" + tick={{ fill: "#E9D5FF" }} + /> + )} + {visibleMetrics.orders && ( + value.toLocaleString()} + className="text-[10px]" + tick={{ fill: "#E9D5FF" }} + /> + )} + { + if (active && payload && payload.length) { + const timestamp = new Date(payload[0].payload.timestamp); + return ( + + +

+ {timestamp.toLocaleDateString([], { + weekday: "short", + month: "short", + day: "numeric" + })} +

+ {payload + .filter(entry => visibleMetrics[entry.dataKey]) + .map((entry, index) => ( +
+ + {entry.name}: + + + {entry.dataKey === 'revenue' + ? formatCurrency(entry.value) + : entry.value.toLocaleString()} + +
+ ))} +
+
+ ); + } + return null; + }} + /> + {visibleMetrics.revenue && ( + + )} + {visibleMetrics.orders && ( + + )} +
+
+
+
+ )} +
); };