import { BadgeCheckIcon } from "@heroicons/react/solid"; import { useRouter } from "next/router"; import { useState } from "react"; import { Controller, useForm } from "react-hook-form"; import TimezoneSelect from "react-timezone-select"; import { DEFAULT_SCHEDULE, availabilityAsString } from "@calcom/lib/availability"; import showToast from "@calcom/lib/notification"; import Button from "@calcom/ui/Button"; import Switch from "@calcom/ui/Switch"; import { Form } from "@calcom/ui/form/fields"; import { QueryCell } from "@lib/QueryCell"; import { HttpError } from "@lib/core/http/error"; import { useLocale } from "@lib/hooks/useLocale"; import { inferQueryOutput, trpc } from "@lib/trpc"; import Shell from "@components/Shell"; import Schedule from "@components/availability/Schedule"; import EditableHeading from "@components/ui/EditableHeading"; export function AvailabilityForm(props: inferQueryOutput<"viewer.availability.schedule">) { const { t } = useLocale(); const router = useRouter(); const form = useForm({ defaultValues: { schedule: props.availability || DEFAULT_SCHEDULE, isDefault: !!props.isDefault, timeZone: props.timeZone, }, }); const updateMutation = trpc.useMutation("viewer.availability.schedule.update", { onSuccess: async () => { await router.push("/availability"); window.location.reload(); showToast(t("availability_updated_successfully"), "success"); }, onError: (err) => { if (err instanceof HttpError) { const message = `${err.statusCode}: ${err.message}`; showToast(message, "error"); } }, }); return (
); } export default function Availability() { const router = useRouter(); const { i18n } = useLocale(); const query = trpc.useQuery([ "viewer.availability.schedule", { scheduleId: parseInt(router.query.schedule as string), }, ]); const [name, setName] = useState