import type { Dayjs } from "@calcom/dayjs"; import dayjs from "@calcom/dayjs"; import type { Slots } from "@calcom/features/schedules"; import { classNames } from "@calcom/lib"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { nameOfDay } from "@calcom/lib/weekday"; import { Button, SkeletonText } from "@calcom/ui"; import { useTimePreferences } from "../lib"; import { TimeFormatToggle } from "./TimeFormatToggle"; type AvailableTimesProps = { date: Dayjs; slots: Slots[string]; onTimeSelect: (time: string) => void; seatsPerTimeslot?: number | null; showTimeformatToggle?: boolean; className?: string; }; export const AvailableTimes = ({ date, slots, onTimeSelect, seatsPerTimeslot, showTimeformatToggle = true, className, }: AvailableTimesProps) => { const { t, i18n } = useLocale(); const [timeFormat, timezone] = useTimePreferences((state) => [state.timeFormat, state.timezone]); const hasTimeSlots = !!seatsPerTimeslot; return (
{nameOfDay(i18n.language, Number(date.format("d")), "short")}, {" "} {date.toDate().toLocaleString(i18n.language, { month: "short" })} {date.format(" D ")} {showTimeformatToggle && (
)}
{!slots.length && (

{t("all_booked_today")}

)} {slots.map((slot) => { const bookingFull = !!(hasTimeSlots && slot.attendees && slot.attendees >= seatsPerTimeslot); return ( ); })}
); }; export const AvailableTimesSkeleton = () => (
{/* Random number of elements between 1 and 10. */} {Array.from({ length: Math.floor(Math.random() * 10) + 1 }).map((_, i) => ( ))}
);