Files
cal.diy/packages/features/ee/teams/components/v2/TeamAvailabilityModal.tsx
T
2f2b72dd54 Feature/date overrides (#5991)
* Initial incomplete (but mostly functional) push of date override functions

* Fixed date shifting on load

* Bring back minDate (automatically disable all dates before current date)

* Fix type error

* Supply working hours to render available dates

* Converted to SSR

* moving defaultValues to the backend

* Improv. as filter can be achieved within the reduce

Co-authored-by: Omar López <[email protected]>

* Double inversion -> single, as it is an early return

* uniq() exit - not needed anymore

* Typefixes

* It's overriding dates :D

* Fixed duplication DateOverrides in list

* Implemented changing the month

* Make dateOverrides an optional param

* Fixed test (which requires dateOverrides due to auto-typing)

* Prevent a full update on set as default from list view

* Added some extra keys to keep ts happy

* Only allow a single date override per date

* Disallow editing excludedDates to the same date

* Bring back duplicate key ?.?

Co-authored-by: Peer Richelsen <[email protected]>
Co-authored-by: zomars <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-12-14 17:30:55 +00:00

103 lines
3.6 KiB
TypeScript

import { useEffect, useState } from "react";
import dayjs from "@calcom/dayjs";
import { WEBAPP_URL } from "@calcom/lib/constants";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { RouterOutputs, trpc } from "@calcom/trpc/react";
import type { ITimezone } from "@calcom/ui";
import { Avatar, DatePickerField as DatePicker, Label, Select, TimezoneSelect } from "@calcom/ui";
import LicenseRequired from "../../../common/components/LicenseRequired";
import TeamAvailabilityTimes from "./TeamAvailabilityTimes";
interface Props {
team?: RouterOutputs["viewer"]["teams"]["get"];
member?: RouterOutputs["viewer"]["teams"]["get"]["members"][number];
}
export default function TeamAvailabilityModal(props: Props) {
const utils = trpc.useContext();
const [selectedDate, setSelectedDate] = useState(dayjs());
const [selectedTimeZone, setSelectedTimeZone] = useState<ITimezone>(
localStorage.getItem("timeOption.preferredTimeZone") || dayjs.tz.guess()
);
const { t } = useLocale();
const [frequency, setFrequency] = useState<15 | 30 | 60>(30);
useEffect(() => {
utils.viewer.teams.getMemberAvailability.invalidate();
}, [utils, selectedTimeZone, selectedDate]);
return (
<LicenseRequired>
<>
<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="ml-2 text-base font-semibold leading-4 text-gray-500">
{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)}
/>
</div>
</div>
<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}
/>
)}
</div>
</div>
</>
</LicenseRequired>
);
}