2022-09-12 22:04:33 +00:00
|
|
|
import classNames from "classnames";
|
|
|
|
import React from "react";
|
|
|
|
import { ITimezone } from "react-timezone-select";
|
|
|
|
|
|
|
|
import { Dayjs } from "@calcom/dayjs";
|
2022-10-10 23:31:16 +00:00
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
2022-09-12 22:04:33 +00:00
|
|
|
import getSlots from "@calcom/lib/slots";
|
|
|
|
import { trpc } from "@calcom/trpc/react";
|
2022-10-10 23:31:16 +00:00
|
|
|
|
|
|
|
import SkeletonLoader from "./SkeletonLoaderAvailabilityTimes";
|
2022-09-12 22:04:33 +00:00
|
|
|
|
|
|
|
interface Props {
|
|
|
|
teamId: number;
|
|
|
|
memberId: number;
|
|
|
|
selectedDate: Dayjs;
|
|
|
|
selectedTimeZone: ITimezone;
|
|
|
|
frequency: number;
|
|
|
|
HeaderComponent?: React.ReactNode;
|
|
|
|
className?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function TeamAvailabilityTimes(props: Props) {
|
2022-10-10 23:31:16 +00:00
|
|
|
const { t } = useLocale();
|
|
|
|
|
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()}`,
|
|
|
|
},
|
2022-09-12 22:04:33 +00:00
|
|
|
{
|
|
|
|
refetchOnWindowFocus: false,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2022-12-21 19:32:42 +00:00
|
|
|
const slots = !isLoading
|
2022-09-12 22:04:33 +00:00
|
|
|
? getSlots({
|
|
|
|
frequency: props.frequency,
|
|
|
|
inviteeDate: props.selectedDate,
|
|
|
|
workingHours: data?.workingHours || [],
|
|
|
|
minimumBookingNotice: 0,
|
|
|
|
eventLength: props.frequency,
|
|
|
|
})
|
|
|
|
: [];
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={classNames("min-w-60 flex-grow pl-0", props.className)}>
|
|
|
|
{props.HeaderComponent}
|
2022-12-21 19:32:42 +00:00
|
|
|
{isLoading && slots.length === 0 && <SkeletonLoader />}
|
|
|
|
{!isLoading && slots.length === 0 ? (
|
2022-09-12 22:04:33 +00:00
|
|
|
<div className="flex flex-col items-center justify-center pt-4">
|
2022-10-10 23:31:16 +00:00
|
|
|
<span className="text-sm text-gray-500">{t("no_available_slots")}</span>
|
2022-09-12 22:04:33 +00:00
|
|
|
</div>
|
|
|
|
) : (
|
2022-10-10 23:31:16 +00:00
|
|
|
<>{!isLoading && <p className="mb-3 text-sm text-gray-600">{t("time_available")}</p>}</>
|
2022-09-12 22:04:33 +00:00
|
|
|
)}
|
|
|
|
<div className="max-h-[390px] overflow-scroll">
|
2022-12-21 19:32:42 +00:00
|
|
|
{slots.map((slot) => (
|
|
|
|
<div key={slot.time.format()} className="flex flex-row items-center ">
|
2022-09-12 22:04:33 +00:00
|
|
|
<a
|
2023-01-12 16:57:43 +00:00
|
|
|
className="min-w-48 border-brand text-bookingdarker dark:text-darkgray-800 mb-2 mr-3 block flex-grow rounded-md border bg-white py-2 text-center font-medium dark:border-transparent dark:bg-gray-600 "
|
2022-09-12 22:04:33 +00:00
|
|
|
data-testid="time">
|
2022-12-21 19:32:42 +00:00
|
|
|
{slot.time.tz(props.selectedTimeZone.toString()).format("HH:mm")}
|
2022-09-12 22:04:33 +00:00
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|