diff --git a/client/src/pages/mobile/CalendarPage.tsx b/client/src/pages/mobile/CalendarPage.tsx index 1757152..a5a35e4 100644 --- a/client/src/pages/mobile/CalendarPage.tsx +++ b/client/src/pages/mobile/CalendarPage.tsx @@ -48,44 +48,66 @@ export default function MobileCalendarPage() { const [currentMonth, setCurrentMonth] = useState(new Date()); const [selectedDate, setSelectedDate] = useState(new Date()); + // Debug log - doit apparaรฎtre dans la console + console.log('๐Ÿ—“๏ธ MobileCalendarPage RENDER', { user: !!user, selectedStoreId, currentMonth: currentMonth.toISOString() }); + const monthStart = startOfMonth(currentMonth); const monthEnd = endOfMonth(currentMonth); // Fetch orders for current month - const { data: orders = [] } = useQuery({ + const { data: orders = [], isLoading: loadingOrders } = useQuery({ queryKey: ["/api/orders", selectedStoreId, format(currentMonth, 'yyyy-MM')], queryFn: async () => { + const start = format(startOfMonth(currentMonth), 'yyyy-MM-dd'); + const end = format(endOfMonth(currentMonth), 'yyyy-MM-dd'); + const params = new URLSearchParams({ - startDate: format(monthStart, 'yyyy-MM-dd'), - endDate: format(monthEnd, 'yyyy-MM-dd') + startDate: start, + endDate: end }); if (selectedStoreId) params.append('storeId', selectedStoreId.toString()); + console.log('๐Ÿ“… Mobile Calendar fetching orders:', { start, end, selectedStoreId }); + const response = await fetch(`/api/orders?${params}`, { credentials: 'include' }); - if (!response.ok) return []; + if (!response.ok) { + console.error('โŒ Orders fetch failed:', response.status); + return []; + } const data = await response.json(); + console.log('๐Ÿ“ฆ Orders received:', Array.isArray(data) ? data.length : 'NOT_ARRAY', data); return Array.isArray(data) ? data : []; }, enabled: !!user, }); + // Fetch deliveries for current month - const { data: deliveries = [] } = useQuery({ + const { data: deliveries = [], isLoading: loadingDeliveries } = useQuery({ queryKey: ["/api/deliveries", selectedStoreId, format(currentMonth, 'yyyy-MM')], queryFn: async () => { + const start = format(startOfMonth(currentMonth), 'yyyy-MM-dd'); + const end = format(endOfMonth(currentMonth), 'yyyy-MM-dd'); + const params = new URLSearchParams({ - startDate: format(monthStart, 'yyyy-MM-dd'), - endDate: format(monthEnd, 'yyyy-MM-dd') + startDate: start, + endDate: end }); if (selectedStoreId) params.append('storeId', selectedStoreId.toString()); + console.log('๐Ÿ“… Mobile Calendar fetching deliveries:', { start, end, selectedStoreId }); + const response = await fetch(`/api/deliveries?${params}`, { credentials: 'include' }); - if (!response.ok) return []; + if (!response.ok) { + console.error('โŒ Deliveries fetch failed:', response.status); + return []; + } const data = await response.json(); + console.log('๐Ÿšš Deliveries received:', Array.isArray(data) ? data.length : 'NOT_ARRAY', data); return Array.isArray(data) ? data : []; }, enabled: !!user, @@ -258,8 +280,8 @@ export default function MobileCalendarPage() {
{event.type === 'order' ?