import classNames from "classnames"; import dayjs, { Dayjs } from "dayjs"; import utc from "dayjs/plugin/utc"; import React from "react"; import { ITimezone } from "react-timezone-select"; import getSlots from "@lib/slots"; import { trpc } from "@lib/trpc"; import Loader from "@components/Loader"; interface Props { teamId: number; memberId: number; selectedDate: Dayjs; selectedTimeZone: ITimezone; frequency: number; HeaderComponent?: React.ReactNode; className?: string; } dayjs.extend(utc); export default function TeamAvailabilityTimes(props: Props) { const { data, isLoading } = trpc.useQuery( [ "viewer.teams.getMemberAvailability", { teamId: props.teamId, memberId: props.memberId, dateFrom: props.selectedDate.toString(), dateTo: props.selectedDate.add(1, "day").toString(), timezone: `${props.selectedTimeZone.toString()}`, }, ], { refetchOnWindowFocus: false, } ); const times = !isLoading ? getSlots({ frequency: props.frequency, inviteeDate: props.selectedDate, workingHours: data?.workingHours || [], minimumBookingNotice: 0, }) : []; return (
{props.HeaderComponent} {isLoading && times.length === 0 && } {!isLoading && times.length === 0 && (
No Available Slots
)} {times.map((time) => (
{time.format("HH:mm")}
))}
); }