Skip to content

Scheduling infrastructure for absolutely everyone.

Feat/improve animation on public booking page (#4848)

Jeroen Reumkens1b15b71a24df
diff --git a/apps/web/components/booking/AvailableTimes.tsx b/apps/web/components/booking/AvailableTimes.tsx
index 03904f3d102..1a8d73185a7 100644
--- a/apps/web/components/booking/AvailableTimes.tsx
+++ b/apps/web/components/booking/AvailableTimes.tsx
@@ -16,7 +16,7 @@ type AvailableTimesProps = {
eventTypeId: number;
recurringCount: number | undefined;
eventTypeSlug: string;
- date: Dayjs;
+ date?: Dayjs;
seatsPerTimeSlot?: number | null;
slots?: Slot[];
isLoading: boolean;
@@ -44,8 +44,10 @@ const AvailableTimes: FC<AvailableTimesProps> = ({
setBrand(getComputedStyle(document.documentElement).getPropertyValue("--brand-color").trim());
}, []);
+ if (!date) return null;
+
return (
- <div className="dark:bg-darkgray-100 mt-8 flex flex-col px-4 text-center sm:mt-0 sm:w-1/3 sm:p-5 md:-mb-5">
+ <div className="dark:bg-darkgray-100 mt-8 flex h-full w-full flex-col px-4 text-center sm:mt-0 sm:p-5 md:-mb-5 md:min-w-[200px] lg:min-w-[300px]">
<div className="mb-4 text-left text-base">
<span className="text-bookingdarker dark:text-darkgray-800 mb-8 w-1/2 break-words font-semibold text-gray-900">
{nameOfDay(i18n.language, Number(date.format("d")))}
@@ -150,4 +152,6 @@ const AvailableTimes: FC<AvailableTimesProps> = ({
);
};
+AvailableTimes.displayName = "AvailableTimes";
+
export default AvailableTimes;
diff --git a/apps/web/components/booking/pages/AvailabilityPage.tsx b/apps/web/components/booking/pages/AvailabilityPage.tsx
index 4fdc09a81f7..c1a4219d143 100644
--- a/apps/web/components/booking/pages/AvailabilityPage.tsx
+++ b/apps/web/components/booking/pages/AvailabilityPage.tsx
@@ -1,10 +1,11 @@
// Get router variables
+import autoAnimate from "@formkit/auto-animate";
import { EventType } from "@prisma/client";
import { SchedulingType } from "@prisma/client";
import * as Popover from "@radix-ui/react-popover";
import { TFunction } from "next-i18next";
import { useRouter } from "next/router";
-import { useReducer, useEffect, useMemo, useState } from "react";
+import { useReducer, useEffect, useMemo, useState, useRef } from "react";
import { Toaster } from "react-hot-toast";
import { FormattedNumber, IntlProvider } from "react-intl";
import { z } from "zod";
@@ -128,6 +129,11 @@ const SlotPicker = ({
const { date, setQuery: setDate } = useRouterQuery("date");
const { month, setQuery: setMonth } = useRouterQuery("month");
const router = useRouter();
+ const slotPickerRef = useRef<HTMLDivElement>(null);
+
+ useEffect(() => {
+ slotPickerRef.current && autoAnimate(slotPickerRef.current);
+ }, [slotPickerRef]);
useEffect(() => {
if (!router.isReady) return;
@@ -175,10 +181,8 @@ const SlotPicker = ({
<DatePicker
isLoading={isLoading}
className={classNames(
- "mt-8 w-full px-4 pb-4 sm:mt-0 sm:min-w-[455px] md:px-5",
- selectedDate
- ? "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"
- : "sm:p-4"
+ "mt-8 px-4 pb-4 sm:mt-0 md:min-w-[300px] md:px-5 lg:min-w-[455px]",
+ selectedDate ? "sm:dark:border-darkgray-200 border-gray-200 sm:border-r sm:p-4 sm:pr-6" : "sm:p-4"
)}
includedDates={Object.keys(slots).filter((k) => slots[k].length > 0)}
locale={isLocaleReady ? i18n.language : "en"}
@@ -193,10 +197,10 @@ const SlotPicker = ({
weekStart={weekStart}
/>
- {selectedDate && (
+ <div ref={slotPickerRef}>
<AvailableTimes
isLoading={isLoading}
- slots={slots[selectedDate.format("YYYY-MM-DD")]}
+ slots={selectedDate && slots[selectedDate.format("YYYY-MM-DD")]}
date={selectedDate}
timeFormat={timeFormat}
eventTypeId={eventType.id}
@@ -205,7 +209,7 @@ const SlotPicker = ({
recurringCount={recurringEventCount}
ethSignature={ethSignature}
/>
- )}
+ </div>
</>
);
};
@@ -317,7 +321,6 @@ const AvailabilityPage = ({ profile, eventType }: Props) => {
const [timeZone, setTimeZone] = useState<string>();
const [timeFormat, setTimeFormat] = useState(timeFormatFromProfile || detectBrowserTimeFormat);
- const [isAvailableTimesVisible, setIsAvailableTimesVisible] = useState<boolean>();
const [gateState, gateDispatcher] = useReducer(
(state: GateState, newState: Partial<GateState>) => ({
...state,
@@ -330,10 +333,6 @@ const AvailabilityPage = ({ profile, eventType }: Props) => {
setTimeZone(localStorageTimeZone() || dayjs.tz.guess());
}, []);
- useEffect(() => {
- setIsAvailableTimesVisible(!!query.date);
- }, [query.date]);
-
// TODO: Improve this;
useExposePlanGlobally(eventType.users.length === 1 ? eventType.users[0].plan : "PRO");
@@ -352,14 +351,7 @@ const AvailabilityPage = ({ profile, eventType }: Props) => {
// get dynamic user list here
const userList = eventType.users ? eventType.users.map((user) => user.username).filter(notEmpty) : [];
- // Recurring event sidebar requires more space
- const maxWidth = isAvailableTimesVisible
- ? recurringEventCount
- ? "max-w-6xl"
- : "max-w-5xl"
- : recurringEventCount
- ? "max-w-4xl"
- : "max-w-3xl";
+
const timezoneDropdown = useMemo(
() => (
<TimezoneDropdown
@@ -402,203 +394,109 @@ const AvailabilityPage = ({ profile, eventType }: Props) => {
<div>
<main
className={classNames(
- shouldAlignCentrally ? "mx-auto" : "",
- isEmbed
- ? classNames(maxWidth)
- : classNames("transition-max-width mx-auto my-0 duration-500 ease-in-out md:my-24", maxWidth)
+ "flex flex-col",
+ shouldAlignCentrally ? "items-center" : "items-start",
+ !isEmbed && classNames("mx-auto my-0 ease-in-out md:my-24")
)}>
- <div
- style={availabilityDatePickerEmbedStyles}
- className={classNames(
- isBackgroundTransparent
- ? ""
- : "dark:bg-darkgray-100 sm:dark:border-darkgray-300 bg-white pb-4 md:pb-0",
- "border-bookinglightest overflow-hidden rounded-md md:border",
- isEmbed ? "mx-auto" : maxWidth
- )}>
- {/* mobile: details */}
- <div className="block px-4 pt-4 sm:p-8 md:hidden">
- <div>
- <UserAvatars
- profile={profile}
- users={eventType.users}
- showMembers={eventType.schedulingType !== SchedulingType.ROUND_ROBIN}
- size={9}
- truncateAfter={5}
- />
- <div className="mt-4">
- <div className="dark:text-darkgray-900 mt-2 gap-2">
- <p className="break-words text-sm font-medium text-gray-600 dark:text-gray-300">
- {profile.name}
- </p>
- <h1 className="text-bookingdark dark:text-darkgray-900 mb-4 break-words text-xl font-semibold">
- {eventType.title}
- </h1>
- <div className="flex flex-col items-start space-y-3">
- {eventType?.description && (
- <div className="dark:text-darkgray-600 flex py-1 text-sm font-medium text-gray-600">
- <div>
- <Icon.FiInfo className="mr-[10px] ml-[2px] inline-block h-4 w-4" />
- </div>
- <EventTypeDescriptionSafeHTML eventType={eventType} />
+ <div>
+ <div
+ style={availabilityDatePickerEmbedStyles}
+ className={classNames(
+ isBackgroundTransparent
+ ? ""
+ : "dark:bg-darkgray-100 sm:dark:border-darkgray-300 bg-white pb-4 md:pb-0",
+ "border-bookinglightest overflow-hidden rounded-md md:border",
+ isEmbed && "mx-auto"
+ )}>
+ <div className="overflow-hidden md:flex">
+ <div
+ className={classNames(
+ "sm:dark:border-darkgray-200 flex flex-col border-gray-200 p-5 sm:border-r",
+ "min-w-full md:w-[280px] md:min-w-[280px]",
+ recurringEventCount && "xl:w-[380px] xl:min-w-[380px]"
+ )}>
+ <UserAvatars
+ profile={profile}
+ users={eventType.users}
+ showMembers={eventType.schedulingType !== SchedulingType.ROUND_ROBIN}
+ size={10}
+ truncateAfter={3}
+ />
+ <h2 className="mt-2 break-words text-sm font-medium text-gray-600 dark:text-gray-300">
+ {profile.name}
+ </h2>
+ <h1 className="font-cal dark:text-darkgray-900 mb-6 break-words text-2xl font-semibold text-gray-900">
+ {eventType.title}
+ </h1>
+ <div className="dark:text-darkgray-600 flex flex-col space-y-3 text-sm font-medium text-gray-600">
+ {eventType?.description && (
+ <div className="flex">
+ <div>
+ <Icon.FiInfo className="mr-[10px] ml-[2px] inline-block h-4 w-4" />
</div>
- )}
- {eventType?.requiresConfirmation && (
- <p className="dark:text-darkgray-600 text-gray-600">
- <Icon.FiCheckSquare className="mr-[10px] ml-[2px] -mt-1 inline-block h-4 w-4" />
- {t("requires_confirmation")}
- </p>
- )}
- <AvailableEventLocations locations={eventType.locations} />
- <p className="dark:text-darkgray-600 text-gray-600">
- <Icon.FiClock className="mr-[10px] -mt-1 ml-[2px] inline-block h-4 w-4" />
- {eventType.length} {t("minutes")}
- </p>
- {eventType.price > 0 && (
- <div className="dark:text-darkgray-600 text-gray-600">
- <Icon.FiCreditCard className="mr-[10px] ml-[2px] -mt-1 inline-block h-4 w-4" />
- <IntlProvider locale="en">
- <FormattedNumber
- value={eventType.price / 100.0}
- style="currency"
- currency={eventType.currency.toUpperCase()}
- />
- </IntlProvider>
+ <EventTypeDescriptionSafeHTML eventType={eventType} />
+ </div>
+ )}
+ {eventType?.requiresConfirmation && (
+ <div className="flex items-center">
+ <div>
+ <Icon.FiCheckSquare className="mr-[10px] ml-[2px] -mt-1 inline-block h-4 w-4 " />
</div>
- )}
- {!rescheduleUid && eventType.recurringEvent && (
- <div className="dark:text-darkgray-600 flex items-center text-gray-600">
- <Icon.FiRefreshCcw className="float-left mr-[10px] mt-1 ml-[2px] inline-block h-4 w-4 shrink-0 text-gray-500" />
- <div>
- <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}
- 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"
- defaultValue={eventType.recurringEvent.count}
- onChange={(event) => {
- setRecurringEventCount(parseInt(event?.target.value));
- }}
- />
- <p className="dark:text-darkgray-600 inline text-gray-600">
- {t("occurrence", {
- count: recurringEventCount,
- })}
- </p>
- </div>
+ {t("requires_confirmation")}
+ </div>
+ )}
+ <AvailableEventLocations locations={eventType.locations} />
+ <p className="text-sm font-medium">
+ <Icon.FiClock className="mr-[10px] -mt-1 ml-[2px] inline-block h-4 w-4" />
+ {eventType.length} {t("minutes")}
+ </p>
+ {!rescheduleUid && eventType.recurringEvent && (
+ <div className="flex items-start text-sm font-medium">
+ <Icon.FiRefreshCcw className="float-left mr-[10px] mt-[7px] ml-[2px] inline-block h-4 w-4 " />
+ <div>
+ <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}
+ 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"
+ defaultValue={eventType.recurringEvent.count}
+ onChange={(event) => {
+ setRecurringEventCount(parseInt(event?.target.value));
+ }}
+ />
+ <p className="inline">
+ {t("occurrence", {
+ count: recurringEventCount,
+ })}
+ </p>
</div>
- )}
- {timezoneDropdown}
-
- <div className="md:hidden">
- {/* Temp disabled booking?.startTime && rescheduleUid && (
- <div>
- <p
- className="mt-8 text-gray-600 dark:text-darkgray-600"
- data-testid="former_time_p_mobile">
- {t("former_time")}
- </p>
- <p className="text-gray-500 line-through dark:text-darkgray-600">
- <CalendarIcon className="mr-[10px] -mt-1 inline-block h-4 w-4 text-gray-500" />
- {typeof booking.startTime === "string" &&
- parseDate(dayjs(booking.startTime), i18n)}
- </p>
- </div>
- )*/}
</div>
- </div>
+ )}
+ {eventType.price > 0 && (
+ <p className="-ml-2 px-2 text-sm font-medium">
+ <Icon.FiCreditCard className="mr-[10px] ml-[2px] -mt-1 inline-block h-4 w-4" />
+ <IntlProvider locale="en">
+ <FormattedNumber
+ value={eventType.price / 100.0}
+ style="currency"
+ currency={eventType.currency.toUpperCase()}
+ />
+ </IntlProvider>
+ </p>
+ )}
+ {timezoneDropdown}
</div>
- </div>
- </div>
- </div>
- <div className="overflow-hidden sm:flex">
- <div
- className={
- "sm:dark:border-darkgray-200 hidden border-gray-200 p-5 sm:border-r md:flex md:flex-col " +
- (isAvailableTimesVisible ? "sm:w-1/3" : recurringEventCount ? "sm:w-2/3" : "sm:w-1/2")
- }>
- <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>
- <h1 className="font-cal dark:text-darkgray-900 mb-6 break-words text-2xl text-gray-900">
- {eventType.title}
- </h1>
- <div className="dark:text-darkgray-600 flex flex-col space-y-3 text-sm font-medium text-gray-600">
- {eventType?.description && (
- <div className="flex">
- <div>
- <Icon.FiInfo className="mr-[10px] ml-[2px] inline-block h-4 w-4" />
- </div>
- <EventTypeDescriptionSafeHTML eventType={eventType} />
- </div>
- )}
- {eventType?.requiresConfirmation && (
- <div className="flex items-center">
- <div>
- <Icon.FiCheckSquare className="mr-[10px] ml-[2px] -mt-1 inline-block h-4 w-4 " />
- </div>
- {t("requires_confirmation")}
+ {!isEmbed && (
+ <div className="mt-auto hidden md:block">
+ <GoBackToPreviousPage t={t} />
</div>
)}
- <AvailableEventLocations locations={eventType.locations} />
- <p className="text-sm font-medium">
- <Icon.FiClock className="mr-[10px] -mt-1 ml-[2px] inline-block h-4 w-4" />
- {eventType.length} {t("minutes")}
- </p>
- {!rescheduleUid && eventType.recurringEvent && (
- <div className="flex items-start text-sm font-medium">
- <Icon.FiRefreshCcw className="float-left mr-[10px] mt-[7px] ml-[2px] inline-block h-4 w-4 " />
- <div>
- <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}
- 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"
- defaultValue={eventType.recurringEvent.count}
- onChange={(event) => {
- setRecurringEventCount(parseInt(event?.target.value));
- }}
- />
- <p className="inline">
- {t("occurrence", {
- count: recurringEventCount,
- })}
- </p>
- </div>
- </div>
- )}
- {eventType.price > 0 && (
- <p className="-ml-2 px-2 text-sm font-medium">
- <Icon.FiCreditCard className="mr-[10px] ml-[2px] -mt-1 inline-block h-4 w-4" />
- <IntlProvider locale="en">
- <FormattedNumber
- value={eventType.price / 100.0}
- style="currency"
- currency={eventType.currency.toUpperCase()}
- />
- </IntlProvider>
- </p>
- )}
- {timezoneDropdown}
- </div>
- {!isEmbed && <GoBackToPreviousPage t={t} />}
-
- {/* Temporarily disabled - booking?.startTime && rescheduleUid && (
+ {/* Temporarily disabled - booking?.startTime && rescheduleUid && (
<div>
<p
className="mt-4 mb-3 text-gray-600 dark:text-darkgray-600"
@@ -611,26 +509,33 @@ const AvailabilityPage = ({ profile, eventType }: Props) => {
</p>
</div>
)*/}
+ </div>
+ <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}
+ users={userList}
+ seatsPerTimeSlot={eventType.seatsPerTimeSlot || undefined}
+ recurringEventCount={recurringEventCount}
+ ethSignature={gateState.rainbowToken}
+ />
</div>
- <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}
- users={userList}
- seatsPerTimeSlot={eventType.seatsPerTimeSlot || undefined}
- recurringEventCount={recurringEventCount}
- ethSignature={gateState.rainbowToken}
- />
</div>
+ {(!eventType.users[0] || !isBrandingHidden(eventType.users[0])) && !isEmbed && <PoweredByCal />}
</div>
- {(!eventType.users[0] || !isBrandingHidden(eventType.users[0])) && !isEmbed && <PoweredByCal />}
</main>
</div>
<Toaster position="bottom-right" />