split datetime-select into files

This commit is contained in:
vchikalkin 2025-04-16 16:03:58 +03:00
parent 1e6718508a
commit 7e143b3054
4 changed files with 36 additions and 29 deletions

View File

@ -0,0 +1,23 @@
'use client';
import { OrderContext } from '@/context/order';
import { Calendar } from '@repo/ui/components/ui/calendar';
import dayjs from 'dayjs';
import { use } from 'react';
export function DateSelect() {
const { date: selectedDate, setDate } = use(OrderContext);
return (
<Calendar
className="bg-background"
disabled={(date) => {
return dayjs().isAfter(dayjs(date), 'day');
}}
mode="single"
onSelect={(date) => {
if (date) setDate(date);
}}
selected={selectedDate}
/>
);
}

View File

@ -1,33 +1,12 @@
'use client';
import { OrderContext } from '@/context/order';
import { Button } from '@repo/ui/components/ui/button';
import { Calendar } from '@repo/ui/components/ui/calendar';
import dayjs, { type Dayjs } from 'dayjs';
import { use } from 'react';
type TimeSlotsProps = {
endTime?: string;
interval?: number;
startTime?: string;
};
export function DateSelect() {
const { date: selectedDate, setDate } = use(OrderContext);
return (
<Calendar
className="bg-background"
disabled={(date) => {
return dayjs().isAfter(dayjs(date), 'day');
}}
mode="single"
onSelect={(date) => {
if (date) setDate(date);
}}
selected={selectedDate}
/>
);
}
const generateTimeSlots = (start: string, end: string, interval: number): Dayjs[] => {
const times: Dayjs[] = [];
let currentTime = dayjs(start, 'HH:mm');

View File

@ -0,0 +1,11 @@
import { DateSelect } from './components/date-select';
import { TimeSelect } from './components/time-select';
export function DateTimeSelect() {
return (
<div className="space-y-4">
<DateSelect />
<TimeSelect />
</div>
);
}

View File

@ -2,11 +2,10 @@
import {
BackButton,
ClientsGrid,
DateSelect,
DateTimeSelect,
MastersGrid,
ServiceSelect,
SubmitButton,
TimeSelect,
} from './components';
import { OrderContext, OrderContextProvider } from '@/context/order';
import { withContext } from '@/utils/context';
@ -14,12 +13,7 @@ import { type JSX, use } from 'react';
const STEP_COMPONENTS: Record<string, JSX.Element> = {
'client-select': <ClientsGrid />,
'datetime-select': (
<>
<DateSelect />
<TimeSelect />
</>
),
'datetime-select': <DateTimeSelect />,
'master-select': <MastersGrid />,
'service-select': <ServiceSelect />,
};