rename files & components
This commit is contained in:
parent
1b8aacbd72
commit
d4145a3c86
@ -1,19 +1,19 @@
|
||||
import { HorizontalDivider } from '@/components/common/divider';
|
||||
import { Container } from '@/components/layout';
|
||||
import { PageHeader } from '@/components/navigation';
|
||||
import { AddSlotForm, SlotsCalendar, SlotsList } from '@/components/schedule';
|
||||
import { ScheduleSlotsProvider } from '@/context/schedule-slots';
|
||||
import { DaySlotAddForm, DaySlotsList, ScheduleCalendar } from '@/components/schedule';
|
||||
import { ScheduleContextProvider } from '@/context/schedule';
|
||||
|
||||
export default function SchedulePage() {
|
||||
return (
|
||||
<ScheduleSlotsProvider>
|
||||
<ScheduleContextProvider>
|
||||
<PageHeader title="График работы" />
|
||||
<Container className="px-0">
|
||||
<SlotsCalendar />
|
||||
<SlotsList />
|
||||
<ScheduleCalendar />
|
||||
<DaySlotsList />
|
||||
<HorizontalDivider className="px-4" />
|
||||
<AddSlotForm />
|
||||
<DaySlotAddForm />
|
||||
</Container>
|
||||
</ScheduleSlotsProvider>
|
||||
</ScheduleContextProvider>
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import { Container } from '@/components/layout';
|
||||
import { PageHeader } from '@/components/navigation';
|
||||
import { SlotButtons, SlotDateTime } from '@/components/schedule';
|
||||
import { OrdersList } from '@/components/schedule/orders-list';
|
||||
import { SlotButtons, SlotDateTime, SlotOrdersList } from '@/components/schedule';
|
||||
import { dehydrate, HydrationBoundary, QueryClient } from '@tanstack/react-query';
|
||||
|
||||
type Props = { params: Promise<{ documentId: string }> };
|
||||
@ -18,7 +17,7 @@ export default async function ProfilePage(props: Readonly<Props>) {
|
||||
<SlotDateTime {...parameters} />
|
||||
<SlotButtons {...parameters} />
|
||||
</Container>
|
||||
<OrdersList {...parameters} className="mt-4" />
|
||||
<SlotOrdersList {...parameters} className="mt-4" />
|
||||
</HydrationBoundary>
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
'use client';
|
||||
import { ScheduleSlotsContext } from '@/context/schedule-slots';
|
||||
import { ScheduleContext } from '@/context/schedule';
|
||||
import { Calendar } from '@repo/ui/components/ui/calendar';
|
||||
import dayjs from 'dayjs';
|
||||
import { use } from 'react';
|
||||
|
||||
export function SlotsCalendar() {
|
||||
const { selectedDate, setSelectedDate } = use(ScheduleSlotsContext);
|
||||
export function ScheduleCalendar() {
|
||||
const { selectedDate, setSelectedDate } = use(ScheduleContext);
|
||||
|
||||
return (
|
||||
<Calendar
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/* eslint-disable canonical/id-match */
|
||||
'use client';
|
||||
import { ContextProvider } from '../context';
|
||||
import { ScheduleTimeContextProvider } from '../context';
|
||||
import { type SlotComponentProps } from '../types';
|
||||
import { ReadonlyTimeRange } from './time-range';
|
||||
import { useSlotQuery } from '@/hooks/slots';
|
||||
@ -10,7 +10,7 @@ import { Badge } from '@repo/ui/components/ui/badge';
|
||||
import { cn } from '@repo/ui/lib/utils';
|
||||
import Link from 'next/link';
|
||||
|
||||
const MAP_BADGE_TEXT: Order<Enum_Slot_State, string> = {
|
||||
const MAP_BADGE_TEXT: Record<Enum_Slot_State, string> = {
|
||||
closed: 'Закрыто',
|
||||
open: 'Открыто',
|
||||
reserved: 'Зарезервировано',
|
||||
@ -22,7 +22,7 @@ function getBadgeText(state: Enum_Slot_State) {
|
||||
return MAP_BADGE_TEXT[state];
|
||||
}
|
||||
|
||||
export const SlotCard = withContext(ContextProvider)(function (
|
||||
export const SlotCard = withContext(ScheduleTimeContextProvider)(function (
|
||||
props: Readonly<SlotComponentProps>,
|
||||
) {
|
||||
const { documentId } = props;
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
'use client';
|
||||
import { Context } from '../context';
|
||||
import { ScheduleTimeContext } from '../context';
|
||||
import { useSlotAdd } from '@/hooks/slots';
|
||||
import { formatTime } from '@/utils/date';
|
||||
import { Input } from '@repo/ui/components/ui/input';
|
||||
@ -14,7 +14,7 @@ type TimeRangeProps = {
|
||||
};
|
||||
|
||||
export function AddTimeRange() {
|
||||
const { endTime, setEndTime, setStartTime, startTime } = use(Context);
|
||||
const { endTime, setEndTime, setStartTime, startTime } = use(ScheduleTimeContext);
|
||||
const { isPending } = useSlotAdd();
|
||||
|
||||
return (
|
||||
|
||||
@ -9,9 +9,9 @@ export type ContextType = {
|
||||
setStartTime: (value: string) => void;
|
||||
startTime: string;
|
||||
};
|
||||
export const Context = createContext<ContextType>({} as ContextType);
|
||||
export const ScheduleTimeContext = createContext<ContextType>({} as ContextType);
|
||||
|
||||
export function ContextProvider({ children }: Readonly<PropsWithChildren>) {
|
||||
export function ScheduleTimeContextProvider({ children }: Readonly<PropsWithChildren>) {
|
||||
const [editMode, setEditMode] = useState(false);
|
||||
const [startTime, setStartTime] = useState('');
|
||||
const [endTime, setEndTime] = useState('');
|
||||
@ -27,5 +27,5 @@ export function ContextProvider({ children }: Readonly<PropsWithChildren>) {
|
||||
};
|
||||
}, [editMode, endTime, setEditMode, startTime]);
|
||||
|
||||
return <Context value={value}>{children}</Context>;
|
||||
return <ScheduleTimeContext value={value}>{children}</ScheduleTimeContext>;
|
||||
}
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
/* eslint-disable canonical/id-match */
|
||||
'use client';
|
||||
import { AddTimeRange } from './components/time-range';
|
||||
import { Context, ContextProvider } from './context';
|
||||
import { ScheduleSlotsContext } from '@/context/schedule-slots';
|
||||
import { ScheduleTimeContext, ScheduleTimeContextProvider } from './context';
|
||||
import { ScheduleContext } from '@/context/schedule';
|
||||
import { useSlotAdd } from '@/hooks/slots';
|
||||
import { withContext } from '@/utils/context';
|
||||
import { Enum_Slot_State } from '@repo/graphql/types';
|
||||
@ -10,10 +10,10 @@ import { Button } from '@repo/ui/components/ui/button';
|
||||
import { PlusSquare } from 'lucide-react';
|
||||
import { type FormEvent, use } from 'react';
|
||||
|
||||
export const AddSlotForm = withContext(ContextProvider)(function () {
|
||||
const { endTime, setEndTime, setStartTime, startTime } = use(Context);
|
||||
export const DaySlotAddForm = withContext(ScheduleTimeContextProvider)(function () {
|
||||
const { endTime, setEndTime, setStartTime, startTime } = use(ScheduleTimeContext);
|
||||
|
||||
const { selectedDate } = use(ScheduleSlotsContext);
|
||||
const { selectedDate } = use(ScheduleContext);
|
||||
|
||||
const { mutate: addSlot } = useSlotAdd();
|
||||
|
||||
@ -3,7 +3,7 @@ import { SlotCard } from './components/slot-card';
|
||||
import { LoadingSpinner } from '@/components/common/spinner';
|
||||
import { useSlots } from '@/hooks/slots';
|
||||
|
||||
export function SlotsList() {
|
||||
export function DaySlotsList() {
|
||||
const { data, isLoading } = useSlots();
|
||||
const slots = data?.data.slots;
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
export * from './add-slot-form';
|
||||
export * from './calendar';
|
||||
export * from './day-slot-add-form';
|
||||
export * from './day-slots-list';
|
||||
export * from './slot-buttons';
|
||||
export * from './slot-datetime';
|
||||
export * from './slots-list';
|
||||
export * from './slot-orders-list';
|
||||
|
||||
@ -4,7 +4,7 @@ import { type SlotComponentProps } from './types';
|
||||
import { useSlotQuery } from '@/hooks/slots';
|
||||
import { cn } from '@repo/ui/lib/utils';
|
||||
|
||||
export function OrdersList({
|
||||
export function SlotOrdersList({
|
||||
className,
|
||||
documentId,
|
||||
}: Readonly<SlotComponentProps> & { readonly className?: string }) {
|
||||
@ -6,12 +6,12 @@ type ContextType = {
|
||||
setSelectedDate: (date: Date) => void;
|
||||
};
|
||||
|
||||
export const ScheduleSlotsContext = createContext<ContextType>({} as ContextType);
|
||||
export const ScheduleContext = createContext<ContextType>({} as ContextType);
|
||||
|
||||
export function ScheduleSlotsProvider({ children }: { readonly children: React.ReactNode }) {
|
||||
export function ScheduleContextProvider({ children }: { readonly children: React.ReactNode }) {
|
||||
const [selectedDate, setSelectedDate] = useState(new Date());
|
||||
|
||||
const value = useMemo(() => ({ selectedDate, setSelectedDate }), [selectedDate]);
|
||||
|
||||
return <ScheduleSlotsContext value={value}>{children}</ScheduleSlotsContext>;
|
||||
return <ScheduleContext value={value}>{children}</ScheduleContext>;
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
import { addSlot, deleteSlot, getSlot, getSlots, updateSlot } from '@/actions/slots';
|
||||
import { ScheduleSlotsContext } from '@/context/schedule-slots';
|
||||
import { ScheduleContext } from '@/context/schedule';
|
||||
import { formatDate } from '@/utils/date';
|
||||
// eslint-disable-next-line sonarjs/no-internal-api-use
|
||||
import type * as ApolloTypes from '@repo/graphql/node_modules/@apollo/client/core';
|
||||
@ -11,7 +11,7 @@ import { use } from 'react';
|
||||
type FixTypescriptCringe = ApolloTypes.FetchResult;
|
||||
|
||||
export const useSlots = () => {
|
||||
const { selectedDate } = use(ScheduleSlotsContext);
|
||||
const { selectedDate } = use(ScheduleContext);
|
||||
|
||||
return useQuery({
|
||||
queryFn: () =>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user