mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-13 18:28:38 +02:00
Improve calendar display stability and data handling
Add robust error handling and data validation to the calendar component and API routes to prevent production crashes, specifically addressing issues with invalid publicity data and ensuring array types for fetched data. 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/FL119j1
This commit is contained in:
1 parent
d276021d3b
commit
e46922bd56
3 files changed
+94
-68
No files matched your search
@@ -171,6 +171,14 @@ 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
|
||||
});
|
||||
const monthStart = startOfMonth(currentDate);
|
||||
const monthEnd = endOfMonth(currentDate);
|
||||
|
||||
@@ -178,29 +186,42 @@ export default function CalendarGrid({
|
||||
const getPublicitiesForDate = (date: Date) => {
|
||||
const dateStr = format(date, 'yyyy-MM-dd');
|
||||
|
||||
// Protection contre les données invalides qui causent des plantages en production
|
||||
if (!publicities || !Array.isArray(publicities)) {
|
||||
console.warn('⚠️ Invalid publicities data:', publicities);
|
||||
return [];
|
||||
}
|
||||
|
||||
console.log('🔍 CalendarGrid getPublicitiesForDate:', {
|
||||
date: dateStr,
|
||||
totalPublicities: publicities.length,
|
||||
selectedStoreId,
|
||||
userGroups: userGroups.length
|
||||
userGroups: userGroups?.length || 0
|
||||
});
|
||||
|
||||
if (publicities.length > 0) {
|
||||
console.log('📄 Sample publicity structure:', publicities[0]);
|
||||
}
|
||||
|
||||
return publicities.filter(pub => {
|
||||
try {
|
||||
return publicities.filter(pub => {
|
||||
// Vérifications de sécurité pour éviter les plantages
|
||||
if (!pub || typeof pub !== 'object') {
|
||||
console.warn('⚠️ Invalid publicity object:', pub);
|
||||
return false;
|
||||
}
|
||||
// Check if the date is within the publicity period
|
||||
const pubStart = pub.startDate;
|
||||
const pubEnd = pub.endDate;
|
||||
|
||||
if (!pubStart || !pubEnd) {
|
||||
console.warn('⚠️ Publicity missing dates:', { pubNumber: pub.pubNumber, startDate: pubStart, endDate: pubEnd });
|
||||
return false;
|
||||
}
|
||||
|
||||
if (dateStr < pubStart || dateStr > pubEnd) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 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 && pub.participations.length > 0;
|
||||
const hasParticipations = pub.participations && Array.isArray(pub.participations) && pub.participations.length > 0;
|
||||
if (hasParticipations) {
|
||||
console.log('📋 Publicity has participations (no store selected):', { pubNumber: pub.pubNumber, participationCount: pub.participations.length });
|
||||
}
|
||||
@@ -209,7 +230,8 @@ export default function CalendarGrid({
|
||||
|
||||
// If a specific store is selected, check if that store participates
|
||||
if (selectedStoreId) {
|
||||
const matches = pub.participations?.some((pg: any) => pg.groupId === selectedStoreId);
|
||||
const matches = pub.participations && Array.isArray(pub.participations) &&
|
||||
pub.participations.some((pg: any) => pg?.groupId === selectedStoreId);
|
||||
if (matches) {
|
||||
console.log('🎯 Publicity matches selected store:', { pubNumber: pub.pubNumber, selectedStoreId });
|
||||
}
|
||||
@@ -218,9 +240,10 @@ export default function CalendarGrid({
|
||||
|
||||
// If no specific store selected but user has assigned stores,
|
||||
// show publicities where any of user's stores participate
|
||||
if (userGroups && userGroups.length > 0) {
|
||||
const userGroupIds = userGroups.map((ug: any) => ug.groupId);
|
||||
const matches = pub.participations?.some((pg: any) => userGroupIds.includes(pg.groupId));
|
||||
if (userGroups && Array.isArray(userGroups) && userGroups.length > 0) {
|
||||
const userGroupIds = userGroups.map((ug: any) => ug?.groupId).filter(id => id !== undefined);
|
||||
const matches = pub.participations && Array.isArray(pub.participations) &&
|
||||
pub.participations.some((pg: any) => pg?.groupId && userGroupIds.includes(pg.groupId));
|
||||
if (matches) {
|
||||
console.log('👥 Publicity matches user groups:', { pubNumber: pub.pubNumber, userGroupIds });
|
||||
}
|
||||
@@ -228,12 +251,16 @@ export default function CalendarGrid({
|
||||
}
|
||||
|
||||
// Default case: only show publicities with participations
|
||||
const hasParticipations = pub.participations && pub.participations.length > 0;
|
||||
const hasParticipations = pub.participations && Array.isArray(pub.participations) && pub.participations.length > 0;
|
||||
if (hasParticipations) {
|
||||
console.log('📋 Publicity has participations (default case):', { pubNumber: pub.pubNumber, participationCount: pub.participations.length });
|
||||
}
|
||||
return hasParticipations;
|
||||
});
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('❌ Error filtering publicities:', error);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
// Get all days in the month
|
||||
|
||||
Reference in new issue
Block a user