From a831aeb21223cf3ca4bdb4d31388b447aeeeb47d Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Wed, 25 Jun 2025 18:20:47 +0300 Subject: [PATCH] highlight days in horizontal calendar --- .../orders/orders-list/date-select.tsx | 43 +++++++++++++++- .../src/components/ui/horizontal-calendar.tsx | 49 ++++++++++++------- 2 files changed, 73 insertions(+), 19 deletions(-) diff --git a/apps/web/components/orders/orders-list/date-select.tsx b/apps/web/components/orders/orders-list/date-select.tsx index 04c93df..f0bfa0b 100644 --- a/apps/web/components/orders/orders-list/date-select.tsx +++ b/apps/web/components/orders/orders-list/date-select.tsx @@ -1,10 +1,51 @@ +/* eslint-disable canonical/id-match */ 'use client'; + +import { useCustomerQuery } from '@/hooks/api/customers'; +import { useOrdersQuery } from '@/hooks/api/orders'; import { useDateTimeStore } from '@/stores/datetime'; +import { Enum_Customer_Role } from '@repo/graphql/types'; import { HorizontalCalendar } from '@repo/ui/components/ui/horizontal-calendar'; +import dayjs from 'dayjs'; +import { useState } from 'react'; export function DateSelect() { + const { data: { customer } = {} } = useCustomerQuery(); + + const isMaster = customer?.role === Enum_Customer_Role.Master; + + const [currentMonthDate, setCurrentMonthDate] = useState(new Date()); + + const { data: { orders } = {} } = useOrdersQuery({ + filters: { + client: { + documentId: { + eq: isMaster ? undefined : customer?.documentId, + }, + }, + slot: { + date: { + gte: dayjs(currentMonthDate).startOf('month').format('YYYY-MM-DD'), + lte: dayjs(currentMonthDate).endOf('month').format('YYYY-MM-DD'), + }, + master: { + documentId: { + eq: isMaster ? customer?.documentId : undefined, + }, + }, + }, + }, + }); + const setSelectedDate = useDateTimeStore((store) => store.setDate); const selectedDate = useDateTimeStore((store) => store.date); - return ; + return ( + new Date(order?.slot?.date))} + onDateChange={setSelectedDate} + onMonthChange={(date) => setCurrentMonthDate(date)} + selectedDate={selectedDate} + /> + ); } diff --git a/packages/ui/src/components/ui/horizontal-calendar.tsx b/packages/ui/src/components/ui/horizontal-calendar.tsx index de39d87..d9a279b 100644 --- a/packages/ui/src/components/ui/horizontal-calendar.tsx +++ b/packages/ui/src/components/ui/horizontal-calendar.tsx @@ -16,13 +16,17 @@ import { useMemo, useRef, useState } from 'react'; type HorizontalCalendarProps = { readonly className?: string; + readonly daysWithOrders?: Date[]; readonly onDateChange: (date: Date) => void; + readonly onMonthChange?: (date: Date) => void; readonly selectedDate: Date; }; export function HorizontalCalendar({ className, + daysWithOrders, onDateChange, + onMonthChange, selectedDate, }: HorizontalCalendarProps) { const scrollRef = useRef(null); @@ -49,12 +53,14 @@ export function HorizontalCalendar({ const newDate = addMonths(currentMonthDate, -1); setCurrentMonthDate(newDate); setTimeout(scrollToStart, 0); + onMonthChange?.(newDate); }; const scrollNext = () => { const newDate = addMonths(currentMonthDate, 1); setCurrentMonthDate(newDate); setTimeout(scrollToStart, 0); + onMonthChange?.(newDate); }; return ( @@ -80,25 +86,32 @@ export function HorizontalCalendar({
- {dates.map((date) => ( -
- -
- ))} + +
+ ); + })}