fix create slot
This commit is contained in:
parent
1b1963e5d9
commit
8242d186fe
@ -1,3 +1,4 @@
|
||||
import { getSlot } from '@/actions/api/slots';
|
||||
import { Container } from '@/components/layout';
|
||||
import { PageHeader } from '@/components/navigation';
|
||||
import { SlotButtons, SlotDateTime, SlotOrdersList } from '@/components/schedule';
|
||||
@ -8,9 +9,15 @@ type Props = { params: Promise<SlotComponentProps> };
|
||||
|
||||
export default async function SlotPage(props: Readonly<Props>) {
|
||||
const parameters = await props.params;
|
||||
const documentId = parameters.documentId;
|
||||
|
||||
const queryClient = new QueryClient();
|
||||
|
||||
await queryClient.prefetchQuery({
|
||||
queryFn: () => getSlot({ documentId }),
|
||||
queryKey: ['slot', documentId],
|
||||
});
|
||||
|
||||
return (
|
||||
<HydrationBoundary state={dehydrate(queryClient)}>
|
||||
<PageHeader title="Слот" />
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
|
||||
import { EditableTimeRangeForm } from '@/components/shared/time-range';
|
||||
import { useSlotCreate } from '@/hooks/api/slots';
|
||||
import { useDateTimeStore } from '@/stores/datetime';
|
||||
import { ScheduleStoreProvider, useScheduleStore } from '@/stores/schedule';
|
||||
import { withContext } from '@/utils/context';
|
||||
import { Enum_Slot_State } from '@repo/graphql/types';
|
||||
@ -11,6 +12,7 @@ import { PlusSquare } from 'lucide-react';
|
||||
import { type FormEvent } from 'react';
|
||||
|
||||
export const DaySlotAddForm = withContext(ScheduleStoreProvider)(function () {
|
||||
const selectedDate = useDateTimeStore((store) => store.date);
|
||||
const endTime = useScheduleStore((state) => state.endTime);
|
||||
const resetTime = useScheduleStore((state) => state.resetTime);
|
||||
const startTime = useScheduleStore((state) => state.startTime);
|
||||
@ -22,6 +24,7 @@ export const DaySlotAddForm = withContext(ScheduleStoreProvider)(function () {
|
||||
if (startTime && endTime) {
|
||||
addSlot({
|
||||
input: {
|
||||
date: selectedDate,
|
||||
state: Enum_Slot_State.Open,
|
||||
time_end: endTime,
|
||||
time_start: startTime,
|
||||
|
||||
@ -71,10 +71,18 @@ export const useSlotCreate = () => {
|
||||
return useMutation({
|
||||
mutationFn: createSlot,
|
||||
mutationKey: ['slot', 'create'],
|
||||
onSuccess: () => {
|
||||
onSuccess: (data) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ['slots', masterId],
|
||||
});
|
||||
|
||||
const documentId = data?.createSlot?.documentId;
|
||||
|
||||
if (documentId)
|
||||
queryClient.prefetchQuery({
|
||||
queryFn: () => getSlot({ documentId }),
|
||||
queryKey: ['slot', documentId],
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user