2022-11-23 02:55:25 +00:00
|
|
|
import { useEffect, useState } from "react";
|
2021-12-09 23:51:30 +00:00
|
|
|
|
2022-06-28 20:40:58 +00:00
|
|
|
import dayjs from "@calcom/dayjs";
|
2023-04-19 14:15:08 +00:00
|
|
|
import LicenseRequired from "@calcom/features/ee/common/components/LicenseRequired";
|
2022-05-30 07:57:48 +00:00
|
|
|
import { WEBAPP_URL } from "@calcom/lib/constants";
|
2023-04-19 14:15:08 +00:00
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
2023-04-05 18:14:46 +00:00
|
|
|
import type { RouterOutputs } from "@calcom/trpc/react";
|
|
|
|
import { trpc } from "@calcom/trpc/react";
|
2022-11-23 02:55:25 +00:00
|
|
|
import type { ITimezone } from "@calcom/ui";
|
2023-04-19 14:15:08 +00:00
|
|
|
import { Avatar, DatePicker, Label, Select, TimezoneSelect } from "@calcom/ui";
|
2021-12-09 23:51:30 +00:00
|
|
|
|
|
|
|
import TeamAvailabilityTimes from "./TeamAvailabilityTimes";
|
|
|
|
|
|
|
|
interface Props {
|
2022-11-10 23:40:01 +00:00
|
|
|
team?: RouterOutputs["viewer"]["teams"]["get"];
|
|
|
|
member?: RouterOutputs["viewer"]["teams"]["get"]["members"][number];
|
2021-12-09 23:51:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default function TeamAvailabilityModal(props: Props) {
|
|
|
|
const utils = trpc.useContext();
|
|
|
|
const [selectedDate, setSelectedDate] = useState(dayjs());
|
2021-12-17 00:16:59 +00:00
|
|
|
const [selectedTimeZone, setSelectedTimeZone] = useState<ITimezone>(
|
|
|
|
localStorage.getItem("timeOption.preferredTimeZone") || dayjs.tz.guess()
|
|
|
|
);
|
2023-04-19 14:15:08 +00:00
|
|
|
|
|
|
|
const { t } = useLocale();
|
|
|
|
|
2021-12-17 00:16:59 +00:00
|
|
|
const [frequency, setFrequency] = useState<15 | 30 | 60>(30);
|
2021-12-09 23:51:30 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
2022-11-10 23:40:01 +00:00
|
|
|
utils.viewer.teams.getMemberAvailability.invalidate();
|
2021-12-09 23:51:30 +00:00
|
|
|
}, [utils, selectedTimeZone, selectedDate]);
|
|
|
|
|
|
|
|
return (
|
2022-05-26 17:07:14 +00:00
|
|
|
<LicenseRequired>
|
2023-04-19 14:15:08 +00:00
|
|
|
<>
|
|
|
|
<div className="grid h-[400px] grid-cols-2 space-x-11 rtl:space-x-reverse">
|
|
|
|
<div className="col-span-1">
|
|
|
|
<div className="flex">
|
|
|
|
<Avatar
|
|
|
|
size="md"
|
|
|
|
imageSrc={WEBAPP_URL + "/" + props.member?.username + "/avatar.png"}
|
|
|
|
alt={props.member?.name || ""}
|
|
|
|
/>
|
|
|
|
<div className="flex items-center justify-center ">
|
|
|
|
<span className="text-subtle ml-2 text-base font-semibold leading-4">
|
|
|
|
{props.member?.name}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<div className="text-brand-900 mt-4 mb-5 text-2xl font-semibold">{t("availability")}</div>
|
|
|
|
<DatePicker
|
|
|
|
minDate={new Date()}
|
|
|
|
date={selectedDate.toDate() || dayjs().toDate()}
|
|
|
|
onDatesChange={(newDate) => {
|
|
|
|
setSelectedDate(dayjs(newDate));
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<Label className="mt-4">{t("timezone")}</Label>
|
|
|
|
<TimezoneSelect
|
|
|
|
id="timeZone"
|
|
|
|
autoFocus
|
|
|
|
value={selectedTimeZone}
|
|
|
|
className="w-64 rounded-md"
|
|
|
|
onChange={(timezone) => setSelectedTimeZone(timezone.value)}
|
|
|
|
classNamePrefix="react-select"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="mt-3">
|
|
|
|
<Label>{t("slot_length")}</Label>
|
|
|
|
<Select
|
|
|
|
options={[
|
|
|
|
{ value: 15, label: "15 minutes" },
|
|
|
|
{ value: 30, label: "30 minutes" },
|
|
|
|
{ value: 60, label: "60 minutes" },
|
|
|
|
]}
|
|
|
|
isSearchable={false}
|
|
|
|
classNamePrefix="react-select"
|
|
|
|
className="w-64"
|
|
|
|
value={{ value: frequency, label: `${frequency} minutes` }}
|
|
|
|
onChange={(newFrequency) => setFrequency(newFrequency?.value ?? 30)}
|
|
|
|
/>
|
2022-05-26 17:07:14 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-04-19 14:15:08 +00:00
|
|
|
|
|
|
|
<div className="col-span-1 max-h-[500px]">
|
|
|
|
{props.team && props.member && (
|
|
|
|
<TeamAvailabilityTimes
|
|
|
|
teamId={props.team.id}
|
|
|
|
memberId={props.member.id}
|
|
|
|
frequency={frequency}
|
|
|
|
selectedDate={selectedDate}
|
|
|
|
selectedTimeZone={selectedTimeZone}
|
|
|
|
/>
|
|
|
|
)}
|
2021-12-09 23:51:30 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-04-19 14:15:08 +00:00
|
|
|
</>
|
2022-05-26 17:07:14 +00:00
|
|
|
</LicenseRequired>
|
2021-12-09 23:51:30 +00:00
|
|
|
);
|
|
|
|
}
|