import { SchedulingType } from "@prisma/client"; import dayjs, { Dayjs } from "dayjs"; import Link from "next/link"; import { useRouter } from "next/router"; import { FC, useEffect, useState } from "react"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { nameOfDay } from "@calcom/lib/weekday"; import { SkeletonContainer, SkeletonText } from "@calcom/ui"; import classNames from "@lib/classNames"; import { timeZone } from "@lib/clock"; import type { Slot } from "@server/routers/viewer/slots"; type AvailableTimesProps = { timeFormat: string; eventTypeId: number; recurringCount: number | undefined; eventTypeSlug: string; date: Dayjs; users: { username: string | null; }[]; schedulingType: SchedulingType | null; seatsPerTimeSlot?: number | null; slots?: Slot[]; isLoading: boolean; }; const AvailableTimes: FC = ({ slots = [], isLoading, date, eventTypeId, eventTypeSlug, recurringCount, timeFormat, schedulingType, seatsPerTimeSlot, }) => { 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, }, }; if (rescheduleUid) { bookingUrl.query.rescheduleUid = rescheduleUid as string; } if (schedulingType === SchedulingType.ROUND_ROBIN) { bookingUrl.query.user = slot.users; } // 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;