2021-06-19 22:50:47 +00:00
|
|
|
import Link from "next/link";
|
2021-06-24 22:15:18 +00:00
|
|
|
import { useRouter } from "next/router";
|
|
|
|
import Slots from "./Slots";
|
2021-07-01 10:31:38 +00:00
|
|
|
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
|
|
|
|
2021-07-08 21:14:29 +00:00
|
|
|
const AvailableTimes = ({
|
|
|
|
date,
|
|
|
|
eventLength,
|
|
|
|
eventTypeId,
|
2021-07-22 22:52:27 +00:00
|
|
|
minimumBookingNotice,
|
2021-07-08 21:14:29 +00:00
|
|
|
workingHours,
|
|
|
|
timeFormat,
|
|
|
|
user,
|
|
|
|
organizerTimeZone,
|
|
|
|
}) => {
|
2021-06-19 22:50:47 +00:00
|
|
|
const router = useRouter();
|
2021-06-27 22:30:11 +00:00
|
|
|
const { rescheduleUid } = router.query;
|
2021-07-08 21:14:29 +00:00
|
|
|
|
|
|
|
const { slots, isFullyBooked, hasErrors } = Slots({
|
|
|
|
date,
|
|
|
|
eventLength,
|
|
|
|
workingHours,
|
|
|
|
organizerTimeZone,
|
2021-07-22 22:52:27 +00:00
|
|
|
minimumBookingNotice,
|
2021-07-08 21:14:29 +00:00
|
|
|
});
|
|
|
|
|
2021-06-19 22:50:47 +00:00
|
|
|
return (
|
2021-08-08 15:13:31 +00:00
|
|
|
<div className="sm:pl-4 mt-8 sm:mt-0 text-center sm:w-1/3 md:max-h-97 overflow-y-auto">
|
2021-08-12 17:10:57 +00:00
|
|
|
<div className="text-gray-600 font-light text-lg mb-4 text-left">
|
|
|
|
<span className="w-1/2 dark:text-white text-gray-600">
|
|
|
|
<strong>{date.format("dddd")}</strong>
|
|
|
|
<span className="text-gray-500">{date.format(", DD MMMM")}</span>
|
|
|
|
</span>
|
2021-06-19 22:50:47 +00:00
|
|
|
</div>
|
2021-07-01 10:31:38 +00:00
|
|
|
{slots.length > 0 &&
|
2021-06-24 22:15:18 +00:00
|
|
|
slots.map((slot) => (
|
|
|
|
<div key={slot.format()}>
|
2021-06-20 00:10:08 +00:00
|
|
|
<Link
|
2021-06-24 22:15:18 +00:00
|
|
|
href={
|
2021-07-01 10:31:38 +00:00
|
|
|
`/${user.username}/book?date=${slot.utc().format()}&type=${eventTypeId}` +
|
2021-06-24 22:15:18 +00:00
|
|
|
(rescheduleUid ? "&rescheduleUid=" + rescheduleUid : "")
|
|
|
|
}>
|
2021-08-12 13:54:05 +00:00
|
|
|
<a className="block font-medium mb-4 bg-white dark:bg-gray-600 text-primary-500 dark:text-neutral-200 border border-primary-500 dark:border-transparent rounded-sm hover:text-white hover:bg-primary-500 dark:hover:border-black py-4 dark:hover:bg-black">
|
2021-06-24 22:15:18 +00:00
|
|
|
{slot.format(timeFormat)}
|
|
|
|
</a>
|
2021-06-20 00:10:08 +00:00
|
|
|
</Link>
|
|
|
|
</div>
|
2021-07-01 10:31:38 +00:00
|
|
|
))}
|
|
|
|
{isFullyBooked && (
|
|
|
|
<div className="w-full h-full flex flex-col justify-center content-center items-center -mt-4">
|
2021-07-13 13:11:01 +00:00
|
|
|
<h1 className="text-xl text-black dark:text-white">{user.name} is all booked today.</h1>
|
2021-07-01 10:31:38 +00:00
|
|
|
</div>
|
2021-06-27 22:30:11 +00:00
|
|
|
)}
|
|
|
|
|
2021-08-04 19:39:59 +00:00
|
|
|
{!isFullyBooked && slots.length === 0 && !hasErrors && <Loader />}
|
2021-06-27 22:30:11 +00:00
|
|
|
|
|
|
|
{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>
|
2021-06-27 22:02:27 +00:00
|
|
|
</div>
|
2021-06-27 22:30:11 +00:00
|
|
|
</div>
|
|
|
|
)}
|
2021-06-19 22:50:47 +00:00
|
|
|
</div>
|
|
|
|
);
|
2021-06-24 22:15:18 +00:00
|
|
|
};
|
2021-06-19 22:50:47 +00:00
|
|
|
|
2021-06-22 15:19:28 +00:00
|
|
|
export default AvailableTimes;
|