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 { 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 router = useRouter(); const { rescheduleUid } = router.query; const { slots, loading, error } = useSlots({ date, eventLength, schedulingType, workingHours, users, minimumBookingNotice, eventTypeId, }); return (
{date.format("dddd")} {date.format(", DD MMMM")}
{!loading && slots?.length > 0 && slots.map((slot) => { const bookingUrl = { pathname: "book", query: { ...router.query, date: slot.time.format(), type: eventTypeId, }, }; if (rescheduleUid) { bookingUrl.query.rescheduleUid = rescheduleUid; } if (schedulingType === SchedulingType.ROUND_ROBIN) { bookingUrl.query.user = slot.users; } return (
{slot.time.format(timeFormat)}
); })} {!loading && !error && !slots.length && (

All booked today.

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

Could not load the available time slots.

)}
); }; export default AvailableTimes;