import { ExclamationIcon } from "@heroicons/react/solid"; import { SchedulingType } from "@prisma/client"; import { Dayjs } from "dayjs"; import Link from "next/link"; import { useRouter } from "next/router"; import React, { FC, useEffect, useState } from "react"; import classNames from "@lib/classNames"; import { useLocale } from "@lib/hooks/useLocale"; import { useSlots } from "@lib/hooks/useSlots"; import Loader from "@components/Loader"; type AvailableTimesProps = { timeFormat: string; minimumBookingNotice: number; eventTypeId: number; eventLength: number; slotInterval: number | null; date: Dayjs; users: { username: string | null; }[]; schedulingType: SchedulingType | null; }; const AvailableTimes: FC = ({ date, eventLength, eventTypeId, slotInterval, minimumBookingNotice, timeFormat, users, schedulingType, }) => { const { t, i18n } = useLocale(); const router = useRouter(); const { rescheduleUid } = router.query; const { slots, loading, error } = useSlots({ date, slotInterval, eventLength, schedulingType, users, minimumBookingNotice, eventTypeId, }); const [brand, setBrand] = useState("#292929"); useEffect(() => { setBrand(getComputedStyle(document.documentElement).getPropertyValue("--brand-color").trim()); }, []); return (
{date.toDate().toLocaleString(i18n.language, { weekday: "long" })} {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, }, }; if (rescheduleUid) { bookingUrl.query.rescheduleUid = rescheduleUid as string; } if (schedulingType === SchedulingType.ROUND_ROBIN) { bookingUrl.query.user = slot.users; } return (
{slot.time.format(timeFormat)}
); })} {!loading && !error && !slots.length && (

{t("all_booked_today")}

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

{t("slots_load_fail")}

)}
); }; export default AvailableTimes;