cal.pub0.org/components/booking/AvailableTimes.tsx

83 lines
2.8 KiB
TypeScript
Raw Normal View History

2021-06-19 22:50:47 +00:00
import Link from "next/link";
import { useRouter } from "next/router";
import Slots from "./Slots";
import { ExclamationIcon } from "@heroicons/react/solid";
2021-08-04 19:39:59 +00:00
import React from "react";
import Loader from "@components/Loader";
2021-06-19 22:50:47 +00:00
const AvailableTimes = ({
date,
eventLength,
eventTypeId,
2021-07-22 22:52:27 +00:00
minimumBookingNotice,
workingHours,
timeFormat,
user,
organizerTimeZone,
2021-08-06 15:29:09 +00:00
height,
}) => {
2021-06-19 22:50:47 +00:00
const router = useRouter();
const { rescheduleUid } = router.query;
const { slots, isFullyBooked, hasErrors } = Slots({
date,
eventLength,
workingHours,
organizerTimeZone,
2021-07-22 22:52:27 +00:00
minimumBookingNotice,
});
2021-06-19 22:50:47 +00:00
return (
2021-08-06 15:29:09 +00:00
<div
className="sm:pl-4 mt-16 pt-4 pr-6 bg-neutral-50 dark:bg-neutral-800 rounded-r-sm border border-l-0 border-neutral-300 dark:border-neutral-700 text-center h-full overflow-y-auto"
style={{ maxHeight: height }}>
<div className="font-semibold mb-4 text-left border-b border-neutral-200 pb-4">
<span className="w-1/2 dark:text-white text-primary-500">{date.format("dddd DD MMMM YYYY")}</span>
2021-06-19 22:50:47 +00:00
</div>
{slots.length > 0 &&
slots.map((slot) => (
<div key={slot.format()}>
<Link
href={
`/${user.username}/book?date=${slot.utc().format()}&type=${eventTypeId}` +
(rescheduleUid ? "&rescheduleUid=" + rescheduleUid : "")
}>
2021-08-06 15:29:09 +00:00
<a className="block font-medium mb-4 bg-white dark:bg-neutral-700 text-primary-500 dark:text-neutral-200 border border-primary-500 dark:border-neutral-600 rounded hover:text-white hover:bg-primary-500 dark:hover:bg-primary-500 dark:hover:border-primary-500 py-4">
{slot.format(timeFormat)}
</a>
</Link>
</div>
))}
{isFullyBooked && (
<div className="w-full h-full flex flex-col justify-center content-center items-center -mt-4">
<h1 className="text-xl text-black dark:text-white">{user.name} is all booked today.</h1>
</div>
)}
2021-08-04 19:39:59 +00:00
{!isFullyBooked && slots.length === 0 && !hasErrors && <Loader />}
{hasErrors && (
<div className="bg-yellow-50 border-l-4 border-yellow-400 p-4">
<div className="flex">
<div className="flex-shrink-0">
<ExclamationIcon className="h-5 w-5 text-yellow-400" aria-hidden="true" />
</div>
<div className="ml-3">
<p className="text-sm text-yellow-700">
Could not load the available time slots.{" "}
<a
href={"mailto:" + user.email}
className="font-medium underline text-yellow-700 hover:text-yellow-600">
Contact {user.name} via e-mail
</a>
</p>
</div>
</div>
</div>
)}
2021-06-19 22:50:47 +00:00
</div>
);
};
2021-06-19 22:50:47 +00:00
export default AvailableTimes;