feat: allow timezones selection in Booker atom via prop (#20044)

* expose props to pass in timezones and booking dry run values from outside

* fix merge conflicts

* update typings

* add props values to test

* fixup: PR feedback

* PR feedback

* fix wrong prop name

* fix merge conflicts

* fixup

* update docs

* update docs examples

* fix props naming

* fix timezone component logic and typo

* extract typings of timeZones

* update typings for Timezone

* update docs

* resolve merge conflicts

* fix typings

---------

Co-authored-by: Morgan <[email protected]>
This commit is contained in:
Rajiv SahalandMorgan authored and GitHub committed 2025-03-20 14:05:45 +00:00
1 parent efeb0a8f41
commit 08d4c800e9
11 files changed
+488 -17

No files matched your search

@@ -83,6 +83,7 @@ const BookerComponent = ({
renderCaptcha,
hashedLink,
confirmButtonDisabled,
timeZones,
}: BookerProps & WrappedBookerProps) => {
const searchParams = useCompatSearchParams();
const isPlatformBookerEmbed = useIsPlatformBookerEmbed();
@@ -404,6 +405,7 @@ const BookerComponent = ({
isPlatform={isPlatform}
isPrivateLink={!!hashedLink}
locale={userLocale}
timeZones={timeZones}
/>
{layout !== BookerLayouts.MONTH_VIEW &&
!(layout === "mobile" && bookerState === "booking") && (
@@ -6,6 +6,7 @@ import { shallow } from "zustand/shallow";
import { Timezone as PlatformTimezoneSelect } from "@calcom/atoms/timezone";
import { useEmbedUiConfig, useIsEmbed } from "@calcom/embed-core/embed-iframe";
import { EventDetails, EventMembers, EventMetaSkeleton, EventTitle } from "@calcom/features/bookings";
import type { Timezone } from "@calcom/features/bookings/Booker/types";
import { SeatsAvailabilityText } from "@calcom/features/bookings/components/SeatsAvailabilityText";
import { EventMetaBlock } from "@calcom/features/bookings/components/event-meta/Details";
import { useTimePreferences } from "@calcom/features/bookings/lib";
@@ -51,6 +52,7 @@ export const EventMeta = ({
isPrivateLink,
classNames,
locale,
timeZones,
}: {
event?: Pick<
BookerEvent,
@@ -83,6 +85,7 @@ export const EventMeta = ({
eventMetaTimezoneSelect?: string;
};
locale?: string | null;
timeZones?: Timezone[];
}) => {
const { timeFormat, timezone } = useBookerTime();
const [setTimezone] = useTimePreferences((state) => [state.setTimezone]);
@@ -211,6 +214,7 @@ export const EventMeta = ({
event.lockTimeZoneToggleOnBookingPage ? "cursor-not-allowed" : ""
}`}>
<TimezoneSelect
timeZones={timeZones}
menuPosition="absolute"
timezoneSelectCustomClassname={classNames?.eventMetaTimezoneSelect}
classNames={{
@@ -7,10 +7,13 @@ import type { UseVerifyCodeReturnType } from "@calcom/features/bookings/Booker/c
import type { UseVerifyEmailReturnType } from "@calcom/features/bookings/Booker/components/hooks/useVerifyEmail";
import type { useScheduleForEventReturnType } from "@calcom/features/bookings/Booker/utils/event";
import type { BookerEventQuery } from "@calcom/features/bookings/types";
import type { IntlSupportedTimeZones } from "@calcom/lib/timeZones";
import type { BookerLayouts } from "@calcom/prisma/zod-utils";
import type { GetBookingType } from "../lib/get-booking";
export type Timezone = (typeof IntlSupportedTimeZones)[number];
export interface BookerProps {
eventSlug: string;
username: string;
@@ -127,10 +130,12 @@ export type WrappedBookerPropsForPlatform = WrappedBookerPropsMain & {
isPlatform: true;
verifyCode: undefined;
customClassNames?: CustomClassNames;
timeZones?: Timezone[];
};
export type WrappedBookerPropsForWeb = WrappedBookerPropsMain & {
isPlatform: false;
verifyCode: UseVerifyCodeReturnType;
timeZones?: Timezone[];
};
export type WrappedBookerProps = WrappedBookerPropsForPlatform | WrappedBookerPropsForWeb;
@@ -48,9 +48,11 @@ export function TimezoneSelect(props: TimezoneSelectProps) {
trpc: { context: { skipBatch: true } },
}
);
const cityTimezonesFormatted = data.map(({ city, timezone }) => ({ label: city, timezone }));
return (
<TimezoneSelectComponent
data={data.map(({ city, timezone }) => ({ label: city, timezone }))}
data={[...cityTimezonesFormatted, ...SELECT_SEARCH_DATA]}
isPending={isPending}
{...props}
/>
@@ -64,6 +66,7 @@ export type TimezoneSelectComponentProps = SelectProps & {
timezoneSelectCustomClassname?: string;
size?: "sm" | "md";
grow?: boolean;
isWebTimezoneSelect?: boolean;
};
// TODO: I wonder if we move this to ui package, and keep the TRPC version in features
@@ -77,9 +80,10 @@ export function TimezoneSelectComponent({
value,
size = "md",
grow = false,
isWebTimezoneSelect = true,
...props
}: TimezoneSelectComponentProps) {
const data = [...(props.data || []), ...SELECT_SEARCH_DATA];
const data = [...(props.data || [])];
/*
* we support multiple timezones for the different labels
* e.g. 'Sao Paulo' and 'Brazil Time' both being 'America/Sao_Paulo'
@@ -108,7 +112,7 @@ export function TimezoneSelectComponent({
{...reactSelectProps}
timezones={{
...(props.data ? addTimezonesToDropdown(data) : {}),
...addTimezonesToDropdown(additionalTimezones),
...(isWebTimezoneSelect ? addTimezonesToDropdown(additionalTimezones) : {}),
}}
styles={{
control: (base) => ({