From 14ec3813ee47fe1e199ff06ffa12884822c6dbd4 Mon Sep 17 00:00:00 2001
From: Morgan <33722304+ThyMinimalDev@users.noreply.github.com>
Date: Wed, 5 Feb 2025 10:36:34 +0200
Subject: [PATCH] chore: enable more router props (#19088)
* chore: enable more router props
* chore: expose booker props via router atom
---
.../atoms/booker-embed/BookerEmbed.tsx | 24 +++++++++--
packages/platform/atoms/router/Router.tsx | 40 ++++++++++++-------
2 files changed, 45 insertions(+), 19 deletions(-)
diff --git a/packages/platform/atoms/booker-embed/BookerEmbed.tsx b/packages/platform/atoms/booker-embed/BookerEmbed.tsx
index 852c41f04f..016f020cd9 100644
--- a/packages/platform/atoms/booker-embed/BookerEmbed.tsx
+++ b/packages/platform/atoms/booker-embed/BookerEmbed.tsx
@@ -12,6 +12,19 @@ export const BookerEmbed = (
routingFormUrl: string;
bannerUrl?: BookerPlatformWrapperAtomPropsForTeam["bannerUrl"];
customClassNames?: BookerPlatformWrapperAtomPropsForTeam["customClassNames"];
+ onCreateBookingSuccess?: BookerPlatformWrapperAtomPropsForTeam["onCreateBookingSuccess"];
+ onCreateBookingError?: BookerPlatformWrapperAtomPropsForTeam["onCreateBookingError"];
+ onCreateRecurringBookingSuccess?: BookerPlatformWrapperAtomPropsForTeam["onCreateRecurringBookingSuccess"];
+ onCreateRecurringBookingError?: BookerPlatformWrapperAtomPropsForTeam["onCreateRecurringBookingError"];
+ onReserveSlotSuccess?: BookerPlatformWrapperAtomPropsForTeam["onReserveSlotSuccess"];
+ onReserveSlotError?: BookerPlatformWrapperAtomPropsForTeam["onReserveSlotError"];
+ onDeleteSlotSuccess?: BookerPlatformWrapperAtomPropsForTeam["onDeleteSlotSuccess"];
+ onDeleteSlotError?: BookerPlatformWrapperAtomPropsForTeam["onDeleteSlotError"];
+ view?: BookerPlatformWrapperAtomPropsForTeam["view"];
+ onDryRunSuccess?: BookerPlatformWrapperAtomPropsForTeam["onDryRunSuccess"];
+ hostsLimit?: BookerPlatformWrapperAtomPropsForTeam["hostsLimit"];
+ metadata?: BookerPlatformWrapperAtomPropsForTeam["metadata"];
+ handleCreateBooking?: BookerPlatformWrapperAtomPropsForTeam["handleCreateBooking"];
}
| (BookerPlatformWrapperAtomPropsForIndividual & {
organizationId?: undefined;
@@ -30,6 +43,7 @@ export const BookerEmbed = (
defaultFormValues,
...routingFormSearchParams
} = routingFormUrlProps;
+ const { onDryRunSuccess, ...rest } = props;
return (
{
- window.location.href = `https://app.cal.com/booking/dry-run-successful`;
+ if (onDryRunSuccess) {
+ onDryRunSuccess();
+ } else {
+ window.location.href = `https://app.cal.com/booking/dry-run-successful`;
+ }
}}
+ {...rest}
/>
);
diff --git a/packages/platform/atoms/router/Router.tsx b/packages/platform/atoms/router/Router.tsx
index c4b5be2263..d85eb2c683 100644
--- a/packages/platform/atoms/router/Router.tsx
+++ b/packages/platform/atoms/router/Router.tsx
@@ -12,10 +12,11 @@ import type { BookerPlatformWrapperAtomPropsForTeam } from "../booker/BookerPlat
* console.log(data),
+ * onCreateBookingError: (err) => console.error(err)
* />
* ```
*/
@@ -27,11 +28,10 @@ export const Router = React.memo(
onExternalRedirect,
onDisplayBookerEmbed,
renderMessage,
- bookerBannerUrl,
- bookerCustomClassNames,
onSubmitFormStart,
onSubmitFormEnd,
renderLoader,
+ bookerProps,
}: {
formId: string;
formResponsesURLParams?: URLSearchParams;
@@ -40,9 +40,25 @@ export const Router = React.memo(
onSubmitFormStart?: () => void;
onSubmitFormEnd?: () => void;
renderMessage?: (message?: string) => ReactElement | ReactElement[];
+ bookerProps?: Pick<
+ Partial,
+ | "customClassNames"
+ | "bannerUrl"
+ | "onCreateBookingSuccess"
+ | "onCreateBookingError"
+ | "onCreateRecurringBookingSuccess"
+ | "onCreateRecurringBookingError"
+ | "onReserveSlotSuccess"
+ | "onReserveSlotError"
+ | "onDeleteSlotSuccess"
+ | "onDeleteSlotError"
+ | "view"
+ | "onDryRunSuccess"
+ | "hostsLimit"
+ | "metadata"
+ | "handleCreateBooking"
+ >;
renderLoader?: (isLoading?: boolean) => ReactElement | ReactElement[];
- bookerBannerUrl?: BookerPlatformWrapperAtomPropsForTeam["bannerUrl"];
- bookerCustomClassNames?: BookerPlatformWrapperAtomPropsForTeam["customClassNames"];
}) => {
const [isLoading, setIsLoading] = useState();
const [routerUrl, setRouterUrl] = useState();
@@ -103,13 +119,7 @@ export const Router = React.memo(
if (redirectParams.get("cal.action") === "eventTypeRedirectUrl") {
// display booker with redirect URL
onDisplayBookerEmbed?.();
- return (
-
- );
+ return ;
} else if (redirectParams.get("cal.action") === "externalRedirectUrl") {
onExternalRedirect?.();
window.location.href = routerUrl;