diff --git a/components/booking/AvailableTimes.tsx b/components/booking/AvailableTimes.tsx
index f6f10574..2e1f5f3e 100644
--- a/components/booking/AvailableTimes.tsx
+++ b/components/booking/AvailableTimes.tsx
@@ -1,36 +1,37 @@
-import dayjs, {Dayjs} from "dayjs";
-import isBetween from 'dayjs/plugin/isBetween';
+import dayjs from "dayjs";
+import isBetween from "dayjs/plugin/isBetween";
dayjs.extend(isBetween);
-import {useEffect, useMemo, useState} from "react";
+import { useEffect, useState } from "react";
import getSlots from "../../lib/slots";
import Link from "next/link";
-import {timeZone} from "../../lib/clock";
-import {useRouter} from "next/router";
+import { timeZone } from "../../lib/clock";
+import { useRouter } from "next/router";
+import { ExclamationIcon } from "@heroicons/react/solid";
const AvailableTimes = (props) => {
-
const router = useRouter();
const { user, rescheduleUid } = router.query;
const [loaded, setLoaded] = useState(false);
+ const [error, setError] = useState(false);
const times = getSlots({
- calendarTimeZone: props.user.timeZone,
- selectedTimeZone: timeZone(),
- eventLength: props.eventType.length,
- selectedDate: props.date,
- dayStartTime: props.user.startTime,
- dayEndTime: props.user.endTime,
- });
+ calendarTimeZone: props.user.timeZone,
+ selectedTimeZone: timeZone(),
+ eventLength: props.eventType.length,
+ selectedDate: props.date,
+ dayStartTime: props.user.startTime,
+ dayEndTime: props.user.endTime,
+ });
const handleAvailableSlots = (busyTimes: []) => {
// Check for conflicts
for (let i = times.length - 1; i >= 0; i -= 1) {
- busyTimes.forEach(busyTime => {
- let startTime = dayjs(busyTime.start);
- let endTime = dayjs(busyTime.end);
+ busyTimes.forEach((busyTime) => {
+ const startTime = dayjs(busyTime.start);
+ const endTime = dayjs(busyTime.end);
// Check if start times are the same
- if (dayjs(times[i]).format('HH:mm') == startTime.format('HH:mm')) {
+ if (dayjs(times[i]).format("HH:mm") == startTime.format("HH:mm")) {
times.splice(i, 1);
}
@@ -40,12 +41,12 @@ const AvailableTimes = (props) => {
}
// Check if slot end time is between start and end time
- if (dayjs(times[i]).add(props.eventType.length, 'minutes').isBetween(startTime, endTime)) {
+ if (dayjs(times[i]).add(props.eventType.length, "minutes").isBetween(startTime, endTime)) {
times.splice(i, 1);
}
// Check if startTime is between slot
- if (startTime.isBetween(dayjs(times[i]), dayjs(times[i]).add(props.eventType.length, 'minutes'))) {
+ if (startTime.isBetween(dayjs(times[i]), dayjs(times[i]).add(props.eventType.length, "minutes"))) {
times.splice(i, 1);
}
});
@@ -57,31 +58,65 @@ const AvailableTimes = (props) => {
// Re-render only when invitee changes date
useEffect(() => {
setLoaded(false);
- fetch(`/api/availability/${user}?dateFrom=${props.date.startOf('day').utc().format()}&dateTo=${props.date.endOf('day').utc().format()}`)
- .then( res => res.json())
- .then(handleAvailableSlots);
+ setError(false);
+ fetch(
+ `/api/availability/${user}?dateFrom=${props.date.startOf("day").utc().format()}&dateTo=${props.date
+ .endOf("day")
+ .utc()
+ .format()}`
+ )
+ .then((res) => res.json())
+ .then(handleAvailableSlots)
+ .catch((e) => {
+ console.error(e);
+ setError(true);
+ });
}, [props.date]);
return (
-
- {props.date.format("dddd DD MMMM YYYY")}
-
+ {props.date.format("dddd DD MMMM YYYY")}
- {
- loaded ? times.map((time) =>
+ {!error &&
+ loaded &&
+ times.map((time) => (
- ) :
- }
+ ))}
+ {!error && !loaded &&
}
+ {error && (
+
+ )}
);
-}
+};
-export default AvailableTimes;
\ No newline at end of file
+export default AvailableTimes;
diff --git a/components/ui/Button.tsx b/components/ui/Button.tsx
index 647d633c..054bbd66 100644
--- a/components/ui/Button.tsx
+++ b/components/ui/Button.tsx
@@ -1,11 +1,10 @@
import { useState } from 'react';
export default function Button(props) {
- const [loading, setLoading] = useState(false);
return(
-