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
This commit is contained in:
michaelschal committed 2025-07-09 19:06:34 +00:00
1 parent 4384818f63
commit b71148da46
3 files changed
+12 -5

No files matched your search

+2 -1
View File
@@ -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",
+2 -1
View File
@@ -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",
+8 -3
View File
@@ -149,9 +149,14 @@ export async function registerRoutes(app: Express): Promise<Server> {
// 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) {