import { useCallback, useEffect, useMemo, useState, Fragment } from "react"; import { Controller, useFieldArray, useFormContext } from "react-hook-form"; import type { UseFieldArrayRemove, FieldValues, FieldPath, FieldPathValue, FieldArrayWithId, ArrayPath, ControllerRenderProps, Control, } from "react-hook-form"; import { GroupBase, Props } from "react-select"; import dayjs, { ConfigType, Dayjs } from "@calcom/dayjs"; import { defaultDayRange as DEFAULT_DAY_RANGE } from "@calcom/lib/availability"; import classNames from "@calcom/lib/classNames"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { weekdayNames } from "@calcom/lib/weekday"; import useMeQuery from "@calcom/trpc/react/hooks/useMeQuery"; import { TimeRange } from "@calcom/types/schedule"; import { Icon } from "@calcom/ui"; import Dropdown, { DropdownMenuContent, DropdownMenuTrigger } from "@calcom/ui/Dropdown"; import { Button } from "@calcom/ui/components/button"; import { Select, Switch } from "@calcom/ui/v2"; import { SkeletonText } from "@calcom/ui/v2/core/skeleton"; export type FieldPathByValue = { [Key in FieldPath]: FieldPathValue extends TValue ? Key : never; }[FieldPath]; const ScheduleDay = ({ name, weekday, control, CopyButton, }: { name: string; weekday: string; control: Control; CopyButton: JSX.Element; }) => { const { watch, setValue } = useFormContext(); const watchDayRange = watch(name); return (
{/* Label & switch container */}
<> {watchDayRange ? (
{!!watchDayRange.length &&
{CopyButton}
}
) : ( )}
); }; const CopyButton = ({ getValuesFromDayRange, weekStart, }: { getValuesFromDayRange: string; weekStart: number; }) => { const { t } = useLocale(); const [open, setOpen] = useState(false); const fieldArrayName = getValuesFromDayRange.substring(0, getValuesFromDayRange.lastIndexOf(".")); const { setValue, getValues } = useFormContext(); return (
))} ); }; const RemoveTimeButton = ({ index, remove, className, }: { index: number | number[]; remove: UseFieldArrayRemove; className?: string; }) => { return ( ); }; export default Schedule;