import { noop } from "@tanstack/react-table"; import { formatInTimeZone } from "date-fns-tz"; import { useIsPlatform } from "@calcom/atoms/hooks/useIsPlatform"; import dayjs from "@calcom/dayjs"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import type { TimeRange, WorkingHours } from "@calcom/types/schedule"; import { Button } from "@calcom/ui/components/button"; import { DialogTrigger } from "@calcom/ui/components/dialog"; import { Tooltip } from "@calcom/ui/components/tooltip"; import DateOverrideInputDialog from "./DateOverrideInputDialog"; const sortByDate = (a: { ranges: TimeRange[]; id: string }, b: { ranges: TimeRange[]; id: string }) => { return a.ranges[0].start > b.ranges[0].start ? 1 : -1; }; interface TravelSchedule { id: number; startDate: Date; endDate: Date | null; timeZone: string; } // I would like this to be decoupled, but RHF really doesn't support this. const DateOverrideList = ({ workingHours, excludedDates = [], travelSchedules = [], userTimeFormat, hour12, replace, fields, weekStart = 0, handleAvailabilityUpdate = noop, isDryRun = false, }: { // eslint-disable-next-line @typescript-eslint/no-explicit-any replace: any; fields: { ranges: TimeRange[]; id: string }[]; workingHours: WorkingHours[]; excludedDates?: string[]; userTimeFormat: number | null; hour12: boolean; travelSchedules?: TravelSchedule[]; weekStart?: 0 | 1 | 2 | 3 | 4 | 5 | 6; handleAvailabilityUpdate?: VoidFunction; isDryRun?: boolean; }) => { const { t, i18n } = useLocale(); const isPlatform = useIsPlatform(); const unsortedFieldArrayMap = fields.reduce( (map: { [id: string]: number }, { id }, index) => ({ ...map, [id]: index }), {} ); if (!fields.length) { return <>>; } const timeSpan = ({ start, end }: TimeRange) => { if (isPlatform) { return `${formatInTimeZone(start, "UTC", "h:mm a")} - ${formatInTimeZone(end, "UTC", "h:mm a")}`; } return `${new Intl.DateTimeFormat(i18n.language, { hour: "numeric", minute: "numeric", hour12 }).format( new Date(start.toISOString().slice(0, -1)) )} - ${new Intl.DateTimeFormat(i18n.language, { hour: "numeric", minute: "numeric", hour12 }).format( new Date(end.toISOString().slice(0, -1)) )}`; }; return (
{t("unavailable")}
) : ( item.ranges.map((range, i) => ({`${timeSpan(range)} ${ travelSchedules .find( (travelSchedule) => !dayjs(item.ranges[0].start).isBefore(travelSchedule.startDate) && (!dayjs(item.ranges[0].end).isAfter(travelSchedule.endDate) || !travelSchedule.endDate) ) ?.timeZone.replace(/_/g, " ") || "" }`} <>>
)) )}