import { BadgeCheckIcon } from "@heroicons/react/solid"; import { useRouter } from "next/router"; import { useState } from "react"; import { Controller, useForm } from "react-hook-form"; import { DEFAULT_SCHEDULE, availabilityAsString } from "@calcom/lib/availability"; import { useLocale } from "@calcom/lib/hooks/useLocale"; 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 { inferQueryOutput, trpc } from "@lib/trpc"; import Shell from "@components/Shell"; import Schedule from "@components/availability/Schedule"; import EditableHeading from "@components/ui/EditableHeading"; import TimezoneSelect from "@components/ui/form/TimezoneSelect"; export function AvailabilityForm(props: inferQueryOutput<"viewer.availability.schedule">) { const { t } = useLocale(); const router = useRouter(); const utils = trpc.useContext(); 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 ({ schedule }) => { await utils.invalidateQueries(["viewer.availability.schedule"]); await router.push("/availability"); showToast( t("availability_updated_successfully", { scheduleName: schedule.name, }), "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