41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
/* eslint-disable canonical/id-match */
|
||
'use client';
|
||
import { EditableTimeRangeForm } from './components/time-range';
|
||
import { ScheduleTimeContext, ScheduleTimeContextProvider } from './context';
|
||
import { useSlotCreate } from '@/hooks/api/slots';
|
||
import { withContext } from '@/utils/context';
|
||
import { Enum_Slot_State } from '@repo/graphql/types';
|
||
import { Button } from '@repo/ui/components/ui/button';
|
||
import { PlusSquare } from 'lucide-react';
|
||
import { type FormEvent, use } from 'react';
|
||
|
||
export const DaySlotAddForm = withContext(ScheduleTimeContextProvider)(function () {
|
||
const { endTime, resetTime, startTime } = use(ScheduleTimeContext);
|
||
|
||
const { isPending, mutate: addSlot } = useSlotCreate();
|
||
|
||
const handleSubmit = (event: FormEvent) => {
|
||
event.preventDefault();
|
||
if (startTime && endTime) {
|
||
addSlot({
|
||
input: {
|
||
state: Enum_Slot_State.Open,
|
||
time_end: endTime,
|
||
time_start: startTime,
|
||
},
|
||
});
|
||
|
||
resetTime();
|
||
}
|
||
};
|
||
|
||
return (
|
||
<EditableTimeRangeForm disabled={isPending} onSubmit={handleSubmit}>
|
||
<Button className="rounded-full" disabled={isPending} type="submit">
|
||
<PlusSquare className="mr-1 size-4" />
|
||
Добавить
|
||
</Button>
|
||
</EditableTimeRangeForm>
|
||
);
|
||
});
|