mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-11 17:27:31 +02:00
Merge pull request #540 from R0m1k3/1.1
feat: add mobile calendar page to display orders and deliveries as ev…
This commit is contained in:
1 file changed
+30
-8
@@ -48,44 +48,66 @@ export default function MobileCalendarPage() {
|
|||||||
const [currentMonth, setCurrentMonth] = useState(new Date());
|
const [currentMonth, setCurrentMonth] = useState(new Date());
|
||||||
const [selectedDate, setSelectedDate] = useState<Date | null>(new Date());
|
const [selectedDate, setSelectedDate] = useState<Date | null>(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 monthStart = startOfMonth(currentMonth);
|
||||||
const monthEnd = endOfMonth(currentMonth);
|
const monthEnd = endOfMonth(currentMonth);
|
||||||
|
|
||||||
// Fetch orders for current month
|
// Fetch orders for current month
|
||||||
const { data: orders = [] } = useQuery({
|
const { data: orders = [], isLoading: loadingOrders } = useQuery({
|
||||||
queryKey: ["/api/orders", selectedStoreId, format(currentMonth, 'yyyy-MM')],
|
queryKey: ["/api/orders", selectedStoreId, format(currentMonth, 'yyyy-MM')],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
|
const start = format(startOfMonth(currentMonth), 'yyyy-MM-dd');
|
||||||
|
const end = format(endOfMonth(currentMonth), 'yyyy-MM-dd');
|
||||||
|
|
||||||
const params = new URLSearchParams({
|
const params = new URLSearchParams({
|
||||||
startDate: format(monthStart, 'yyyy-MM-dd'),
|
startDate: start,
|
||||||
endDate: format(monthEnd, 'yyyy-MM-dd')
|
endDate: end
|
||||||
});
|
});
|
||||||
if (selectedStoreId) params.append('storeId', selectedStoreId.toString());
|
if (selectedStoreId) params.append('storeId', selectedStoreId.toString());
|
||||||
|
|
||||||
|
console.log('📅 Mobile Calendar fetching orders:', { start, end, selectedStoreId });
|
||||||
|
|
||||||
const response = await fetch(`/api/orders?${params}`, {
|
const response = await fetch(`/api/orders?${params}`, {
|
||||||
credentials: 'include'
|
credentials: 'include'
|
||||||
});
|
});
|
||||||
if (!response.ok) return [];
|
if (!response.ok) {
|
||||||
|
console.error('❌ Orders fetch failed:', response.status);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
console.log('📦 Orders received:', Array.isArray(data) ? data.length : 'NOT_ARRAY', data);
|
||||||
return Array.isArray(data) ? data : [];
|
return Array.isArray(data) ? data : [];
|
||||||
},
|
},
|
||||||
enabled: !!user,
|
enabled: !!user,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// Fetch deliveries for current month
|
// Fetch deliveries for current month
|
||||||
const { data: deliveries = [] } = useQuery({
|
const { data: deliveries = [], isLoading: loadingDeliveries } = useQuery({
|
||||||
queryKey: ["/api/deliveries", selectedStoreId, format(currentMonth, 'yyyy-MM')],
|
queryKey: ["/api/deliveries", selectedStoreId, format(currentMonth, 'yyyy-MM')],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
|
const start = format(startOfMonth(currentMonth), 'yyyy-MM-dd');
|
||||||
|
const end = format(endOfMonth(currentMonth), 'yyyy-MM-dd');
|
||||||
|
|
||||||
const params = new URLSearchParams({
|
const params = new URLSearchParams({
|
||||||
startDate: format(monthStart, 'yyyy-MM-dd'),
|
startDate: start,
|
||||||
endDate: format(monthEnd, 'yyyy-MM-dd')
|
endDate: end
|
||||||
});
|
});
|
||||||
if (selectedStoreId) params.append('storeId', selectedStoreId.toString());
|
if (selectedStoreId) params.append('storeId', selectedStoreId.toString());
|
||||||
|
|
||||||
|
console.log('📅 Mobile Calendar fetching deliveries:', { start, end, selectedStoreId });
|
||||||
|
|
||||||
const response = await fetch(`/api/deliveries?${params}`, {
|
const response = await fetch(`/api/deliveries?${params}`, {
|
||||||
credentials: 'include'
|
credentials: 'include'
|
||||||
});
|
});
|
||||||
if (!response.ok) return [];
|
if (!response.ok) {
|
||||||
|
console.error('❌ Deliveries fetch failed:', response.status);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
console.log('🚚 Deliveries received:', Array.isArray(data) ? data.length : 'NOT_ARRAY', data);
|
||||||
return Array.isArray(data) ? data : [];
|
return Array.isArray(data) ? data : [];
|
||||||
},
|
},
|
||||||
enabled: !!user,
|
enabled: !!user,
|
||||||
|
|||||||
Reference in new issue
Block a user