2021-12-09 23:51:30 +00:00
|
|
|
import dayjs from "dayjs";
|
|
|
|
import utc from "dayjs/plugin/utc";
|
|
|
|
import React, { useState, useEffect } from "react";
|
|
|
|
import TimezoneSelect, { ITimezone } from "react-timezone-select";
|
|
|
|
|
|
|
|
import { getPlaceholderAvatar } from "@lib/getPlaceholderAvatar";
|
|
|
|
import { trpc, inferQueryOutput } from "@lib/trpc";
|
|
|
|
|
|
|
|
import Avatar from "@components/ui/Avatar";
|
|
|
|
import { DatePicker } from "@components/ui/form/DatePicker";
|
2021-12-17 00:16:59 +00:00
|
|
|
import Select from "@components/ui/form/Select";
|
2021-12-09 23:51:30 +00:00
|
|
|
|
|
|
|
import TeamAvailabilityTimes from "./TeamAvailabilityTimes";
|
|
|
|
|
|
|
|
dayjs.extend(utc);
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
team?: inferQueryOutput<"viewer.teams.get">;
|
|
|
|
member?: inferQueryOutput<"viewer.teams.get">["members"][number];
|
|
|
|
}
|
|
|
|
|
|
|
|
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(() => {
|
|
|
|
utils.invalidateQueries(["viewer.teams.getMemberAvailability"]);
|
|
|
|
}, [utils, selectedTimeZone, selectedDate]);
|
|
|
|
|
|
|
|
return (
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className="flex max-h-[500px] min-h-[500px] flex-row space-x-8 rtl:space-x-reverse">
|
2022-02-09 22:32:31 +00:00
|
|
|
<div className="min-w-64 w-64 space-y-5 p-5 pr-0">
|
2021-12-09 23:51:30 +00:00
|
|
|
<div className="flex">
|
|
|
|
<Avatar
|
|
|
|
imageSrc={getPlaceholderAvatar(props.member?.avatar, props.member?.name as string)}
|
|
|
|
alt={props.member?.name || ""}
|
2022-02-09 00:05:13 +00:00
|
|
|
className="h-14 w-14 rounded-full"
|
2021-12-09 23:51:30 +00:00
|
|
|
/>
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className="ml-3 inline-block pt-1">
|
2021-12-09 23:51:30 +00:00
|
|
|
<span className="text-lg font-bold text-neutral-700">{props.member?.name}</span>
|
2022-02-09 00:05:13 +00:00
|
|
|
<span className="-mt-1 block text-sm text-gray-400">{props.member?.email}</span>
|
2021-12-09 23:51:30 +00:00
|
|
|
</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)}
|
2022-04-14 14:58:23 +00:00
|
|
|
className="mt-1 block w-full rounded-sm border border-gray-300 shadow-sm sm:text-sm"
|
2021-12-09 23:51:30 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<span className="font-bold text-gray-600">Slot Length</span>
|
2021-12-17 00:16:59 +00:00
|
|
|
<Select
|
|
|
|
options={[
|
|
|
|
{ value: 15, label: "15 minutes" },
|
|
|
|
{ value: 30, label: "30 minutes" },
|
|
|
|
{ value: 60, label: "60 minutes" },
|
|
|
|
]}
|
|
|
|
isSearchable={false}
|
2022-04-14 14:58:23 +00:00
|
|
|
className="block w-full min-w-0 flex-1 rounded-sm border border-gray-300 sm:text-sm"
|
2021-12-17 00:16:59 +00:00
|
|
|
value={{ value: frequency, label: `${frequency} minutes` }}
|
|
|
|
onChange={(newFrequency) => setFrequency(newFrequency?.value ?? 30)}
|
2021-12-09 23:51:30 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{props.team && props.member && (
|
|
|
|
<TeamAvailabilityTimes
|
2022-04-19 15:50:19 +00:00
|
|
|
className="overflow-auto"
|
2021-12-17 00:16:59 +00:00
|
|
|
teamId={props.team.id}
|
|
|
|
memberId={props.member.id}
|
2021-12-09 23:51:30 +00:00
|
|
|
frequency={frequency}
|
|
|
|
selectedDate={selectedDate}
|
|
|
|
selectedTimeZone={selectedTimeZone}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|