/** * @deprecated modifications to this file should be v2 only * Use `/apps/web/pages/v2/availability/[schedule].tsx` instead */ // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-nocheck import { GetStaticPaths, GetStaticProps } from "next"; import { useRouter } from "next/router"; import { useState } from "react"; import { Controller, useForm } from "react-hook-form"; import { z } from "zod"; import { DEFAULT_SCHEDULE, availabilityAsString } from "@calcom/lib/availability"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import showToast from "@calcom/lib/notification"; import { stringOrNumber } from "@calcom/prisma/zod-utils"; import { inferQueryOutput, trpc } from "@calcom/trpc/react"; import Button from "@calcom/ui/Button"; import { BadgeCheckIcon } from "@calcom/ui/Icon"; import Shell from "@calcom/ui/Shell"; import Switch from "@calcom/ui/Switch"; import TimezoneSelect from "@calcom/ui/form/TimezoneSelect"; import { Form } from "@calcom/ui/form/fields"; import { QueryCell } from "@lib/QueryCell"; import { HttpError } from "@lib/core/http/error"; import Schedule from "@components/availability/Schedule"; import EditableHeading from "@components/ui/EditableHeading"; /** * @deprecated modifications to this file should be v2 only * Use `/apps/web/pages/v2/availability/[schedule].tsx` instead */ 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 (
); } const querySchema = z.object({ schedule: stringOrNumber, }); export default function Availability() { const router = useRouter(); const { i18n } = useLocale(); const { schedule: scheduleId } = router.isReady ? querySchema.parse(router.query) : { schedule: -1 }; const query = trpc.useQuery(["viewer.availability.schedule", { scheduleId }], { enabled: router.isReady }); const [name, setName] = useState