fix: busy times are shown on booking
parent
24f10e4f29
commit
3c8b9da54d
|
@ -1,7 +1,7 @@
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import isBetween from "dayjs/plugin/isBetween";
|
import isBetween from "dayjs/plugin/isBetween";
|
||||||
dayjs.extend(isBetween);
|
dayjs.extend(isBetween);
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState, useMemo } from "react";
|
||||||
import getSlots from "../../lib/slots";
|
import getSlots from "../../lib/slots";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { timeZone } from "../../lib/clock";
|
import { timeZone } from "../../lib/clock";
|
||||||
|
@ -14,14 +14,18 @@ const AvailableTimes = (props) => {
|
||||||
const [loaded, setLoaded] = useState(false);
|
const [loaded, setLoaded] = useState(false);
|
||||||
const [error, setError] = useState(false);
|
const [error, setError] = useState(false);
|
||||||
|
|
||||||
const times = getSlots({
|
const times = useMemo(() => {
|
||||||
calendarTimeZone: props.user.timeZone,
|
const slots = getSlots({
|
||||||
selectedTimeZone: timeZone(),
|
calendarTimeZone: props.user.timeZone,
|
||||||
eventLength: props.eventType.length,
|
selectedTimeZone: timeZone(),
|
||||||
selectedDate: props.date,
|
eventLength: props.eventType.length,
|
||||||
dayStartTime: props.user.startTime,
|
selectedDate: props.date,
|
||||||
dayEndTime: props.user.endTime,
|
dayStartTime: props.user.startTime,
|
||||||
});
|
dayEndTime: props.user.endTime,
|
||||||
|
});
|
||||||
|
|
||||||
|
return slots;
|
||||||
|
}, [props.date]);
|
||||||
|
|
||||||
const handleAvailableSlots = (busyTimes: []) => {
|
const handleAvailableSlots = (busyTimes: []) => {
|
||||||
// Check for conflicts
|
// Check for conflicts
|
||||||
|
@ -80,6 +84,7 @@ const AvailableTimes = (props) => {
|
||||||
</div>
|
</div>
|
||||||
{!error &&
|
{!error &&
|
||||||
loaded &&
|
loaded &&
|
||||||
|
times.length > 0 &&
|
||||||
times.map((time) => (
|
times.map((time) => (
|
||||||
<div key={dayjs(time).utc().format()}>
|
<div key={dayjs(time).utc().format()}>
|
||||||
<Link
|
<Link
|
||||||
|
@ -95,6 +100,11 @@ const AvailableTimes = (props) => {
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
{!error && loaded && times.length == 0 && (
|
||||||
|
<div className="w-full h-full flex flex-col justify-center content-center items-center -mt-4">
|
||||||
|
<h1 className="text-xl font">{props.user.name} is all booked today.</h1>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
{!error && !loaded && <div className="loader" />}
|
{!error && !loaded && <div className="loader" />}
|
||||||
{error && (
|
{error && (
|
||||||
<div className="bg-yellow-50 border-l-4 border-yellow-400 p-4">
|
<div className="bg-yellow-50 border-l-4 border-yellow-400 p-4">
|
||||||
|
|
Loading…
Reference in New Issue