import { useAutoAnimate } from "@formkit/auto-animate/react"; import * as RadioGroup from "@radix-ui/react-radio-group"; import { EventTypeSetupProps, FormValues } from "pages/event-types/[type]"; import React, { useEffect, useState } from "react"; import { Controller, useFormContext, UseFormRegisterReturn, useWatch } from "react-hook-form"; import { classNames } from "@calcom/lib"; import convertToNewDurationType, { DurationType } from "@calcom/lib/convertToNewDurationType"; import findDurationType from "@calcom/lib/findDurationType"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { PeriodType } from "@calcom/prisma/client"; import type { BookingLimit } from "@calcom/types/Calendar"; import { Button, DateRangePicker, Input, InputField, Label, Select, SettingsToggle } from "@calcom/ui"; import { FiPlus, FiTrash } from "@calcom/ui/components/icon"; const MinimumBookingNoticeInput = React.forwardRef< HTMLInputElement, Omit, "ref"> >(function MinimumBookingNoticeInput({ ...passThroughProps }, ref) { const { t } = useLocale(); const { setValue, getValues } = useFormContext(); const durationTypeOptions: { value: DurationType; label: string; }[] = [ { label: t("minutes"), value: "minutes", }, { label: t("hours"), value: "hours", }, { label: t("days"), value: "days", }, ]; const [minimumBookingNoticeDisplayValues, setMinimumBookingNoticeDisplayValues] = useState<{ type: DurationType; value: number; }>({ type: findDurationType(getValues(passThroughProps.name)), value: convertToNewDurationType( "minutes", findDurationType(getValues(passThroughProps.name)), getValues(passThroughProps.name) ), }); // keep hidden field in sync with minimumBookingNoticeDisplayValues useEffect(() => { setValue( passThroughProps.name, convertToNewDurationType( minimumBookingNoticeDisplayValues.type, "minutes", minimumBookingNoticeDisplayValues.value ) ); }, [minimumBookingNoticeDisplayValues, setValue, passThroughProps.name]); return (
setMinimumBookingNoticeDisplayValues({ ...minimumBookingNoticeDisplayValues, value: parseInt(e.target.value || "0", 10), }) } label={t("minimum_booking_notice")} type="number" placeholder="0" className="mb-0 h-[38px] rounded-[4px] ltr:mr-2 rtl:ml-2" />
{ if (val) onChange(val.value); }} defaultValue={ beforeBufferOptions.find((option) => option.value === value) || beforeBufferOptions[0] } options={beforeBufferOptions} /> ); }} />
{ const afterBufferOptions = [ { label: t("event_buffer_default"), value: 0, }, ...[5, 10, 15, 20, 30, 45, 60, 90, 120].map((minutes) => ({ label: minutes + " " + t("minutes"), value: minutes, })), ]; return ( { formMethods.setValue("slotInterval", val && (val.value || 0) > 0 ? val.value : null); }} defaultValue={ slotIntervalOptions.find((option) => option.value === eventType.slotInterval) || slotIntervalOptions[0] } options={slotIntervalOptions} /> ); }} />

( 0} onCheckedChange={(active) => { if (active) { formMethods.setValue("bookingLimits", { PER_DAY: 1, }); } else { formMethods.setValue("bookingLimits", {}); } }}> )} />
( formMethods.setValue("periodType", bool ? "ROLLING" : "UNLIMITED")}> formMethods.setValue("periodType", val as PeriodType)}> {PERIOD_TYPES.map((period) => { if (period.type === "UNLIMITED") return null; return (
{period.prefix ? {period.prefix}  : null} {period.type === "ROLLING" && (
)} {period.type === "RANGE" && (
( { formMethods.setValue("periodDates", { startDate, endDate, }); }} /> )} />
)} {period.suffix ? (  {period.suffix} ) : null}
); })}
)} /> ); }; const validationOrderKeys = ["PER_DAY", "PER_WEEK", "PER_MONTH", "PER_YEAR"]; type BookingLimitsKey = keyof BookingLimit; const BookingLimits = () => { const { watch, setValue, control } = useFormContext(); const watchBookingLimits = watch("bookingLimits"); const { t } = useLocale(); const [animateRef] = useAutoAnimate(); const BOOKING_LIMIT_OPTIONS: { value: keyof BookingLimit; label: string; }[] = [ { value: "PER_DAY", label: "Per Day", }, { value: "PER_WEEK", label: "Per Week", }, { value: "PER_MONTH", label: "Per Month", }, { value: "PER_YEAR", label: "Per Year", }, ]; return ( { const currentBookingLimits = value; return (
    {currentBookingLimits && watchBookingLimits && Object.entries(currentBookingLimits) .sort(([limitkeyA], [limitKeyB]) => { return ( validationOrderKeys.indexOf(limitkeyA as BookingLimitsKey) - validationOrderKeys.indexOf(limitKeyB as BookingLimitsKey) ); }) .map(([key, bookingAmount]) => { const bookingLimitKey = key as BookingLimitsKey; return (
    { const val = e.target.value; setValue(`bookingLimits.${bookingLimitKey}`, parseInt(val)); }} />