From 25af55c84061d5ca4afa652b982ca75f26dd65c6 Mon Sep 17 00:00:00 2001 From: michaelschal <35957947-michaelschal@users.noreply.replit.com> Date: Mon, 11 Aug 2025 21:22:28 +0000 Subject: [PATCH] Update statistics panel to show data for the current month only Fix StatsPanel component to use a passed-in currentDate prop, defaulting to new Date(), and update Calendar page to pass currentDate to StatsPanel. Refactor useQuery to include fetch logic. Replit-Commit-Author: Agent Replit-Commit-Session-Id: b163d4c0-de5e-4f4e-a9c0-aed4c7049718 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/b163d4c0-de5e-4f4e-a9c0-aed4c7049718/r0JXGx6 --- client/src/components/StatsPanel.tsx | 18 ++++++++++++++++-- client/src/pages/Calendar.tsx | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/client/src/components/StatsPanel.tsx b/client/src/components/StatsPanel.tsx index bbaae5b..6d0f704 100644 --- a/client/src/components/StatsPanel.tsx +++ b/client/src/components/StatsPanel.tsx @@ -4,10 +4,13 @@ import { TrendingUp, Package, Truck, Clock } from "lucide-react"; import { useStore } from "./Layout"; import { useAuthUnified } from "@/hooks/useAuthUnified"; -export default function StatsPanel() { +interface StatsPanelProps { + currentDate?: Date; +} + +export default function StatsPanel({ currentDate = new Date() }: StatsPanelProps) { const { selectedStoreId } = useStore(); const { user } = useAuthUnified(); - const currentDate = new Date(); const year = currentDate.getFullYear(); const month = currentDate.getMonth() + 1; @@ -16,6 +19,17 @@ export default function StatsPanel() { const { data: stats, isLoading } = useQuery({ queryKey: [statsUrl, selectedStoreId], // Include selectedStoreId in key to force refetch + queryFn: async () => { + const response = await fetch(statsUrl, { + credentials: 'include' + }); + + if (!response.ok) { + throw new Error('Failed to fetch stats'); + } + + return response.json(); + }, }); if (isLoading) { diff --git a/client/src/pages/Calendar.tsx b/client/src/pages/Calendar.tsx index 85fc433..2935aaa 100644 --- a/client/src/pages/Calendar.tsx +++ b/client/src/pages/Calendar.tsx @@ -267,7 +267,7 @@ export default function Calendar() { )} {/* Stats Panel */} - + ); }