import { FormValues } from "pages/event-types/[type]"; import { Controller, useFormContext } from "react-hook-form"; import { components, OptionProps, SingleValueProps } from "react-select"; import dayjs from "@calcom/dayjs"; import classNames from "@calcom/lib/classNames"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { weekdayNames } from "@calcom/lib/weekday"; import { trpc } from "@calcom/trpc/react"; import useMeQuery from "@calcom/trpc/react/hooks/useMeQuery"; import { Badge, Button, Select, SettingsToggle, SkeletonText } from "@calcom/ui"; import { FiExternalLink, FiGlobe } from "@calcom/ui/components/icon"; import { SelectSkeletonLoader } from "@components/availability/SkeletonLoader"; type AvailabilityOption = { label: string; value: number; isDefault: boolean; }; const Option = ({ ...props }: OptionProps) => { const { label, isDefault } = props.data; const { t } = useLocale(); return ( {label} {isDefault && ( {t("default")} )} ); }; const SingleValue = ({ ...props }: SingleValueProps) => { const { label, isDefault } = props.data; const { t } = useLocale(); return ( {label} {isDefault && ( {t("default")} )} ); }; const AvailabilitySelect = ({ className = "", ...props }: { className?: string; name: string; value: number; onBlur: () => void; onChange: (value: AvailabilityOption | null) => void; }) => { const { data, isLoading } = trpc.viewer.availability.list.useQuery(); const { t } = useLocale(); if (isLoading) { return ; } const schedules = data?.schedules || []; const options = schedules.map((schedule) => ({ value: schedule.id, label: schedule.name, isDefault: schedule.isDefault, })); const value = options.find((option) => props.value ? option.value === props.value : option.value === schedules.find((schedule) => schedule.isDefault)?.id ); return (