import { ExclamationIcon } from "@heroicons/react/solid"; import { SchedulingType } from "@prisma/client"; import dayjs, { Dayjs } from "dayjs"; import Link from "next/link"; import { useRouter } from "next/router"; import React, { FC, useEffect, useState } from "react"; import { nameOfDay } from "@calcom/lib/weekday"; import classNames from "@lib/classNames"; import { timeZone } from "@lib/clock"; import { useLocale } from "@lib/hooks/useLocale"; import { useSlots } from "@lib/hooks/useSlots"; import Loader from "@components/Loader"; type AvailableTimesProps = { timeFormat: string; minimumBookingNotice: number; beforeBufferTime: number; afterBufferTime: number; eventTypeId: number; eventLength: number; recurringCount: number | undefined; eventTypeSlug: string; slotInterval: number | null; date: Dayjs; users: { username: string | null; }[]; schedulingType: SchedulingType | null; }; const AvailableTimes: FC = ({ date, eventLength, eventTypeId, eventTypeSlug, slotInterval, minimumBookingNotice, recurringCount, timeFormat, users, schedulingType, beforeBufferTime, afterBufferTime, }) => { const { t, i18n } = useLocale(); const router = useRouter(); const { rescheduleUid } = router.query; const { slots, loading, error } = useSlots({ date, slotInterval, eventLength, schedulingType, users, minimumBookingNotice, beforeBufferTime, afterBufferTime, eventTypeId, }); const [brand, setBrand] = useState("#292929"); useEffect(() => { setBrand(getComputedStyle(document.documentElement).getPropertyValue("--brand-color").trim()); }, []); return (
{nameOfDay(i18n.language, Number(date.format("d")))} {date.format(", D ")} {date.toDate().toLocaleString(i18n.language, { month: "long" })}
{!loading && slots?.length > 0 && slots.map((slot) => { type BookingURL = { pathname: string; query: Record; }; const bookingUrl: BookingURL = { pathname: "book", query: { ...router.query, date: slot.time.format(), type: eventTypeId, slug: eventTypeSlug, /** Treat as recurring only when a count exist and it's not a rescheduling workflow */ count: recurringCount && !rescheduleUid ? recurringCount : undefined, }, }; if (rescheduleUid) { bookingUrl.query.rescheduleUid = rescheduleUid as string; } if (schedulingType === SchedulingType.ROUND_ROBIN) { bookingUrl.query.user = slot.users; } return (
{dayjs.tz(slot.time, timeZone()).format(timeFormat)}
); })} {!loading && !error && !slots.length && (

{t("all_booked_today")}

)} {loading && } {error && (

{t("slots_load_fail")}

)}
); }; export default AvailableTimes;