2021-12-09 23:51:30 +00:00
|
|
|
import classNames from "classnames";
|
|
|
|
import React from "react";
|
|
|
|
import { ITimezone } from "react-timezone-select";
|
|
|
|
|
2022-06-28 20:40:58 +00:00
|
|
|
import { Dayjs } from "@calcom/dayjs";
|
2022-07-22 17:27:06 +00:00
|
|
|
import getSlots from "@calcom/lib/slots";
|
|
|
|
import { trpc } from "@calcom/trpc/react";
|
2022-11-23 02:55:25 +00:00
|
|
|
import { Loader } from "@calcom/ui";
|
2021-12-09 23:51:30 +00:00
|
|
|
|
|
|
|
interface Props {
|
2021-12-17 00:16:59 +00:00
|
|
|
teamId: number;
|
|
|
|
memberId: number;
|
2021-12-09 23:51:30 +00:00
|
|
|
selectedDate: Dayjs;
|
|
|
|
selectedTimeZone: ITimezone;
|
|
|
|
frequency: number;
|
|
|
|
HeaderComponent?: React.ReactNode;
|
|
|
|
className?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function TeamAvailabilityTimes(props: Props) {
|
2022-11-10 23:40:01 +00:00
|
|
|
const { data, isLoading } = trpc.viewer.teams.getMemberAvailability.useQuery(
|
|
|
|
{
|
|
|
|
teamId: props.teamId,
|
|
|
|
memberId: props.memberId,
|
|
|
|
dateFrom: props.selectedDate.toString(),
|
|
|
|
dateTo: props.selectedDate.add(1, "day").toString(),
|
|
|
|
timezone: `${props.selectedTimeZone.toString()}`,
|
|
|
|
},
|
2021-12-09 23:51:30 +00:00
|
|
|
{
|
|
|
|
refetchOnWindowFocus: false,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2022-12-21 19:32:42 +00:00
|
|
|
const slots = !isLoading
|
2021-12-09 23:51:30 +00:00
|
|
|
? getSlots({
|
|
|
|
frequency: props.frequency,
|
|
|
|
inviteeDate: props.selectedDate,
|
|
|
|
workingHours: data?.workingHours || [],
|
|
|
|
minimumBookingNotice: 0,
|
2022-03-12 06:52:27 +00:00
|
|
|
eventLength: props.frequency,
|
2021-12-09 23:51:30 +00:00
|
|
|
})
|
|
|
|
: [];
|
|
|
|
|
|
|
|
return (
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className={classNames("min-w-60 flex-grow p-5 pl-0", props.className)}>
|
2021-12-09 23:51:30 +00:00
|
|
|
{props.HeaderComponent}
|
2022-12-21 19:32:42 +00:00
|
|
|
{isLoading && slots.length === 0 && <Loader />}
|
|
|
|
{!isLoading && slots.length === 0 && (
|
2021-12-09 23:51:30 +00:00
|
|
|
<div className="flex flex-col items-center justify-center pt-4">
|
|
|
|
<span className="text-sm text-gray-500">No Available Slots</span>
|
|
|
|
</div>
|
|
|
|
)}
|
2022-12-21 19:32:42 +00:00
|
|
|
{slots.map((slot) => (
|
|
|
|
<div key={slot.time.format()} className="flex flex-row items-center">
|
2021-12-09 23:51:30 +00:00
|
|
|
<a
|
2023-01-12 16:57:43 +00:00
|
|
|
className="min-w-48 border-brand text-bookingdarker hover:bg-brand hover:text-brandcontrast dark:hover:bg-darkmodebrand dark:hover:text-darkmodebrandcontrast dark:text-darkgray-800 mb-2 mr-3 block flex-grow rounded-sm border bg-white py-2 text-center font-medium dark:border-transparent dark:bg-gray-600 dark:hover:border-black dark:hover:bg-black dark:hover:text-white"
|
2021-12-09 23:51:30 +00:00
|
|
|
data-testid="time">
|
2022-12-21 19:32:42 +00:00
|
|
|
{slot.time.format("HH:mm")}
|
2021-12-09 23:51:30 +00:00
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|