fix upcoming deliveries display count on calendar
This commit is contained in:
@@ -70,7 +70,11 @@ WHERE id = $21;
|
||||
|
||||
-- name: GetDeliveryCount :many
|
||||
SELECT COUNT(*) as count, date FROM deliveries
|
||||
WHERE date >= CURRENT_DATE AND date < CURRENT_DATE + INTERVAL '7 days'
|
||||
WHERE date >= CURRENT_DATE
|
||||
AND date < GREATEST(
|
||||
CURRENT_DATE + INTERVAL '7 days',
|
||||
DATE_TRUNC('month', CURRENT_DATE) + INTERVAL '1 month'
|
||||
)
|
||||
GROUP BY date;
|
||||
|
||||
-- name: UpdateDeliveryStatus :exec
|
||||
|
||||
@@ -218,7 +218,11 @@ func (q *Queries) GetDeliveryByID(ctx context.Context, id pgtype.UUID) (Delivery
|
||||
|
||||
const getDeliveryCount = `-- name: GetDeliveryCount :many
|
||||
SELECT COUNT(*) as count, date FROM deliveries
|
||||
WHERE date >= CURRENT_DATE AND date < CURRENT_DATE + INTERVAL '7 days'
|
||||
WHERE date >= CURRENT_DATE
|
||||
AND date < GREATEST(
|
||||
CURRENT_DATE + INTERVAL '7 days',
|
||||
DATE_TRUNC('month', CURRENT_DATE) + INTERVAL '1 month'
|
||||
)
|
||||
GROUP BY date
|
||||
`
|
||||
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "delivery-tracker",
|
||||
"version": "0.0.6",
|
||||
"version": "0.0.7",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "delivery-tracker",
|
||||
"version": "0.0.6",
|
||||
"version": "0.0.7",
|
||||
"dependencies": {
|
||||
"@tailwindcss/vite": "^4.2.2",
|
||||
"date-fns": "^4.1.0",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "delivery-tracker",
|
||||
"private": true,
|
||||
"version": "0.0.6",
|
||||
"version": "0.0.7",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -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