diff --git a/dashboard/src/components/dashboard/MiniSalesChart.jsx b/dashboard/src/components/dashboard/MiniSalesChart.jsx index 0f5853a..3ed14b2 100644 --- a/dashboard/src/components/dashboard/MiniSalesChart.jsx +++ b/dashboard/src/components/dashboard/MiniSalesChart.jsx @@ -19,7 +19,7 @@ import { import { DateTime } from "luxon"; import { Skeleton } from "@/components/ui/skeleton"; import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; -import { AlertCircle, TrendingUp, DollarSign, ShoppingCart } from "lucide-react"; +import { AlertCircle, TrendingUp, DollarSign, ShoppingCart, Truck, PiggyBank, ArrowUp,ArrowDown, Banknote, Package } from "lucide-react"; import { formatCurrency, CustomTooltip, processData, StatCard } from "./SalesChart.jsx"; const SkeletonChart = () => ( @@ -57,22 +57,56 @@ const SkeletonChart = () => ( ); -const MiniStatCard = memo(({ title, value, icon: Icon, colorClass, iconColor, iconBackground, background }) => ( +const MiniStatCard = memo(({ + title, + value, + icon: Icon, + colorClass, + iconColor, + iconBackground, + background, + previousValue, + trend, + trendValue +}) => ( {title} {Icon && ( -
+
- +
)} -
- {value} +
+
+
+ {value} +
+
+ Prev: {previousValue} + {trend && ( + + {trend === "up" ? ( + + ) : ( + + )} + {trendValue} + + )} +
+
@@ -87,6 +121,12 @@ const MiniSalesChart = ({ className = "" }) => { const [summaryStats, setSummaryStats] = useState({ totalRevenue: 0, totalOrders: 0, + prevRevenue: 0, + prevOrders: 0, + growth: { + revenue: 0, + orders: 0 + } }); const fetchData = useCallback(async () => { @@ -112,14 +152,31 @@ const MiniSalesChart = ({ className = "" }) => { const processedData = processData(stats); - // Calculate totals + // Calculate totals and growth const totals = stats.reduce((acc, day) => ({ totalRevenue: acc.totalRevenue + (Number(day.revenue) || 0), totalOrders: acc.totalOrders + (Number(day.orders) || 0), - }), { totalRevenue: 0, totalOrders: 0 }); + prevRevenue: acc.prevRevenue + (Number(day.prevRevenue) || 0), + prevOrders: acc.prevOrders + (Number(day.prevOrders) || 0), + }), { + totalRevenue: 0, + totalOrders: 0, + prevRevenue: 0, + prevOrders: 0 + }); + + // Calculate growth percentages + const growth = { + revenue: totals.prevRevenue > 0 + ? ((totals.totalRevenue - totals.prevRevenue) / totals.prevRevenue) * 100 + : 0, + orders: totals.prevOrders > 0 + ? ((totals.totalOrders - totals.prevOrders) / totals.prevOrders) * 100 + : 0 + }; setData(processedData); - setSummaryStats(totals); + setSummaryStats({ ...totals, growth }); setError(null); } catch (error) { console.error("Error fetching data:", error); @@ -161,8 +218,11 @@ const MiniSalesChart = ({ className = "" }) => { = 0 ? "up" : "down"} + trendValue={`${Math.abs(Math.round(summaryStats.growth.revenue))}%`} colorClass="text-emerald-200" - icon={DollarSign} + icon={PiggyBank} iconColor="text-emerald-900" iconBackground="bg-emerald-300" background="bg-gradient-to-br from-emerald-900 to-emerald-800" @@ -170,8 +230,11 @@ const MiniSalesChart = ({ className = "" }) => { = 0 ? "up" : "down"} + trendValue={`${Math.abs(Math.round(summaryStats.growth.orders))}%`} colorClass="text-blue-200" - icon={ShoppingCart} + icon={Truck} iconColor="text-blue-900" iconBackground="bg-blue-300" background="bg-gradient-to-br from-blue-900 to-blue-800" diff --git a/dashboard/src/components/dashboard/MiniStatCards.jsx b/dashboard/src/components/dashboard/MiniStatCards.jsx index 91a3484..c868773 100644 --- a/dashboard/src/components/dashboard/MiniStatCards.jsx +++ b/dashboard/src/components/dashboard/MiniStatCards.jsx @@ -387,7 +387,7 @@ const MiniStatCards = ({ description={ stats?.periodProgress < 100 ? (
- Projected: + Proj: {projectionLoading ? ( ) : ( diff --git a/dashboard/src/components/dashboard/StatCards.jsx b/dashboard/src/components/dashboard/StatCards.jsx index 39fe9f9..afceb98 100644 --- a/dashboard/src/components/dashboard/StatCards.jsx +++ b/dashboard/src/components/dashboard/StatCards.jsx @@ -1044,13 +1044,13 @@ const StatCard = ({ )}
{Icon && ( -
+
{variant === 'mini' && iconBackground && (
)} - +
)}