mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-16 03:40:06 +02:00
Stabilize calendar display by refining data caching and invalidation
Fix an issue where closing an order or delivery card caused all calendar entries to disappear by implementing selective cache invalidation and adjusting cache timings. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 7c468936-2a88-4686-ac0a-84921a45222d Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/7c468936-2a88-4686-ac0a-84921a45222d/B7k6m01
This commit is contained in:
1 parent
e32f83de1f
commit
3b46f945a4
5 files changed
+80
-70
No files matched your search
@@ -171,14 +171,16 @@ export default function CalendarGrid({
|
||||
onDateClick,
|
||||
onItemClick,
|
||||
}: CalendarGridProps) {
|
||||
console.log('🗓️ CalendarGrid rendered with:', {
|
||||
currentDate: currentDate?.toISOString(),
|
||||
ordersCount: orders?.length || 0,
|
||||
deliveriesCount: deliveries?.length || 0,
|
||||
publicitiesCount: publicities?.length || 0,
|
||||
selectedStoreId,
|
||||
userGroupsCount: userGroups?.length || 0
|
||||
});
|
||||
if (import.meta.env.DEV) {
|
||||
console.log('🗓️ CalendarGrid rendered with:', {
|
||||
currentDate: currentDate?.toISOString(),
|
||||
ordersCount: orders?.length || 0,
|
||||
deliveriesCount: deliveries?.length || 0,
|
||||
publicitiesCount: publicities?.length || 0,
|
||||
selectedStoreId,
|
||||
userGroupsCount: userGroups?.length || 0
|
||||
});
|
||||
}
|
||||
const monthStart = startOfMonth(currentDate);
|
||||
const monthEnd = endOfMonth(currentDate);
|
||||
|
||||
@@ -192,12 +194,14 @@ export default function CalendarGrid({
|
||||
return [];
|
||||
}
|
||||
|
||||
console.log('🔍 CalendarGrid getPublicitiesForDate:', {
|
||||
date: dateStr,
|
||||
totalPublicities: publicities.length,
|
||||
selectedStoreId,
|
||||
userGroups: userGroups?.length || 0
|
||||
});
|
||||
if (import.meta.env.DEV) {
|
||||
console.log('🔍 CalendarGrid getPublicitiesForDate:', {
|
||||
date: dateStr,
|
||||
totalPublicities: publicities.length,
|
||||
selectedStoreId,
|
||||
userGroups: userGroups?.length || 0
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
return publicities.filter(pub => {
|
||||
@@ -222,7 +226,7 @@ export default function CalendarGrid({
|
||||
// If no store is selected and user has no assigned groups, show only publicities with participations
|
||||
if (!selectedStoreId && (!userGroups || userGroups.length === 0)) {
|
||||
const hasParticipations = pub.participations && Array.isArray(pub.participations) && pub.participations.length > 0;
|
||||
if (hasParticipations) {
|
||||
if (hasParticipations && import.meta.env.DEV) {
|
||||
console.log('📋 Publicity has participations (no store selected):', { pubNumber: pub.pubNumber, participationCount: pub.participations.length });
|
||||
}
|
||||
return hasParticipations;
|
||||
@@ -232,7 +236,7 @@ export default function CalendarGrid({
|
||||
if (selectedStoreId) {
|
||||
const matches = pub.participations && Array.isArray(pub.participations) &&
|
||||
pub.participations.some((pg: any) => pg?.groupId === selectedStoreId);
|
||||
if (matches) {
|
||||
if (matches && import.meta.env.DEV) {
|
||||
console.log('🎯 Publicity matches selected store:', { pubNumber: pub.pubNumber, selectedStoreId });
|
||||
}
|
||||
return matches;
|
||||
|
||||
@@ -43,8 +43,8 @@ export default function OrderDetailModal({
|
||||
title: "Succès",
|
||||
description: "Commande validée avec succès",
|
||||
});
|
||||
// Invalidation sélective pour éviter la disparition du calendrier
|
||||
queryClient.invalidateQueries({ queryKey: ['/api/orders'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['/api/deliveries'] });
|
||||
onClose();
|
||||
},
|
||||
onError: (error) => {
|
||||
@@ -76,8 +76,8 @@ export default function OrderDetailModal({
|
||||
title: "Succès",
|
||||
description: "Livraison validée avec succès",
|
||||
});
|
||||
// Invalidation sélective pour éviter la disparition du calendrier
|
||||
queryClient.invalidateQueries({ queryKey: ['/api/deliveries'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['/api/orders'] });
|
||||
onClose();
|
||||
},
|
||||
onError: (error) => {
|
||||
@@ -103,37 +103,26 @@ export default function OrderDetailModal({
|
||||
const deleteMutation = useMutation({
|
||||
mutationFn: async (id: number) => {
|
||||
const endpoint = isOrder ? `/api/orders/${id}` : `/api/deliveries/${id}`;
|
||||
console.log(`🗑️ Deleting ${isOrder ? 'order' : 'delivery'}:`, id);
|
||||
if (import.meta.env.DEV) {
|
||||
console.log(`🗑️ Deleting ${isOrder ? 'order' : 'delivery'}:`, id);
|
||||
}
|
||||
await apiRequest(endpoint, "DELETE");
|
||||
},
|
||||
onSuccess: () => {
|
||||
console.log(`✅ ${isOrder ? 'Order' : 'Delivery'} deleted successfully, clearing cache...`);
|
||||
if (import.meta.env.DEV) {
|
||||
console.log(`✅ ${isOrder ? 'Order' : 'Delivery'} deleted successfully`);
|
||||
}
|
||||
toast({
|
||||
title: "Succès",
|
||||
description: `${isOrder ? 'Commande' : 'Livraison'} supprimée avec succès`,
|
||||
});
|
||||
|
||||
// SOLUTION PRODUCTION : Cache clearing radical pour éviter incohérences storeId
|
||||
console.log('🗑️ Cache cleared, forcing page reload to maintain storeId consistency...');
|
||||
|
||||
// SOLUTION HYBRIDE : Invalidation sélective pour éviter perte storeId
|
||||
console.log('🧹 Using selective invalidation to preserve storeId context...');
|
||||
|
||||
// Invalidation ciblée sans clear() pour préserver le contexte
|
||||
queryClient.invalidateQueries({
|
||||
predicate: (query) => {
|
||||
const key = query.queryKey[0]?.toString() || '';
|
||||
return key.includes('/api/orders') || key.includes('/api/deliveries');
|
||||
}
|
||||
});
|
||||
|
||||
// Force refetch pour garantir synchronisation immédiate
|
||||
queryClient.refetchQueries({
|
||||
predicate: (query) => {
|
||||
const key = query.queryKey[0]?.toString() || '';
|
||||
return key.includes('/api/orders') || key.includes('/api/deliveries');
|
||||
}
|
||||
});
|
||||
// Invalidation sélective uniquement pour l'API concernée
|
||||
if (isOrder) {
|
||||
queryClient.invalidateQueries({ queryKey: ['/api/orders'] });
|
||||
} else {
|
||||
queryClient.invalidateQueries({ queryKey: ['/api/deliveries'] });
|
||||
}
|
||||
|
||||
onClose();
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user