import { useState, useEffect, useMemo } from 'react'; import { Plus, Printer, ChevronRight, CalendarDays } from 'lucide-react'; import { format, startOfMonth, endOfMonth, eachDayOfInterval, isToday, getDay } from 'date-fns'; import { ru } from 'date-fns/locale'; import { useDeliveryStore } from '../stores/deliveryStore'; import type { Delivery } from '../types'; import { pickupLocationLabels } from '../types'; import { Button } from '../components/ui/Button'; import { Card } from '../components/ui/Card'; interface DashboardProps { onDateSelect: (date: string) => void; onAddDelivery: () => void; } const Dashboard = ({ onDateSelect, onAddDelivery }: DashboardProps) => { const deliveryCounts = useDeliveryStore(state => state.deliveryCounts); const fetchDeliveryCounts = useDeliveryStore(state => state.fetchDeliveryCounts); const [currentMonth, setCurrentMonth] = useState(new Date()); // Fetch counts on mount useEffect(() => { fetchDeliveryCounts(); }, [fetchDeliveryCounts]); const days = useMemo(() => { const monthStart = startOfMonth(currentMonth); const monthEnd = endOfMonth(currentMonth); return eachDayOfInterval({ start: monthStart, end: monthEnd }); }, [currentMonth]); const getCountForDate = (date: Date) => { const dateStr = format(date, 'dd-MM-yyyy'); return deliveryCounts[dateStr] || 0; }; const handlePrintDay = (date: Date) => { const dateStr = format(date, 'dd-MM-yyyy'); const fetchDeliveriesByDate = useDeliveryStore.getState().fetchDeliveriesByDate; // Fetch and print fetchDeliveriesByDate(dateStr).then(() => { const deliveries = useDeliveryStore.getState().deliveries; printDeliveries(date, deliveries); }); }; const printDeliveries = (date: Date, dayDeliveries: Delivery[]) => { const printWindow = window.open('', '_blank'); if (!printWindow) return; const html = `
| Загрузка | Товар | Клиент | Адрес | Телефон | Услуги | Комментарий |
|---|---|---|---|---|---|---|
| ${d.pickupLocation2 ? pickupLocationLabels[d.pickupLocation] + ' + ' + pickupLocationLabels[d.pickupLocation2] : pickupLocationLabels[d.pickupLocation]} | ${d.productName}${d.productName2 ? ' + ' + d.productName2 + '' : ''} |
${d.customerName} |
ул. ${d.street}, д. ${d.house}${d.apartment ? ', кв. ' + d.apartment : ''}
${d.entrance || d.floor ? ' ' + (d.entrance ? 'Подъезд ' + d.entrance : '') + (d.entrance && d.floor ? ', ' : '') + (d.floor ? 'этаж ' + d.floor : '') + '' : ''} |
${d.phone} | ${d.serviceInfo || '-'} | ${d.comment || '-'} |
Выберите дату для просмотра доставок
Нет запланированных доставок