import { PlusIcon } from "@heroicons/react/solid"; import { useRouter } from "next/router"; import { useForm } from "react-hook-form"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import showToast from "@calcom/lib/notification"; import { Button } from "@calcom/ui"; import { Dialog, DialogClose, DialogContent, DialogTrigger } from "@calcom/ui/Dialog"; import { Form } from "@calcom/ui/form/fields"; import { HttpError } from "@lib/core/http/error"; import { trpc } from "@lib/trpc"; export function NewScheduleButton({ name = "new-schedule" }: { name?: string }) { const router = useRouter(); const { t } = useLocale(); const form = useForm<{ name: string; }>(); const { register } = form; const createMutation = trpc.useMutation("viewer.availability.schedule.create", { onSuccess: async ({ schedule }) => { await router.push("/availability/" + schedule.id); showToast(t("schedule_created_successfully", { scheduleName: schedule.name }), "success"); }, onError: (err) => { if (err instanceof HttpError) { const message = `${err.statusCode}: ${err.message}`; showToast(message, "error"); } if (err.data?.code === "UNAUTHORIZED") { const message = `${err.data.code}: You are not able to create this event`; showToast(message, "error"); } }, }); return (

{t("new_event_type_to_book_description")}

{ createMutation.mutate(values); }}>
); }