switch frontend to real API instead of mocks
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import { useState } from 'react';
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Plus, Printer, ChevronRight, CalendarDays } from 'lucide-react';
|
||||
import { format, startOfMonth, endOfMonth, eachDayOfInterval, isToday } from 'date-fns';
|
||||
import { ru } from 'date-fns/locale';
|
||||
import { useDeliveryStore } from '../stores/deliveryStore';
|
||||
import type { Delivery } from '../types';
|
||||
import { Button } from '../components/ui/Button';
|
||||
import { Card } from '../components/ui/Card';
|
||||
|
||||
@@ -12,21 +13,36 @@ interface DashboardProps {
|
||||
}
|
||||
|
||||
export const Dashboard = ({ onDateSelect, onAddDelivery }: DashboardProps) => {
|
||||
const deliveries = useDeliveryStore(state => state.deliveries);
|
||||
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 monthStart = startOfMonth(currentMonth);
|
||||
const monthEnd = endOfMonth(currentMonth);
|
||||
const days = eachDayOfInterval({ start: monthStart, end: monthEnd });
|
||||
|
||||
const getCountForDate = (date: Date) => {
|
||||
const dateStr = format(date, 'dd-MM-yyyy');
|
||||
return deliveries.filter(d => d.date === dateStr).length;
|
||||
return deliveryCounts[dateStr] || 0;
|
||||
};
|
||||
|
||||
const handlePrintDay = (date: Date) => {
|
||||
const dateStr = format(date, 'dd-MM-yyyy');
|
||||
const dayDeliveries = deliveries.filter(d => d.date === dateStr);
|
||||
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;
|
||||
@@ -57,7 +73,7 @@ export const Dashboard = ({ onDateSelect, onAddDelivery }: DashboardProps) => {
|
||||
<th>Телефон</th>
|
||||
<th>Комментарий</th>
|
||||
</tr>
|
||||
${dayDeliveries.map(d => `
|
||||
${dayDeliveries.map((d: Delivery) => `
|
||||
<tr>
|
||||
<td><span class="status-${d.status}">${d.status === 'new' ? 'Новое' : 'Доставлено'}</span></td>
|
||||
<td>${d.pickupLocation === 'warehouse' ? 'Склад' : d.pickupLocation === 'symbat' ? 'Сымбат' : d.pickupLocation === 'nursaya' ? 'Нурсая' : 'Галактика'}</td>
|
||||
@@ -74,7 +90,7 @@ export const Dashboard = ({ onDateSelect, onAddDelivery }: DashboardProps) => {
|
||||
|
||||
printWindow.document.write(html);
|
||||
printWindow.document.close();
|
||||
printWindow.print();
|
||||
printWindow?.print();
|
||||
};
|
||||
|
||||
const navigateMonth = (direction: 'prev' | 'next') => {
|
||||
|
||||
Reference in New Issue
Block a user