2021-09-14 08:45:28 +00:00
|
|
|
// Get router variables
|
2022-06-15 20:54:31 +00:00
|
|
|
import { EventType } from "@prisma/client";
|
2022-08-15 19:52:01 +00:00
|
|
|
import { SchedulingType } from "@prisma/client";
|
2021-09-22 19:52:38 +00:00
|
|
|
import * as Collapsible from "@radix-ui/react-collapsible";
|
2022-05-25 20:34:08 +00:00
|
|
|
import { TFunction } from "next-i18next";
|
2021-09-22 19:52:38 +00:00
|
|
|
import { useRouter } from "next/router";
|
2022-09-05 21:10:58 +00:00
|
|
|
import { useReducer, useEffect, useMemo, useState } from "react";
|
|
|
|
import { Toaster } from "react-hot-toast";
|
2021-09-22 19:52:38 +00:00
|
|
|
import { FormattedNumber, IntlProvider } from "react-intl";
|
2022-06-27 21:01:46 +00:00
|
|
|
import { z } from "zod";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2022-06-28 20:40:58 +00:00
|
|
|
import dayjs, { Dayjs } from "@calcom/dayjs";
|
2022-04-25 04:33:00 +00:00
|
|
|
import {
|
2022-07-23 00:39:50 +00:00
|
|
|
useEmbedNonStylesConfig,
|
2022-08-05 18:44:30 +00:00
|
|
|
useEmbedStyles,
|
2022-04-25 04:33:00 +00:00
|
|
|
useIsBackgroundTransparent,
|
2022-08-05 18:44:30 +00:00
|
|
|
useIsEmbed,
|
2022-05-27 15:37:02 +00:00
|
|
|
} from "@calcom/embed-core/embed-iframe";
|
2022-07-23 00:39:50 +00:00
|
|
|
import CustomBranding from "@calcom/lib/CustomBranding";
|
2022-04-08 05:33:24 +00:00
|
|
|
import classNames from "@calcom/lib/classNames";
|
2022-08-15 19:52:01 +00:00
|
|
|
import { WEBSITE_URL } from "@calcom/lib/constants";
|
2022-04-14 21:25:24 +00:00
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
2022-07-28 19:58:26 +00:00
|
|
|
import useTheme from "@calcom/lib/hooks/useTheme";
|
2022-08-12 19:29:29 +00:00
|
|
|
import notEmpty from "@calcom/lib/notEmpty";
|
2022-06-10 20:38:06 +00:00
|
|
|
import { getRecurringFreq } from "@calcom/lib/recurringStrings";
|
2022-07-28 19:58:26 +00:00
|
|
|
import { collectPageParameters, telemetryEventTypes, useTelemetry } from "@calcom/lib/telemetry";
|
|
|
|
import { detectBrowserTimeFormat } from "@calcom/lib/timeFormat";
|
2022-05-09 18:12:47 +00:00
|
|
|
import { localStorage } from "@calcom/lib/webstorage";
|
2022-07-22 17:27:06 +00:00
|
|
|
import { trpc } from "@calcom/trpc/react";
|
2022-07-27 02:24:00 +00:00
|
|
|
import { Icon } from "@calcom/ui/Icon";
|
2022-08-24 20:18:42 +00:00
|
|
|
import DatePicker from "@calcom/ui/v2/modules/booker/DatePicker";
|
2022-04-08 05:33:24 +00:00
|
|
|
|
2022-06-27 21:01:46 +00:00
|
|
|
import { timeZone as localStorageTimeZone } from "@lib/clock";
|
|
|
|
// import { timeZone } from "@lib/clock";
|
2022-04-04 15:44:04 +00:00
|
|
|
import { useExposePlanGlobally } from "@lib/hooks/useExposePlanGlobally";
|
2021-09-22 19:52:38 +00:00
|
|
|
import { isBrandingHidden } from "@lib/isBrandingHidden";
|
|
|
|
|
2022-09-05 21:10:58 +00:00
|
|
|
import Gates, { Gate, GateState } from "@components/Gates";
|
2021-09-14 08:45:28 +00:00
|
|
|
import AvailableTimes from "@components/booking/AvailableTimes";
|
|
|
|
import TimeOptions from "@components/booking/TimeOptions";
|
2022-08-15 19:52:01 +00:00
|
|
|
import { UserAvatars } from "@components/booking/UserAvatars";
|
2022-08-05 18:44:30 +00:00
|
|
|
import EventTypeDescriptionSafeHTML from "@components/eventtype/EventTypeDescriptionSafeHTML";
|
2021-09-14 08:45:28 +00:00
|
|
|
import { HeadSeo } from "@components/seo/head-seo";
|
2021-09-26 14:04:01 +00:00
|
|
|
import PoweredByCal from "@components/ui/PoweredByCal";
|
2021-09-14 08:45:28 +00:00
|
|
|
|
2022-06-15 20:54:31 +00:00
|
|
|
import type { AvailabilityPageProps } from "../../../pages/[user]/[type]";
|
|
|
|
import type { DynamicAvailabilityPageProps } from "../../../pages/d/[link]/[slug]";
|
|
|
|
import type { AvailabilityTeamPageProps } from "../../../pages/team/[slug]/[type]";
|
2022-08-26 00:48:50 +00:00
|
|
|
import { AvailableEventLocations } from "../AvailableEventLocations";
|
2021-09-23 14:08:44 +00:00
|
|
|
|
2022-07-06 14:47:22 +00:00
|
|
|
const GoBackToPreviousPage = ({ t }: { t: TFunction }) => {
|
2021-09-14 08:45:28 +00:00
|
|
|
const router = useRouter();
|
2022-07-06 14:47:22 +00:00
|
|
|
const path = router.asPath.split("/");
|
|
|
|
path.pop(); // Remove the last item (where we currently are)
|
|
|
|
path.shift(); // Removes first item e.g. if we were visitng "/teams/test/30mins" the array will new look like ["teams","test"]
|
|
|
|
const slug = path.join("/");
|
2022-07-04 14:26:22 +00:00
|
|
|
return (
|
2022-06-15 20:54:31 +00:00
|
|
|
<div className="flex h-full flex-col justify-end">
|
2022-07-04 14:26:22 +00:00
|
|
|
<button title={t("profile")} onClick={() => router.replace(`${WEBSITE_URL}/${slug}`)}>
|
2022-08-24 20:18:42 +00:00
|
|
|
<Icon.FiArrowLeft className="dark:text-darkgray-600 h-4 w-4 text-black transition-opacity hover:cursor-pointer" />
|
2022-07-04 14:26:22 +00:00
|
|
|
<p className="sr-only">Go Back</p>
|
|
|
|
</button>
|
2022-06-15 20:54:31 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const useSlots = ({
|
|
|
|
eventTypeId,
|
2022-08-12 19:29:29 +00:00
|
|
|
eventTypeSlug,
|
2022-06-15 20:54:31 +00:00
|
|
|
startTime,
|
|
|
|
endTime,
|
2022-08-12 19:29:29 +00:00
|
|
|
usernameList,
|
2022-06-27 21:01:46 +00:00
|
|
|
timeZone,
|
2022-06-15 20:54:31 +00:00
|
|
|
}: {
|
|
|
|
eventTypeId: number;
|
2022-08-12 19:29:29 +00:00
|
|
|
eventTypeSlug: string;
|
2022-06-27 21:01:46 +00:00
|
|
|
startTime?: Dayjs;
|
|
|
|
endTime?: Dayjs;
|
2022-08-12 19:29:29 +00:00
|
|
|
usernameList: string[];
|
2022-07-14 10:28:46 +00:00
|
|
|
timeZone?: string;
|
2022-06-15 20:54:31 +00:00
|
|
|
}) => {
|
2022-07-06 14:25:41 +00:00
|
|
|
const { data, isLoading, isIdle } = trpc.useQuery(
|
2022-06-19 15:02:00 +00:00
|
|
|
[
|
|
|
|
"viewer.public.slots.getSchedule",
|
|
|
|
{
|
|
|
|
eventTypeId,
|
2022-08-12 19:29:29 +00:00
|
|
|
eventTypeSlug,
|
|
|
|
usernameList,
|
2022-06-27 21:01:46 +00:00
|
|
|
startTime: startTime?.toISOString() || "",
|
|
|
|
endTime: endTime?.toISOString() || "",
|
2022-06-29 09:01:30 +00:00
|
|
|
timeZone,
|
2022-06-19 15:02:00 +00:00
|
|
|
},
|
|
|
|
],
|
2022-06-27 21:01:46 +00:00
|
|
|
{ enabled: !!startTime && !!endTime }
|
2022-06-19 15:02:00 +00:00
|
|
|
);
|
2022-06-27 21:01:46 +00:00
|
|
|
const [cachedSlots, setCachedSlots] = useState<NonNullable<typeof data>["slots"]>({});
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (data?.slots) {
|
|
|
|
setCachedSlots((c) => ({ ...c, ...data?.slots }));
|
|
|
|
}
|
|
|
|
}, [data]);
|
|
|
|
|
2022-07-06 14:25:41 +00:00
|
|
|
// The very first time isIdle is set if auto-fetch is disabled, so isIdle should also be considered a loading state.
|
|
|
|
return { slots: cachedSlots, isLoading: isLoading || isIdle };
|
2022-06-15 20:54:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const SlotPicker = ({
|
|
|
|
eventType,
|
|
|
|
timeFormat,
|
|
|
|
timeZone,
|
|
|
|
recurringEventCount,
|
2022-08-12 19:29:29 +00:00
|
|
|
users,
|
2022-06-15 20:54:31 +00:00
|
|
|
seatsPerTimeSlot,
|
|
|
|
weekStart = 0,
|
2022-09-05 21:10:58 +00:00
|
|
|
ethSignature,
|
2022-06-15 20:54:31 +00:00
|
|
|
}: {
|
|
|
|
eventType: Pick<EventType, "id" | "schedulingType" | "slug">;
|
|
|
|
timeFormat: string;
|
2022-07-14 10:28:46 +00:00
|
|
|
timeZone?: string;
|
2022-06-15 20:54:31 +00:00
|
|
|
seatsPerTimeSlot?: number;
|
|
|
|
recurringEventCount?: number;
|
2022-08-12 19:29:29 +00:00
|
|
|
users: string[];
|
2022-06-15 20:54:31 +00:00
|
|
|
weekStart?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
2022-09-05 21:10:58 +00:00
|
|
|
ethSignature?: string;
|
2022-06-15 20:54:31 +00:00
|
|
|
}) => {
|
2022-06-27 21:01:46 +00:00
|
|
|
const [selectedDate, setSelectedDate] = useState<Dayjs>();
|
|
|
|
const [browsingDate, setBrowsingDate] = useState<Dayjs>();
|
2022-06-28 02:17:23 +00:00
|
|
|
const { date, setQuery: setDate } = useRouterQuery("date");
|
|
|
|
const { month, setQuery: setMonth } = useRouterQuery("month");
|
2022-06-27 21:01:46 +00:00
|
|
|
const router = useRouter();
|
2022-06-15 20:54:31 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
2022-06-28 02:17:23 +00:00
|
|
|
if (!router.isReady) return;
|
2022-06-27 21:01:46 +00:00
|
|
|
|
|
|
|
// Etc/GMT is not actually a timeZone, so handle this select option explicitly to prevent a hard crash.
|
|
|
|
if (timeZone === "Etc/GMT") {
|
2022-07-25 21:45:34 +00:00
|
|
|
setBrowsingDate(dayjs.utc(month).set("date", 1).set("hour", 0).set("minute", 0).set("second", 0));
|
2022-06-27 21:01:46 +00:00
|
|
|
if (date) {
|
|
|
|
setSelectedDate(dayjs.utc(date));
|
|
|
|
}
|
|
|
|
} else {
|
2022-07-25 21:45:34 +00:00
|
|
|
// Set the start of the month without shifting time like startOf() may do.
|
|
|
|
setBrowsingDate(
|
|
|
|
dayjs.tz(month, timeZone).set("date", 1).set("hour", 0).set("minute", 0).set("second", 0)
|
|
|
|
);
|
2022-06-27 21:01:46 +00:00
|
|
|
if (date) {
|
2022-07-25 21:45:34 +00:00
|
|
|
// It's important to set the date immediately to the timeZone, dayjs(date) will convert to browsertime.
|
|
|
|
setSelectedDate(dayjs.tz(date, timeZone));
|
2022-06-27 21:01:46 +00:00
|
|
|
}
|
2022-02-03 23:23:20 +00:00
|
|
|
}
|
2022-06-28 02:17:23 +00:00
|
|
|
}, [router.isReady, month, date, timeZone]);
|
2022-06-15 20:54:31 +00:00
|
|
|
|
2022-06-27 21:01:46 +00:00
|
|
|
const { i18n, isLocaleReady } = useLocale();
|
|
|
|
const { slots: _1 } = useSlots({
|
|
|
|
eventTypeId: eventType.id,
|
2022-08-12 19:29:29 +00:00
|
|
|
eventTypeSlug: eventType.slug,
|
|
|
|
usernameList: users,
|
2022-06-28 22:53:14 +00:00
|
|
|
startTime: selectedDate?.startOf("day"),
|
|
|
|
endTime: selectedDate?.endOf("day"),
|
2022-06-27 21:01:46 +00:00
|
|
|
timeZone,
|
|
|
|
});
|
|
|
|
const { slots: _2, isLoading } = useSlots({
|
2022-06-15 20:54:31 +00:00
|
|
|
eventTypeId: eventType.id,
|
2022-08-12 19:29:29 +00:00
|
|
|
eventTypeSlug: eventType.slug,
|
|
|
|
usernameList: users,
|
2022-06-27 21:01:46 +00:00
|
|
|
startTime: browsingDate?.startOf("month"),
|
|
|
|
endTime: browsingDate?.endOf("month"),
|
|
|
|
timeZone,
|
2022-06-15 20:54:31 +00:00
|
|
|
});
|
2022-02-03 23:23:20 +00:00
|
|
|
|
2022-09-14 17:32:52 +00:00
|
|
|
const slots = useMemo(() => ({ ..._2, ..._1 }), [_1, _2]);
|
2022-06-27 21:01:46 +00:00
|
|
|
|
2022-06-15 20:54:31 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<DatePicker
|
|
|
|
isLoading={isLoading}
|
2022-07-14 10:28:46 +00:00
|
|
|
className={classNames(
|
2022-08-30 13:47:43 +00:00
|
|
|
"mt-8 w-full px-4 sm:mt-0 sm:min-w-[455px] md:px-5",
|
2022-08-05 08:46:44 +00:00
|
|
|
selectedDate
|
2022-09-14 17:32:52 +00:00
|
|
|
? "sm:dark:border-darkgray-200 border-gray-200 sm:w-1/2 sm:border-r sm:p-4 sm:pr-6 md:w-1/3"
|
2022-08-05 08:46:44 +00:00
|
|
|
: "sm:p-4"
|
2022-07-14 10:28:46 +00:00
|
|
|
)}
|
2022-06-15 20:54:31 +00:00
|
|
|
includedDates={Object.keys(slots).filter((k) => slots[k].length > 0)}
|
2022-06-19 15:02:00 +00:00
|
|
|
locale={isLocaleReady ? i18n.language : "en"}
|
2022-06-15 20:54:31 +00:00
|
|
|
selected={selectedDate}
|
2022-06-28 02:17:23 +00:00
|
|
|
onChange={(newDate) => {
|
|
|
|
setDate(newDate.format("YYYY-MM-DD"));
|
2022-06-27 21:01:46 +00:00
|
|
|
}}
|
2022-06-28 02:17:23 +00:00
|
|
|
onMonthChange={(newMonth) => {
|
|
|
|
setMonth(newMonth.format("YYYY-MM"));
|
2022-06-19 15:02:00 +00:00
|
|
|
}}
|
2022-06-27 21:01:46 +00:00
|
|
|
browsingDate={browsingDate}
|
2022-06-15 20:54:31 +00:00
|
|
|
weekStart={weekStart}
|
|
|
|
/>
|
|
|
|
|
|
|
|
{selectedDate && (
|
|
|
|
<AvailableTimes
|
2022-06-27 21:01:46 +00:00
|
|
|
isLoading={isLoading}
|
2022-06-29 09:01:30 +00:00
|
|
|
slots={slots[selectedDate.format("YYYY-MM-DD")]}
|
2022-06-27 21:01:46 +00:00
|
|
|
date={selectedDate}
|
2022-06-15 20:54:31 +00:00
|
|
|
timeFormat={timeFormat}
|
|
|
|
eventTypeId={eventType.id}
|
|
|
|
eventTypeSlug={eventType.slug}
|
|
|
|
seatsPerTimeSlot={seatsPerTimeSlot}
|
|
|
|
recurringCount={recurringEventCount}
|
2022-09-05 21:10:58 +00:00
|
|
|
ethSignature={ethSignature}
|
2022-06-15 20:54:31 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
function TimezoneDropdown({
|
|
|
|
onChangeTimeFormat,
|
|
|
|
onChangeTimeZone,
|
2022-06-27 21:01:46 +00:00
|
|
|
timeZone,
|
2022-07-26 18:02:44 +00:00
|
|
|
timeFormat,
|
2022-06-15 20:54:31 +00:00
|
|
|
}: {
|
|
|
|
onChangeTimeFormat: (newTimeFormat: string) => void;
|
|
|
|
onChangeTimeZone: (newTimeZone: string) => void;
|
2022-06-27 21:01:46 +00:00
|
|
|
timeZone?: string;
|
2022-07-26 18:02:44 +00:00
|
|
|
timeFormat: string;
|
2022-06-15 20:54:31 +00:00
|
|
|
}) {
|
|
|
|
const [isTimeOptionsOpen, setIsTimeOptionsOpen] = useState(false);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
handleToggle24hClock(localStorage.getItem("timeOption.is24hClock") === "true");
|
2022-07-26 18:02:44 +00:00
|
|
|
|
2022-06-15 20:54:31 +00:00
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
const handleSelectTimeZone = (newTimeZone: string) => {
|
|
|
|
onChangeTimeZone(newTimeZone);
|
2022-06-27 21:01:46 +00:00
|
|
|
localStorageTimeZone(newTimeZone);
|
2022-06-15 20:54:31 +00:00
|
|
|
setIsTimeOptionsOpen(false);
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleToggle24hClock = (is24hClock: boolean) => {
|
|
|
|
onChangeTimeFormat(is24hClock ? "HH:mm" : "h:mma");
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2022-08-29 16:01:45 +00:00
|
|
|
<Collapsible.Root open={isTimeOptionsOpen} onOpenChange={setIsTimeOptionsOpen} className="flex">
|
2022-09-01 09:22:49 +00:00
|
|
|
<Collapsible.Trigger className="min-w-32 dark:text-darkgray-600 mb-2 -ml-2 px-2 text-left text-gray-600">
|
2022-08-29 16:01:45 +00:00
|
|
|
<p className="text-sm font-medium">
|
|
|
|
<Icon.FiGlobe className="mr-[10px] ml-[2px] -mt-[2px] inline-block h-4 w-4" />
|
2022-07-06 14:25:41 +00:00
|
|
|
{timeZone}
|
2022-07-01 11:28:17 +00:00
|
|
|
{isTimeOptionsOpen ? (
|
2022-09-14 17:32:52 +00:00
|
|
|
<Icon.FiChevronUp className="ml-1 inline-block h-4 w-4" />
|
2022-07-01 11:28:17 +00:00
|
|
|
) : (
|
2022-09-14 17:32:52 +00:00
|
|
|
<Icon.FiChevronDown className="ml-1 inline-block h-4 w-4" />
|
2022-07-01 11:28:17 +00:00
|
|
|
)}
|
|
|
|
</p>
|
2022-06-15 20:54:31 +00:00
|
|
|
</Collapsible.Trigger>
|
|
|
|
<Collapsible.Content>
|
2022-07-26 18:02:44 +00:00
|
|
|
<TimeOptions
|
|
|
|
onSelectTimeZone={handleSelectTimeZone}
|
|
|
|
onToggle24hClock={handleToggle24hClock}
|
|
|
|
timeFormat={timeFormat}
|
|
|
|
/>
|
2022-06-15 20:54:31 +00:00
|
|
|
</Collapsible.Content>
|
|
|
|
</Collapsible.Root>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-06-27 21:01:46 +00:00
|
|
|
const dateQuerySchema = z.object({
|
|
|
|
rescheduleUid: z.string().optional().default(""),
|
|
|
|
date: z.string().optional().default(""),
|
|
|
|
timeZone: z.string().optional().default(""),
|
|
|
|
});
|
2022-06-15 20:54:31 +00:00
|
|
|
|
2022-06-28 02:17:23 +00:00
|
|
|
const useRouterQuery = <T extends string>(name: T) => {
|
|
|
|
const router = useRouter();
|
2022-08-05 17:08:47 +00:00
|
|
|
const existingQueryParams = router.asPath.split("?")[1];
|
|
|
|
|
|
|
|
const urlParams = new URLSearchParams(existingQueryParams);
|
|
|
|
const query = Object.fromEntries(urlParams);
|
2022-06-28 02:17:23 +00:00
|
|
|
|
|
|
|
const setQuery = (newValue: string | number | null | undefined) => {
|
|
|
|
router.replace({ query: { ...router.query, [name]: newValue } }, undefined, { shallow: true });
|
2022-08-05 17:08:47 +00:00
|
|
|
router.replace({ query: { ...router.query, ...query, [name]: newValue } }, undefined, { shallow: true });
|
2022-06-28 02:17:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return { [name]: query[name], setQuery } as {
|
|
|
|
[K in T]: string | undefined;
|
|
|
|
} & { setQuery: typeof setQuery };
|
|
|
|
};
|
|
|
|
|
2022-09-05 21:10:58 +00:00
|
|
|
export type Props = AvailabilityTeamPageProps | AvailabilityPageProps | DynamicAvailabilityPageProps;
|
|
|
|
|
2022-06-15 20:54:31 +00:00
|
|
|
const AvailabilityPage = ({ profile, eventType }: Props) => {
|
|
|
|
const router = useRouter();
|
|
|
|
const isEmbed = useIsEmbed();
|
2022-06-27 21:01:46 +00:00
|
|
|
const query = dateQuerySchema.parse(router.query);
|
|
|
|
const { rescheduleUid } = query;
|
2022-07-26 08:27:57 +00:00
|
|
|
useTheme(profile.theme);
|
2022-06-16 02:07:07 +00:00
|
|
|
const { t } = useLocale();
|
2022-06-15 20:54:31 +00:00
|
|
|
const availabilityDatePickerEmbedStyles = useEmbedStyles("availabilityDatePicker");
|
|
|
|
const shouldAlignCentrallyInEmbed = useEmbedNonStylesConfig("align") !== "left";
|
|
|
|
const shouldAlignCentrally = !isEmbed || shouldAlignCentrallyInEmbed;
|
|
|
|
const isBackgroundTransparent = useIsBackgroundTransparent();
|
|
|
|
|
|
|
|
const [timeZone, setTimeZone] = useState<string>();
|
2022-02-23 12:37:15 +00:00
|
|
|
const [timeFormat, setTimeFormat] = useState(detectBrowserTimeFormat);
|
2022-06-15 20:54:31 +00:00
|
|
|
const [isAvailableTimesVisible, setIsAvailableTimesVisible] = useState<boolean>();
|
2022-09-05 21:10:58 +00:00
|
|
|
const [gateState, gateDispatcher] = useReducer(
|
|
|
|
(state: GateState, newState: Partial<GateState>) => ({
|
|
|
|
...state,
|
|
|
|
...newState,
|
|
|
|
}),
|
|
|
|
{}
|
|
|
|
);
|
2022-02-23 12:37:15 +00:00
|
|
|
|
2022-06-15 20:54:31 +00:00
|
|
|
useEffect(() => {
|
2022-06-27 21:01:46 +00:00
|
|
|
setTimeZone(localStorageTimeZone() || dayjs.tz.guess());
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
setIsAvailableTimesVisible(!!query.date);
|
|
|
|
}, [query.date]);
|
2022-06-15 20:54:31 +00:00
|
|
|
|
|
|
|
// TODO: Improve this;
|
|
|
|
useExposePlanGlobally(eventType.users.length === 1 ? eventType.users[0].plan : "PRO");
|
2021-09-14 08:45:28 +00:00
|
|
|
|
2022-06-15 20:54:31 +00:00
|
|
|
const [recurringEventCount, setRecurringEventCount] = useState(eventType.recurringEvent?.count);
|
2022-02-23 12:37:15 +00:00
|
|
|
|
2022-06-15 20:54:31 +00:00
|
|
|
const telemetry = useTelemetry();
|
|
|
|
useEffect(() => {
|
2022-06-02 16:19:01 +00:00
|
|
|
if (top !== window) {
|
|
|
|
//page_view will be collected automatically by _middleware.ts
|
|
|
|
telemetry.event(
|
|
|
|
telemetryEventTypes.embedView,
|
2022-05-11 05:14:08 +00:00
|
|
|
collectPageParameters("/availability", { isTeamBooking: document.URL.includes("team/") })
|
2022-06-02 16:19:01 +00:00
|
|
|
);
|
|
|
|
}
|
2021-09-14 08:45:28 +00:00
|
|
|
}, [telemetry]);
|
|
|
|
|
2022-08-12 19:29:29 +00:00
|
|
|
// get dynamic user list here
|
2022-09-05 21:10:58 +00:00
|
|
|
const userList = eventType.users ? eventType.users.map((user) => user.username).filter(notEmpty) : [];
|
2022-05-05 21:16:25 +00:00
|
|
|
// Recurring event sidebar requires more space
|
2022-06-15 20:54:31 +00:00
|
|
|
const maxWidth = isAvailableTimesVisible
|
2022-05-05 21:16:25 +00:00
|
|
|
? recurringEventCount
|
|
|
|
? "max-w-6xl"
|
|
|
|
: "max-w-5xl"
|
|
|
|
: recurringEventCount
|
|
|
|
? "max-w-4xl"
|
|
|
|
: "max-w-3xl";
|
2022-06-27 21:01:46 +00:00
|
|
|
const timezoneDropdown = useMemo(
|
|
|
|
() => (
|
|
|
|
<TimezoneDropdown
|
2022-07-26 18:02:44 +00:00
|
|
|
timeFormat={timeFormat}
|
2022-06-27 21:01:46 +00:00
|
|
|
onChangeTimeFormat={setTimeFormat}
|
|
|
|
timeZone={timeZone}
|
|
|
|
onChangeTimeZone={setTimeZone}
|
|
|
|
/>
|
|
|
|
),
|
2022-08-12 19:29:29 +00:00
|
|
|
[timeZone, timeFormat]
|
2022-06-15 20:54:31 +00:00
|
|
|
);
|
2022-07-15 16:54:14 +00:00
|
|
|
const rawSlug = profile.slug ? profile.slug.split("/") : [];
|
|
|
|
if (rawSlug.length > 1) rawSlug.pop(); //team events have team name as slug, but user events have [user]/[type] as slug.
|
|
|
|
const slug = rawSlug.join("/");
|
2022-06-15 20:54:31 +00:00
|
|
|
|
2022-09-05 21:10:58 +00:00
|
|
|
// Define conditional gates here
|
|
|
|
const gates = [
|
|
|
|
// Rainbow gate is only added if the event has both a `blockchainId` and a `smartContractAddress`
|
|
|
|
eventType.metadata && eventType.metadata.blockchainId && eventType.metadata.smartContractAddress
|
|
|
|
? ("rainbow" as Gate)
|
|
|
|
: undefined,
|
|
|
|
];
|
|
|
|
|
2021-09-14 08:45:28 +00:00
|
|
|
return (
|
2022-09-05 21:10:58 +00:00
|
|
|
<Gates gates={gates} metadata={eventType.metadata} dispatch={gateDispatcher}>
|
2021-09-24 22:11:30 +00:00
|
|
|
<HeadSeo
|
2021-10-08 11:43:48 +00:00
|
|
|
title={`${rescheduleUid ? t("reschedule") : ""} ${eventType.title} | ${profile.name}`}
|
|
|
|
description={`${rescheduleUid ? t("reschedule") : ""} ${eventType.title}`}
|
2021-11-18 01:03:19 +00:00
|
|
|
name={profile.name || undefined}
|
2022-07-15 16:54:14 +00:00
|
|
|
username={slug || undefined}
|
2022-07-26 00:17:15 +00:00
|
|
|
nextSeoProps={{
|
|
|
|
nofollow: eventType.hidden,
|
|
|
|
noindex: eventType.hidden,
|
|
|
|
}}
|
2021-09-24 22:11:30 +00:00
|
|
|
/>
|
2022-03-05 15:37:46 +00:00
|
|
|
<CustomBranding lightVal={profile.brandColor} darkVal={profile.darkBrandColor} />
|
2021-09-24 22:11:30 +00:00
|
|
|
<div>
|
|
|
|
<main
|
2022-04-25 04:33:00 +00:00
|
|
|
className={classNames(
|
|
|
|
shouldAlignCentrally ? "mx-auto" : "",
|
2022-04-08 05:33:24 +00:00
|
|
|
isEmbed
|
2022-05-05 21:16:25 +00:00
|
|
|
? classNames(maxWidth)
|
2022-08-29 16:01:45 +00:00
|
|
|
: classNames("transition-max-width mx-auto my-0 duration-500 ease-in-out md:my-24", maxWidth)
|
2022-04-25 04:33:00 +00:00
|
|
|
)}>
|
2022-06-16 02:07:07 +00:00
|
|
|
<div
|
|
|
|
style={availabilityDatePickerEmbedStyles}
|
|
|
|
className={classNames(
|
2022-08-30 08:56:30 +00:00
|
|
|
isBackgroundTransparent ? "" : "dark:bg-darkgray-100 sm:dark:border-darkgray-300 bg-white",
|
2022-09-07 07:26:22 +00:00
|
|
|
"border-bookinglightest overflow-hidden rounded-md md:border",
|
2022-06-16 02:07:07 +00:00
|
|
|
isEmbed ? "mx-auto" : maxWidth
|
|
|
|
)}>
|
|
|
|
{/* mobile: details */}
|
2022-06-23 18:36:23 +00:00
|
|
|
<div className="block px-4 pt-4 sm:p-8 md:hidden">
|
2022-06-16 02:07:07 +00:00
|
|
|
<div>
|
2022-08-30 13:47:43 +00:00
|
|
|
<UserAvatars
|
|
|
|
profile={profile}
|
|
|
|
users={eventType.users}
|
|
|
|
showMembers={eventType.schedulingType !== SchedulingType.ROUND_ROBIN}
|
|
|
|
size={9}
|
|
|
|
truncateAfter={5}
|
|
|
|
/>
|
2022-08-30 08:56:30 +00:00
|
|
|
<div className="mt-4">
|
2022-08-24 20:18:42 +00:00
|
|
|
<div className="dark:text-darkgray-900 mt-2 gap-2">
|
2022-08-30 13:47:43 +00:00
|
|
|
<p className="break-words text-sm font-medium text-gray-600 dark:text-gray-300">
|
|
|
|
{profile.name}
|
|
|
|
</p>
|
2022-08-24 20:18:42 +00:00
|
|
|
<h1 className="text-bookingdark dark:text-darkgray-900 mb-4 break-words text-xl font-semibold">
|
2022-06-16 02:07:07 +00:00
|
|
|
{eventType.title}
|
|
|
|
</h1>
|
2022-08-30 11:51:08 +00:00
|
|
|
<div className="flex flex-col space-y-3">
|
2022-06-16 02:07:07 +00:00
|
|
|
{eventType?.description && (
|
2022-09-01 09:22:49 +00:00
|
|
|
<div className="dark:text-darkgray-600 flex py-1 text-sm font-medium text-gray-600">
|
2022-08-05 18:44:30 +00:00
|
|
|
<div>
|
2022-08-29 16:01:45 +00:00
|
|
|
<Icon.FiInfo className="mr-[10px] ml-[2px] inline-block h-4 w-4" />
|
2022-08-05 18:44:30 +00:00
|
|
|
</div>
|
|
|
|
<EventTypeDescriptionSafeHTML eventType={eventType} />
|
|
|
|
</div>
|
2022-06-16 02:07:07 +00:00
|
|
|
)}
|
|
|
|
{eventType?.requiresConfirmation && (
|
2022-09-14 17:32:52 +00:00
|
|
|
<p className="dark:text-darkgray-600 text-gray-600">
|
2022-08-29 16:01:45 +00:00
|
|
|
<Icon.FiCheckSquare className="mr-[10px] ml-[2px] -mt-1 inline-block h-4 w-4" />
|
2022-06-16 02:07:07 +00:00
|
|
|
{t("requires_confirmation")}
|
|
|
|
</p>
|
|
|
|
)}
|
2022-08-26 00:48:50 +00:00
|
|
|
<AvailableEventLocations locations={eventType.locations} />
|
2022-09-01 09:22:49 +00:00
|
|
|
<p className="dark:text-darkgray-600 text-gray-600">
|
2022-08-29 16:01:45 +00:00
|
|
|
<Icon.FiClock className="mr-[10px] -mt-1 ml-[2px] inline-block h-4 w-4" />
|
2022-06-16 02:07:07 +00:00
|
|
|
{eventType.length} {t("minutes")}
|
|
|
|
</p>
|
|
|
|
{eventType.price > 0 && (
|
2022-09-01 09:22:49 +00:00
|
|
|
<div className="dark:text-darkgray-600 text-gray-600">
|
2022-08-29 16:01:45 +00:00
|
|
|
<Icon.FiCreditCard className="mr-[10px] ml-[2px] -mt-1 inline-block h-4 w-4" />
|
2022-06-16 02:07:07 +00:00
|
|
|
<IntlProvider locale="en">
|
|
|
|
<FormattedNumber
|
|
|
|
value={eventType.price / 100.0}
|
|
|
|
style="currency"
|
|
|
|
currency={eventType.currency.toUpperCase()}
|
|
|
|
/>
|
|
|
|
</IntlProvider>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{!rescheduleUid && eventType.recurringEvent && (
|
2022-08-24 20:18:42 +00:00
|
|
|
<div className="dark:text-darkgray-600 flex items-center text-gray-600">
|
2022-08-15 19:35:48 +00:00
|
|
|
<Icon.FiRefreshCcw className="float-left mr-[10px] mt-1 ml-[2px] inline-block h-4 w-4 shrink-0 text-gray-500" />
|
|
|
|
<div>
|
2022-06-16 02:07:07 +00:00
|
|
|
<p className="mb-1 -ml-2 inline px-2 py-1">
|
|
|
|
{getRecurringFreq({ t, recurringEvent: eventType.recurringEvent })}
|
|
|
|
</p>
|
|
|
|
<input
|
|
|
|
type="number"
|
|
|
|
min="1"
|
|
|
|
max={eventType.recurringEvent.count}
|
2022-08-24 20:18:42 +00:00
|
|
|
className="w-15 dark:text-darkgray-600 h-7 rounded-sm border-gray-300 bg-white text-sm text-gray-600 [appearance:textfield] ltr:mr-2 rtl:ml-2 dark:border-gray-500 dark:bg-gray-600"
|
2022-06-16 02:07:07 +00:00
|
|
|
defaultValue={eventType.recurringEvent.count}
|
|
|
|
onChange={(event) => {
|
|
|
|
setRecurringEventCount(parseInt(event?.target.value));
|
|
|
|
}}
|
|
|
|
/>
|
2022-09-14 17:32:52 +00:00
|
|
|
<p className="dark:text-darkgray-600 inline text-gray-600">
|
2022-06-16 02:07:07 +00:00
|
|
|
{t("occurrence", {
|
|
|
|
count: recurringEventCount,
|
|
|
|
})}
|
|
|
|
</p>
|
2022-06-09 20:49:09 +00:00
|
|
|
</div>
|
2022-06-16 02:07:07 +00:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{timezoneDropdown}
|
2022-06-08 07:11:34 +00:00
|
|
|
|
2022-06-16 02:07:07 +00:00
|
|
|
<div className="md:hidden">
|
|
|
|
{/* Temp disabled booking?.startTime && rescheduleUid && (
|
2022-06-01 12:58:46 +00:00
|
|
|
<div>
|
|
|
|
<p
|
2022-08-24 20:18:42 +00:00
|
|
|
className="mt-8 text-gray-600 dark:text-darkgray-600"
|
2022-06-01 12:58:46 +00:00
|
|
|
data-testid="former_time_p_mobile">
|
|
|
|
{t("former_time")}
|
|
|
|
</p>
|
2022-08-24 20:18:42 +00:00
|
|
|
<p className="text-gray-500 line-through dark:text-darkgray-600">
|
2022-08-05 08:46:44 +00:00
|
|
|
<CalendarIcon className="mr-[10px] -mt-1 inline-block h-4 w-4 text-gray-500" />
|
2022-06-01 12:58:46 +00:00
|
|
|
{typeof booking.startTime === "string" &&
|
|
|
|
parseDate(dayjs(booking.startTime), i18n)}
|
|
|
|
</p>
|
|
|
|
</div>
|
2022-06-15 20:54:31 +00:00
|
|
|
)*/}
|
2022-04-17 11:25:11 +00:00
|
|
|
</div>
|
2021-09-14 08:45:28 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-06-16 02:07:07 +00:00
|
|
|
</div>
|
2021-09-14 08:45:28 +00:00
|
|
|
|
2022-08-05 08:46:44 +00:00
|
|
|
<div className="overflow-hidden sm:flex">
|
2022-06-16 02:07:07 +00:00
|
|
|
<div
|
|
|
|
className={
|
2022-08-24 20:18:42 +00:00
|
|
|
"sm:dark:border-darkgray-200 hidden overflow-hidden border-gray-200 p-5 sm:border-r md:flex md:flex-col " +
|
2022-06-16 02:07:07 +00:00
|
|
|
(isAvailableTimesVisible ? "sm:w-1/3" : recurringEventCount ? "sm:w-2/3" : "sm:w-1/2")
|
|
|
|
}>
|
2022-08-30 13:47:43 +00:00
|
|
|
<UserAvatars
|
|
|
|
profile={profile}
|
|
|
|
users={eventType.users}
|
|
|
|
showMembers={eventType.schedulingType !== SchedulingType.ROUND_ROBIN}
|
|
|
|
size={10}
|
|
|
|
truncateAfter={3}
|
|
|
|
/>
|
|
|
|
<h2 className="break-words text-sm font-medium text-gray-600 dark:text-gray-300 lg:mt-2">
|
|
|
|
{profile.name}
|
|
|
|
</h2>
|
2022-09-14 17:32:52 +00:00
|
|
|
<h1 className="font-cal dark:text-darkgray-900 mb-6 break-words text-2xl text-gray-900">
|
2022-06-16 02:07:07 +00:00
|
|
|
{eventType.title}
|
|
|
|
</h1>
|
2022-09-01 09:22:49 +00:00
|
|
|
<div className="dark:text-darkgray-600 flex flex-col space-y-3 text-sm font-medium text-gray-600">
|
2022-06-16 02:07:07 +00:00
|
|
|
{eventType?.description && (
|
2022-09-14 17:32:52 +00:00
|
|
|
<div className="flex">
|
2022-06-16 02:07:07 +00:00
|
|
|
<div>
|
2022-08-29 16:01:45 +00:00
|
|
|
<Icon.FiInfo className="mr-[10px] ml-[2px] inline-block h-4 w-4" />
|
2022-06-01 12:58:46 +00:00
|
|
|
</div>
|
2022-08-05 18:44:30 +00:00
|
|
|
<EventTypeDescriptionSafeHTML eventType={eventType} />
|
2022-06-16 02:07:07 +00:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{eventType?.requiresConfirmation && (
|
2022-08-30 08:56:30 +00:00
|
|
|
<div className="flex items-center">
|
2022-06-16 02:07:07 +00:00
|
|
|
<div>
|
2022-08-24 20:18:42 +00:00
|
|
|
<Icon.FiCheckSquare className="mr-[10px] ml-[2px] -mt-1 inline-block h-4 w-4 " />
|
2022-06-10 23:32:54 +00:00
|
|
|
</div>
|
2022-06-16 02:07:07 +00:00
|
|
|
{t("requires_confirmation")}
|
|
|
|
</div>
|
|
|
|
)}
|
2022-08-26 00:48:50 +00:00
|
|
|
<AvailableEventLocations locations={eventType.locations} />
|
2022-08-30 08:56:30 +00:00
|
|
|
<p className="text-sm font-medium">
|
2022-08-29 16:01:45 +00:00
|
|
|
<Icon.FiClock className="mr-[10px] -mt-1 ml-[2px] inline-block h-4 w-4" />
|
2022-06-16 02:07:07 +00:00
|
|
|
{eventType.length} {t("minutes")}
|
|
|
|
</p>
|
|
|
|
{!rescheduleUid && eventType.recurringEvent && (
|
2022-08-30 08:56:30 +00:00
|
|
|
<div className="flex items-start text-sm font-medium">
|
2022-08-29 16:01:45 +00:00
|
|
|
<Icon.FiRefreshCcw className="float-left mr-[10px] mt-[7px] ml-[2px] inline-block h-4 w-4 " />
|
2022-08-15 19:35:48 +00:00
|
|
|
<div>
|
2022-06-16 02:07:07 +00:00
|
|
|
<p className="mb-1 -ml-2 inline px-2 py-1">
|
|
|
|
{getRecurringFreq({ t, recurringEvent: eventType.recurringEvent })}
|
|
|
|
</p>
|
|
|
|
<input
|
|
|
|
type="number"
|
|
|
|
min="1"
|
|
|
|
max={eventType.recurringEvent.count}
|
2022-08-29 16:01:45 +00:00
|
|
|
className="w-15 dark:bg-darkgray-200 h-7 rounded-sm border-gray-300 bg-white text-sm font-medium [appearance:textfield] ltr:mr-2 rtl:ml-2 dark:border-gray-500"
|
2022-06-16 02:07:07 +00:00
|
|
|
defaultValue={eventType.recurringEvent.count}
|
|
|
|
onChange={(event) => {
|
|
|
|
setRecurringEventCount(parseInt(event?.target.value));
|
|
|
|
}}
|
|
|
|
/>
|
2022-08-29 16:01:45 +00:00
|
|
|
<p className="inline">
|
2022-06-16 02:07:07 +00:00
|
|
|
{t("occurrence", {
|
|
|
|
count: recurringEventCount,
|
2022-06-01 12:58:46 +00:00
|
|
|
})}
|
|
|
|
</p>
|
|
|
|
</div>
|
2022-06-16 02:07:07 +00:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{eventType.price > 0 && (
|
2022-09-14 17:32:52 +00:00
|
|
|
<p className="-ml-2 px-2 text-sm font-medium">
|
2022-08-24 20:18:42 +00:00
|
|
|
<Icon.FiCreditCard className="mr-[10px] ml-[2px] -mt-1 inline-block h-4 w-4" />
|
2022-06-16 02:07:07 +00:00
|
|
|
<IntlProvider locale="en">
|
|
|
|
<FormattedNumber
|
|
|
|
value={eventType.price / 100.0}
|
|
|
|
style="currency"
|
|
|
|
currency={eventType.currency.toUpperCase()}
|
|
|
|
/>
|
|
|
|
</IntlProvider>
|
2022-05-25 20:34:08 +00:00
|
|
|
</p>
|
2022-06-16 02:07:07 +00:00
|
|
|
)}
|
|
|
|
{timezoneDropdown}
|
|
|
|
</div>
|
2022-06-01 12:58:46 +00:00
|
|
|
|
2022-07-12 14:33:12 +00:00
|
|
|
{!isEmbed && <GoBackToPreviousPage t={t} />}
|
2022-06-15 20:54:31 +00:00
|
|
|
|
2022-06-16 02:07:07 +00:00
|
|
|
{/* Temporarily disabled - booking?.startTime && rescheduleUid && (
|
2022-04-14 21:25:24 +00:00
|
|
|
<div>
|
2022-04-18 10:25:56 +00:00
|
|
|
<p
|
2022-08-24 20:18:42 +00:00
|
|
|
className="mt-4 mb-3 text-gray-600 dark:text-darkgray-600"
|
2022-04-18 10:25:56 +00:00
|
|
|
data-testid="former_time_p_desktop">
|
2022-04-14 21:25:24 +00:00
|
|
|
{t("former_time")}
|
|
|
|
</p>
|
2022-08-24 20:18:42 +00:00
|
|
|
<p className="text-gray-500 line-through dark:text-darkgray-600">
|
2022-08-05 08:46:44 +00:00
|
|
|
<CalendarIcon className="mr-[10px] -mt-1 inline-block h-4 w-4 text-gray-500" />
|
2022-04-14 21:25:24 +00:00
|
|
|
{typeof booking.startTime === "string" && parseDate(dayjs(booking.startTime), i18n)}
|
|
|
|
</p>
|
|
|
|
</div>
|
2022-06-15 20:54:31 +00:00
|
|
|
)*/}
|
2021-09-14 08:45:28 +00:00
|
|
|
</div>
|
2022-07-14 10:28:46 +00:00
|
|
|
<SlotPicker
|
|
|
|
weekStart={
|
|
|
|
typeof profile.weekStart === "string"
|
|
|
|
? (["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"].indexOf(
|
|
|
|
profile.weekStart
|
|
|
|
) as 0 | 1 | 2 | 3 | 4 | 5 | 6)
|
|
|
|
: profile.weekStart /* Allows providing weekStart as number */
|
|
|
|
}
|
|
|
|
eventType={eventType}
|
|
|
|
timeFormat={timeFormat}
|
|
|
|
timeZone={timeZone}
|
2022-08-12 19:29:29 +00:00
|
|
|
users={userList}
|
2022-07-14 10:28:46 +00:00
|
|
|
seatsPerTimeSlot={eventType.seatsPerTimeSlot || undefined}
|
|
|
|
recurringEventCount={recurringEventCount}
|
2022-09-05 21:10:58 +00:00
|
|
|
ethSignature={gateState.rainbowToken}
|
2022-07-14 10:28:46 +00:00
|
|
|
/>
|
2021-09-14 08:45:28 +00:00
|
|
|
</div>
|
2022-06-16 02:07:07 +00:00
|
|
|
</div>
|
2022-04-08 05:33:24 +00:00
|
|
|
{(!eventType.users[0] || !isBrandingHidden(eventType.users[0])) && !isEmbed && <PoweredByCal />}
|
2021-09-24 22:11:30 +00:00
|
|
|
</main>
|
|
|
|
</div>
|
2022-09-05 21:10:58 +00:00
|
|
|
<Toaster position="bottom-right" />
|
|
|
|
</Gates>
|
2021-09-14 08:45:28 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default AvailabilityPage;
|