import Link from "next/link"; import { useRouter } from "next/router"; import { FC, useEffect, useState } from "react"; import dayjs, { Dayjs } from "@calcom/dayjs"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { nameOfDay } from "@calcom/lib/weekday"; import type { Slot } from "@calcom/trpc/server/routers/viewer/slots"; import { SkeletonContainer, SkeletonText } from "@calcom/ui"; import classNames from "@lib/classNames"; import { timeZone } from "@lib/clock"; type AvailableTimesProps = { timeFormat: string; eventTypeId: number; recurringCount: number | undefined; eventTypeSlug: string; date: Dayjs; seatsPerTimeSlot?: number | null; slots?: Slot[]; isLoading: boolean; ethSignature?: string; }; const AvailableTimes: FC = ({ slots = [], isLoading, date, eventTypeId, eventTypeSlug, recurringCount, timeFormat, seatsPerTimeSlot, ethSignature, }) => { const { t, i18n } = useLocale(); const router = useRouter(); const { rescheduleUid } = router.query; 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" })}
{slots.length > 0 && slots.map((slot) => { type BookingURL = { pathname: string; query: Record; }; const bookingUrl: BookingURL = { pathname: "book", query: { ...router.query, date: dayjs(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, ethSignature, }, }; if (rescheduleUid) { bookingUrl.query.rescheduleUid = rescheduleUid as string; } // If event already has an attendee add booking id if (slot.bookingUid) { bookingUrl.query.bookingUid = slot.bookingUid; } return (
{/* Current there is no way to disable Next.js Links */} {seatsPerTimeSlot && slot.attendees && slot.attendees >= seatsPerTimeSlot ? (
{dayjs(slot.time).tz(timeZone()).format(timeFormat)} {!!seatsPerTimeSlot &&

{t("booking_full")}

}
) : ( {dayjs(slot.time).tz(timeZone()).format(timeFormat)} {!!seatsPerTimeSlot && (

= 0.8 ? "text-rose-600" : slot.attendees && slot.attendees / seatsPerTimeSlot >= 0.33 ? "text-yellow-500" : "text-emerald-400" } text-sm`}> {slot.attendees ? seatsPerTimeSlot - slot.attendees : seatsPerTimeSlot} /{" "} {seatsPerTimeSlot} {t("seats_available")}

)}
)}
); })} {!isLoading && !slots.length && (

{t("all_booked_today")}

)} {isLoading && !slots.length && ( <> )}
); }; export default AvailableTimes;