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:
1 parent
efeb0a8f41
commit
08d4c800e9
11 files changed
+488
-17
No files matched your search
@@ -59,6 +59,7 @@ export const BookerPlatformWrapper = (
|
||||
onBookerStateChange,
|
||||
allowUpdatingUrlParams = false,
|
||||
confirmButtonDisabled,
|
||||
isBookingDryRun,
|
||||
} = props;
|
||||
const layout = BookerLayouts[view];
|
||||
|
||||
@@ -292,7 +293,9 @@ export const BookerPlatformWrapper = (
|
||||
|
||||
const _cacheParam = searchParams?.get("cal.cache");
|
||||
const shouldServeCache = _cacheParam ? _cacheParam === "true" : undefined;
|
||||
const isBookingDryRun = searchParams?.get("cal.isBookingDryRun")?.toLowerCase() === "true";
|
||||
const isBookingDryRun =
|
||||
searchParams?.get("cal.isBookingDryRun")?.toLowerCase() === "true" ||
|
||||
searchParams?.get("cal.sandbox")?.toLowerCase() === "true";
|
||||
setRoutingParams({
|
||||
...(skipContactOwner ? { skipContactOwner } : {}),
|
||||
...(routedTeamMemberIds ? { routedTeamMemberIds } : {}),
|
||||
@@ -487,6 +490,7 @@ export const BookerPlatformWrapper = (
|
||||
return (
|
||||
<AtomsWrapper customClassName={props?.customClassNames?.atomsWrapper}>
|
||||
<BookerComponent
|
||||
timeZones={props.timeZones}
|
||||
teamMemberEmail={teamMemberEmail}
|
||||
crmAppSlug={crmAppSlug}
|
||||
crmOwnerRecordType={crmOwnerRecordType}
|
||||
@@ -575,7 +579,7 @@ export const BookerPlatformWrapper = (
|
||||
verifyCode={undefined}
|
||||
isPlatform
|
||||
hasValidLicense={true}
|
||||
isBookingDryRun={routingParams?.isBookingDryRun}
|
||||
isBookingDryRun={isBookingDryRun ?? routingParams?.isBookingDryRun}
|
||||
/>
|
||||
</AtomsWrapper>
|
||||
);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { BookerProps } from "@calcom/features/bookings/Booker";
|
||||
import type { BookerStore } from "@calcom/features/bookings/Booker/store";
|
||||
import type { Timezone } from "@calcom/features/bookings/Booker/types";
|
||||
import type { BookingResponse } from "@calcom/platform-libraries";
|
||||
import type {
|
||||
ApiSuccessResponse,
|
||||
@@ -74,6 +75,8 @@ export type BookerPlatformWrapperAtomProps = Omit<
|
||||
preventEventTypeRedirect?: boolean;
|
||||
allowUpdatingUrlParams?: boolean;
|
||||
confirmButtonDisabled?: boolean;
|
||||
timeZones?: Timezone[];
|
||||
isBookingDryRun?: boolean;
|
||||
};
|
||||
|
||||
type VIEW_TYPE = keyof typeof BookerLayouts;
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
export const formatTimezones = (
|
||||
timeZones: {
|
||||
city: string;
|
||||
timezone: string;
|
||||
}[]
|
||||
) => {
|
||||
return timeZones.map(({ city, timezone }) => ({
|
||||
label: city,
|
||||
timezone,
|
||||
}));
|
||||
};
|
||||
|
||||
export const filterPropsTimezones = (
|
||||
propsTimezones: string[],
|
||||
availableTimezones: { city: string; timezone: string }[]
|
||||
) => {
|
||||
return availableTimezones.filter((availableTimezone) =>
|
||||
propsTimezones.includes(availableTimezone.timezone)
|
||||
);
|
||||
};
|
||||
@@ -1,23 +1,30 @@
|
||||
import { useMemo } from "react";
|
||||
|
||||
import { TimezoneSelectComponent as TimezoneSelect } from "@calcom/features/components/timezone-select";
|
||||
import type { TimezoneSelectProps } from "@calcom/features/components/timezone-select";
|
||||
|
||||
import type { Timezone } from "@calcom/features/bookings/Booker/types";
|
||||
import useGetCityTimezones from "../hooks/useGetCityTimezones";
|
||||
import { filterPropsTimezones, formatTimezones } from "../src/lib/timeZones";
|
||||
|
||||
export function Timezone(props: TimezoneSelectProps) {
|
||||
const { isLoading, data } = useGetCityTimezones();
|
||||
export function Timezone(props: TimezoneSelectProps & { timeZones?: Timezone[] }) {
|
||||
const { isLoading: isLoadingAvailableCityTimezones, data: availableCityTimezones } = useGetCityTimezones();
|
||||
const cityTimeZones = useMemo(() => {
|
||||
if (props.timeZones) {
|
||||
const filteredTimeZones = filterPropsTimezones(props.timeZones, availableCityTimezones ?? []);
|
||||
return formatTimezones(filteredTimeZones);
|
||||
} else if (availableCityTimezones && !isLoadingAvailableCityTimezones) {
|
||||
return formatTimezones(availableCityTimezones);
|
||||
}
|
||||
|
||||
return [];
|
||||
}, [availableCityTimezones, props.timeZones, isLoadingAvailableCityTimezones]);
|
||||
|
||||
return (
|
||||
<TimezoneSelect
|
||||
{...props}
|
||||
data={
|
||||
Array.isArray(data)
|
||||
? data.map(({ city, timezone }) => ({
|
||||
label: city,
|
||||
timezone,
|
||||
}))
|
||||
: []
|
||||
}
|
||||
isPending={isLoading}
|
||||
data={cityTimeZones}
|
||||
isPending={isLoadingAvailableCityTimezones}
|
||||
isWebTimezoneSelect={false}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -91,6 +91,8 @@ export default function Bookings(props: { calUsername: string; calEmail: string
|
||||
{!bookingTitle && eventTypeSlug && !rescheduleUid && (
|
||||
<>
|
||||
<Booker
|
||||
// timeZones={["Europe/London", "Asia/Kolkata"]}
|
||||
// isBookingDryRun={true}
|
||||
bannerUrl="https://i0.wp.com/mahala.co.uk/wp-content/uploads/2014/12/img_banner-thin_mountains.jpg?fit=800%2C258&ssl=1"
|
||||
eventSlug={eventTypeSlug}
|
||||
onCreateBookingSuccess={(data) => {
|
||||
|
||||
Reference in new issue
Block a user