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";
|
2022-05-30 07:57:48 +00:00
|
|
|
import { WEBAPP_URL } from "@calcom/lib/constants";
|
2022-11-10 23:40:01 +00:00
|
|
|
import { RouterOutputs, trpc } from "@calcom/trpc/react";
|
2022-11-23 02:55:25 +00:00
|
|
|
import type { ITimezone } from "@calcom/ui";
|
|
|
|
import { Avatar, DatePickerField as DatePicker, Select, TimezoneSelect } from "@calcom/ui";
|
2021-12-09 23:51:30 +00:00
|
|
|
|
2022-07-28 19:58:26 +00:00
|
|
|
import LicenseRequired from "../../common/components/LicenseRequired";
|
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()
|
|
|
|
);
|
|
|
|
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>
|
|
|
|
<div className="flex max-h-[500px] min-h-[500px] flex-row space-x-8 rtl:space-x-reverse">
|
|
|
|
<div className="min-w-64 w-64 space-y-5 p-5 pr-0">
|
|
|
|
<div className="flex">
|
|
|
|
<Avatar
|
2022-07-28 19:58:26 +00:00
|
|
|
size="sm"
|
2022-05-30 07:57:48 +00:00
|
|
|
imageSrc={WEBAPP_URL + "/" + props.member?.username + "/avatar.png"}
|
2022-05-26 17:07:14 +00:00
|
|
|
alt={props.member?.name || ""}
|
|
|
|
className="h-14 w-14 rounded-full"
|
|
|
|
/>
|
|
|
|
<div className="ml-3 inline-block pt-1">
|
|
|
|
<span className="text-lg font-bold text-neutral-700">{props.member?.name}</span>
|
|
|
|
<span className="-mt-1 block text-sm text-gray-400">{props.member?.email}</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="flex flex-col">
|
|
|
|
<span className="font-bold text-gray-600">Date</span>
|
|
|
|
<DatePicker
|
|
|
|
date={selectedDate.toDate()}
|
|
|
|
onDatesChange={(newDate) => {
|
|
|
|
setSelectedDate(dayjs(newDate));
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<span className="font-bold text-gray-600">Timezone</span>
|
|
|
|
<TimezoneSelect
|
|
|
|
id="timeZone"
|
|
|
|
value={selectedTimeZone}
|
|
|
|
onChange={(timezone) => setSelectedTimeZone(timezone.value)}
|
|
|
|
classNamePrefix="react-select"
|
2022-07-27 02:24:00 +00:00
|
|
|
className="react-select-container mt-1 block w-full rounded-sm border border-gray-300 text-sm focus:border-neutral-800 focus:ring-neutral-800"
|
2022-05-26 17:07:14 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<span className="font-bold text-gray-600">Slot Length</span>
|
|
|
|
<Select
|
|
|
|
options={[
|
|
|
|
{ value: 15, label: "15 minutes" },
|
|
|
|
{ value: 30, label: "30 minutes" },
|
|
|
|
{ value: 60, label: "60 minutes" },
|
|
|
|
]}
|
|
|
|
isSearchable={false}
|
|
|
|
classNamePrefix="react-select"
|
2022-07-27 02:24:00 +00:00
|
|
|
className="react-select-container focus:ring-primary-500 focus:border-primary-500 block w-full min-w-0 flex-1 rounded-sm border border-gray-300 text-sm"
|
2022-05-26 17:07:14 +00:00
|
|
|
value={{ value: frequency, label: `${frequency} minutes` }}
|
|
|
|
onChange={(newFrequency) => setFrequency(newFrequency?.value ?? 30)}
|
|
|
|
/>
|
2021-12-09 23:51:30 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-05-26 17:07:14 +00:00
|
|
|
{props.team && props.member && (
|
|
|
|
<TeamAvailabilityTimes
|
|
|
|
className="overflow-scroll"
|
|
|
|
teamId={props.team.id}
|
|
|
|
memberId={props.member.id}
|
|
|
|
frequency={frequency}
|
|
|
|
selectedDate={selectedDate}
|
|
|
|
selectedTimeZone={selectedTimeZone}
|
2021-12-09 23:51:30 +00:00
|
|
|
/>
|
2022-05-26 17:07:14 +00:00
|
|
|
)}
|
2021-12-09 23:51:30 +00:00
|
|
|
</div>
|
2022-05-26 17:07:14 +00:00
|
|
|
</LicenseRequired>
|
2021-12-09 23:51:30 +00:00
|
|
|
);
|
|
|
|
}
|