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 } from "react"; import { useLocale } from "@lib/hooks/useLocale"; import { useSlots } from "@lib/hooks/useSlots"; import Loader from "@components/Loader"; type AvailableTimesProps = { workingHours: { days: number[]; startTime: number; endTime: number; }[]; timeFormat: string; minimumBookingNotice: number; eventTypeId: number; eventLength: number; date: Dayjs; users: { username: string | null; }[]; schedulingType: SchedulingType | null; }; const AvailableTimes: FC = ({ date, eventLength, eventTypeId, minimumBookingNotice, workingHours, timeFormat, users, schedulingType, }) => { const { t } = useLocale(); const router = useRouter(); const { rescheduleUid } = router.query; const { slots, loading, error } = useSlots({ date, eventLength, schedulingType, workingHours, users, minimumBookingNotice, eventTypeId, }); return (
{t(date.format("dddd").toLowerCase())} {date.format(", DD ")} {t(date.format("MMMM").toLowerCase())}
{!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;