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
This commit is contained in:
michaelschal committed 2025-08-11 21:22:28 +00:00
1 parent 79cf87d067
commit 25af55c840
2 files changed
+17 -3

No files matched your search

+16 -2
View File
@@ -4,10 +4,13 @@ import { TrendingUp, Package, Truck, Clock } from "lucide-react";
import { useStore } from "./Layout"; import { useStore } from "./Layout";
import { useAuthUnified } from "@/hooks/useAuthUnified"; 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 { selectedStoreId } = useStore();
const { user } = useAuthUnified(); const { user } = useAuthUnified();
const currentDate = new Date();
const year = currentDate.getFullYear(); const year = currentDate.getFullYear();
const month = currentDate.getMonth() + 1; const month = currentDate.getMonth() + 1;
@@ -16,6 +19,17 @@ export default function StatsPanel() {
const { data: stats, isLoading } = useQuery({ const { data: stats, isLoading } = useQuery({
queryKey: [statsUrl, selectedStoreId], // Include selectedStoreId in key to force refetch 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) { if (isLoading) {
+1 -1
View File
@@ -267,7 +267,7 @@ export default function Calendar() {
)} )}
{/* Stats Panel */} {/* Stats Panel */}
<StatsPanel /> <StatsPanel currentDate={currentDate} />
</div> </div>
); );
} }