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
+32
-10
@@ -48,44 +48,66 @@ export default function MobileCalendarPage() {
|
||||
const [currentMonth, setCurrentMonth] = useState(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 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() {
|
||||
<CardContent className="p-3">
|
||||
<div className="flex items-start gap-3">
|
||||
<div className={`p-2 rounded-lg ${event.type === 'order'
|
||||
? 'bg-blue-100'
|
||||
: 'bg-green-100'
|
||||
? 'bg-blue-100'
|
||||
: 'bg-green-100'
|
||||
}`}>
|
||||
{event.type === 'order'
|
||||
? <Package className="h-4 w-4 text-blue-600" />
|
||||
|
||||
Reference in new issue
Block a user