From b71148da4671e838006680d93a8590126cf55d55 Mon Sep 17 00:00:00 2001 From: michaelschal <35957947-michaelschal@users.noreply.replit.com> Date: Wed, 9 Jul 2025 19:06:34 +0000 Subject: [PATCH] Make sales history update reliably after adding or removing sales Invalidate all sales queries instead of exact matches and handle missing store ID. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 91318273-c764-4fd4-be04-bdc12c38af32 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/0715008c-7244-40f4-befc-26c014852236/aec99dd8-53a6-474d-8bf0-cdc42edf20c7.jpg --- client/src/components/NewSaleForm.tsx | 3 ++- client/src/components/SalesHistory.tsx | 3 ++- server/routes.ts | 11 ++++++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/client/src/components/NewSaleForm.tsx b/client/src/components/NewSaleForm.tsx index f470698..bdf4285 100644 --- a/client/src/components/NewSaleForm.tsx +++ b/client/src/components/NewSaleForm.tsx @@ -75,7 +75,8 @@ export default function NewSaleForm() { return response.json(); }, onSuccess: () => { - queryClient.invalidateQueries({ queryKey: ['/api/sales'] }); + // Invalidate all sales queries to refresh the history + queryClient.invalidateQueries({ queryKey: ['/api/sales'], exact: false }); toast({ title: "Vente enregistrée", description: "La vente a été enregistrée avec succès", diff --git a/client/src/components/SalesHistory.tsx b/client/src/components/SalesHistory.tsx index 912b45f..e83f678 100644 --- a/client/src/components/SalesHistory.tsx +++ b/client/src/components/SalesHistory.tsx @@ -52,7 +52,8 @@ export default function SalesHistory({ canDelete = false }: SalesHistoryProps) { mutationFn: (saleId: number) => apiRequest(`/api/sales/${saleId}`, { method: 'DELETE' }), onSuccess: () => { - queryClient.invalidateQueries({ queryKey: ['/api/sales'] }); + // Invalidate all sales queries to refresh the history + queryClient.invalidateQueries({ queryKey: ['/api/sales'], exact: false }); toast({ title: "Vente supprimée", description: "La vente a été supprimée avec succès", diff --git a/server/routes.ts b/server/routes.ts index f46dad9..c7d34a1 100644 --- a/server/routes.ts +++ b/server/routes.ts @@ -149,9 +149,14 @@ export async function registerRoutes(app: Express): Promise { // Determine which store to query let targetStoreId: number; - if (user.role === 'admin' && storeId) { - // Admin can query any store - targetStoreId = parseInt(storeId as string); + if (user.role === 'admin') { + if (storeId) { + // Admin querying a specific store + targetStoreId = parseInt(storeId as string); + } else { + // Admin without specific store - should not happen with the new frontend + return res.status(400).json({ error: "Store ID required for admin queries" }); + } } else { // Non-admin users can only query their own store if (!user.storeId) {