fix upcoming deliveries display count on calendar
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
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 { addDays, format, startOfDay, startOfMonth, endOfMonth, eachDayOfInterval, isToday, getDay } from 'date-fns';
|
||||
import { ru } from 'date-fns/locale';
|
||||
import { useDeliveryStore } from '../stores/deliveryStore';
|
||||
import type { Delivery } from '../types';
|
||||
@@ -29,6 +29,11 @@ const Dashboard = ({ onDateSelect, onAddDelivery }: DashboardProps) => {
|
||||
return eachDayOfInterval({ start: monthStart, end: monthEnd });
|
||||
}, [currentMonth]);
|
||||
|
||||
const upcomingDays = useMemo(() => {
|
||||
const today = startOfDay(new Date());
|
||||
return eachDayOfInterval({ start: today, end: addDays(today, 6) });
|
||||
}, []);
|
||||
|
||||
const getCountForDate = (date: Date) => {
|
||||
const dateStr = format(date, 'dd-MM-yyyy');
|
||||
return deliveryCounts[dateStr] || 0;
|
||||
@@ -186,9 +191,8 @@ const Dashboard = ({ onDateSelect, onAddDelivery }: DashboardProps) => {
|
||||
|
||||
<div className="space-y-3">
|
||||
<h3 className="font-semibold text-[#1b1b1d]">Ближайшие даты с доставками</h3>
|
||||
{days
|
||||
{upcomingDays
|
||||
.filter(day => getCountForDate(day) > 0)
|
||||
.slice(0, 7)
|
||||
.map(day => {
|
||||
const count = getCountForDate(day);
|
||||
return (
|
||||
@@ -232,7 +236,7 @@ const Dashboard = ({ onDateSelect, onAddDelivery }: DashboardProps) => {
|
||||
);
|
||||
})}
|
||||
|
||||
{days.filter(day => getCountForDate(day) > 0).length === 0 && (
|
||||
{upcomingDays.filter(day => getCountForDate(day) > 0).length === 0 && (
|
||||
<Card className="p-8 text-center">
|
||||
<p className="text-[#75777d]">Нет запланированных доставок</p>
|
||||
<Button onClick={onAddDelivery} variant="ghost" className="mt-2">
|
||||
|
||||
Reference in New Issue
Block a user