zapishis-client/apps/web/context/schedule-slots.tsx
vchikalkin a3ed709c36 add hook useSlots
fix update slots list after add slot
fix initial fetch slots
2025-02-08 14:56:35 +03:00

19 lines
645 B
TypeScript

'use client';
import { combineDateTime } from '@/utils/date';
import { createContext, useMemo, useState } from 'react';
type ContextType = {
selectedDate: Date;
setSelectedDate: (date: Date) => void;
};
export const ScheduleSlotsContext = createContext<ContextType>({} as ContextType);
export function ScheduleSlotsProvider({ children }: { readonly children: React.ReactNode }) {
const [selectedDate, setSelectedDate] = useState(combineDateTime(new Date(), '00:00'));
const value = useMemo(() => ({ selectedDate, setSelectedDate }), [selectedDate]);
return <ScheduleSlotsContext value={value}>{children}</ScheduleSlotsContext>;
}