import React, { Fragment, useCallback, useEffect, useMemo, useRef, useState } from "react"; import type { ArrayPath, Control, ControllerRenderProps, FieldArrayWithId, FieldPath, FieldPathValue, FieldValues, UseFieldArrayRemove, } from "react-hook-form"; import { Controller, useFieldArray, useFormContext } from "react-hook-form"; import { createFilter, type GroupBase, type Props } from "react-select"; import type { scheduleClassNames } from "@calcom/atoms/availability/types"; import type { ConfigType } from "@calcom/dayjs"; import dayjs from "@calcom/dayjs"; import { defaultDayRange as DEFAULT_DAY_RANGE } from "@calcom/lib/availability"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { weekdayNames } from "@calcom/lib/weekday"; import useMeQuery from "@calcom/trpc/react/hooks/useMeQuery"; import type { TimeRange } from "@calcom/types/schedule"; import cn from "@calcom/ui/classNames"; import { Button } from "@calcom/ui/components/button"; import { Dropdown, DropdownMenuContent, DropdownMenuTrigger } from "@calcom/ui/components/dropdown"; import { Select } from "@calcom/ui/components/form"; import { CheckboxField } from "@calcom/ui/components/form"; import { Switch } from "@calcom/ui/components/form"; import { SkeletonText } from "@calcom/ui/components/skeleton"; export type { TimeRange }; export type ScheduleLabelsType = { addTime: string; copyTime: string; deleteTime: string; }; export type SelectInnerClassNames = { control?: string; singleValue?: string; valueContainer?: string; input?: string; menu?: string; }; export type FieldPathByValue = { [Key in FieldPath]: FieldPathValue extends TValue ? Key : never; }[FieldPath]; export const ScheduleDay = ({ name, weekday, control, CopyButton, disabled, labels, userTimeFormat, classNames, }: { name: ArrayPath; weekday: string; control: Control; CopyButton: JSX.Element; disabled?: boolean; labels?: ScheduleLabelsType; userTimeFormat: number | null; classNames?: scheduleClassNames; }) => { const { watch, setValue } = useFormContext(); const watchDayRange = watch(name); return (
{/* Label & switch container */}
<> {!watchDayRange && } {watchDayRange.length > 0 && (
{!disabled &&
{CopyButton}
}
)}
); }; const CopyButton = ({ getValuesFromDayRange, weekStart, labels, }: { getValuesFromDayRange: string; weekStart: number; labels?: ScheduleLabelsType; }) => { const { t } = useLocale(); const [open, setOpen] = useState(false); const fieldArrayName = getValuesFromDayRange.substring(0, getValuesFromDayRange.lastIndexOf(".")); const { setValue, getValues } = useFormContext(); return (