frontend refactor
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useState, useEffect, useMemo } 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 { pickupLocationLabels } from '../types';
|
||||
import { Button } from '../components/ui/Button';
|
||||
import { Card } from '../components/ui/Card';
|
||||
|
||||
@@ -12,7 +13,7 @@ interface DashboardProps {
|
||||
onAddDelivery: () => void;
|
||||
}
|
||||
|
||||
export const Dashboard = ({ onDateSelect, onAddDelivery }: DashboardProps) => {
|
||||
const Dashboard = ({ onDateSelect, onAddDelivery }: DashboardProps) => {
|
||||
const deliveryCounts = useDeliveryStore(state => state.deliveryCounts);
|
||||
const fetchDeliveryCounts = useDeliveryStore(state => state.fetchDeliveryCounts);
|
||||
const [currentMonth, setCurrentMonth] = useState(new Date());
|
||||
@@ -22,9 +23,11 @@ export const Dashboard = ({ onDateSelect, onAddDelivery }: DashboardProps) => {
|
||||
fetchDeliveryCounts();
|
||||
}, [fetchDeliveryCounts]);
|
||||
|
||||
const monthStart = startOfMonth(currentMonth);
|
||||
const monthEnd = endOfMonth(currentMonth);
|
||||
const days = eachDayOfInterval({ start: monthStart, end: monthEnd });
|
||||
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');
|
||||
@@ -76,7 +79,7 @@ export const Dashboard = ({ onDateSelect, onAddDelivery }: DashboardProps) => {
|
||||
${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>
|
||||
<td>${pickupLocationLabels[d.pickupLocation]}</td>
|
||||
<td>${d.productName}</td>
|
||||
<td>${d.address}</td>
|
||||
<td>${d.phone}</td>
|
||||
@@ -118,7 +121,7 @@ export const Dashboard = ({ onDateSelect, onAddDelivery }: DashboardProps) => {
|
||||
<div className="flex items-center justify-between mb-6">
|
||||
<h2 className="text-lg font-semibold text-[#1b1b1d] flex items-center gap-2">
|
||||
<CalendarDays size={20} className="text-[#1B263B]" />
|
||||
{format(currentMonth, 'MMMM yyyy', { locale: ru })}
|
||||
{format(currentMonth, 'LLLL yyyy', { locale: ru })}
|
||||
</h2>
|
||||
<div className="flex gap-2">
|
||||
<Button variant="ghost" size="sm" onClick={() => navigateMonth('prev')}>
|
||||
@@ -234,3 +237,5 @@ export const Dashboard = ({ onDateSelect, onAddDelivery }: DashboardProps) => {
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Dashboard;
|
||||
|
||||
Reference in New Issue
Block a user