import { useForm } from "react-hook-form"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import type { ApiErrorResponse } from "@calcom/platform-types"; import { Button } from "@calcom/ui/components/button"; import { Form } from "@calcom/ui/components/form"; import { InputField } from "@calcom/ui/components/form"; import { useAtomCreateSchedule } from "../hooks/schedules/useAtomCreateSchedule"; import { AtomsWrapper } from "../src/components/atoms-wrapper"; import { useToast } from "../src/components/ui/use-toast"; import { cn } from "../src/lib/utils"; export type ActionButtonsClassNames = { container?: string; continue?: string; close?: string; }; export const CreateScheduleForm = ({ onSuccess, onError, onCancel, customClassNames, disableToasts = false, }: { onSuccess?: (scheduleId: number) => void; onError?: (err: ApiErrorResponse) => void; onCancel?: () => void; customClassNames?: { formWrapper?: string; inputField?: string; actionsButtons?: ActionButtonsClassNames; }; disableToasts?: boolean; }) => { const { toast } = useToast(); const { t } = useLocale(); const form = useForm<{ name: string; }>(); const { register } = form; const { mutateAsync: createSchedule, isPending: isCreateSchedulePending } = useAtomCreateSchedule({ onSuccess: (res) => { if (!disableToasts) { toast({ description: t("schedule_created_successfully", { scheduleName: res.data.schedule.name }), }); } form.reset(); onSuccess?.(res.data.schedule.id); }, onError: (err) => { onError?.(err); if (!disableToasts) { toast({ description: `Could not create schedule: ${err.error.message}`, }); } }, }); return (
{ await createSchedule(values); }}> (!v || v.trim() === "" ? null : v), })} />
{onCancel && ( )}
); };