chore: enable more router props (#19088)

* chore: enable more router props

* chore: expose booker props via router atom
This commit is contained in:
Morgan
2025-02-05 08:36:34 +00:00
committed by GitHub
parent 288248d94f
commit 14ec3813ee
2 changed files with 45 additions and 19 deletions
@@ -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 (
<CalProvider
clientId={import.meta.env.VITE_BOOKER_EMBED_OAUTH_CLIENT_ID}
@@ -45,20 +59,22 @@ export const BookerEmbed = (
isTeamEvent: true,
teamId: routingTeamId || 0,
username: "",
customClassNames: props?.customClassNames,
}
: {
eventSlug: eventTypeSlug,
username: username ?? "",
isTeamEvent: false,
customClassNames: props?.customClassNames,
})}
routingFormSearchParams={routingFormSearchParams}
defaultFormValues={defaultFormValues}
bannerUrl={props.bannerUrl}
onDryRunSuccess={() => {
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}
/>
</CalProvider>
);
+25 -15
View File
@@ -12,10 +12,11 @@ import type { BookerPlatformWrapperAtomPropsForTeam } from "../booker/BookerPlat
* <Router
* formId="1a1a1a1a-2b2b-3c3c-4d4d-5e5e5e5e5e5e"
* formResponsesURLParams={new URLSearchParams({ Territory: "Europe" })}
* bookerBannerUrl="https://i0.wp.com/mahala.co.uk/wp-content/uploads/2014/12/img_banner-thin_mountains.jpg?fit=800%2C258&ssl=1"
* bookerCustomClassNames={{
* bookerWrapper: "dark",
* }}
* bookerProps={{
* customClassNames: { bookerWrapper: "dark" },
* bannerUrl: "https://i0.wp.com/mahala.co.uk/wp-content/uploads/2014/12/img_banner-thin_mountains.jpg?fit=800%2C258&ssl=1",
* onCreateBookingSuccess: (data) => 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<BookerPlatformWrapperAtomPropsForTeam>,
| "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<boolean>();
const [routerUrl, setRouterUrl] = useState<string>();
@@ -103,13 +119,7 @@ export const Router = React.memo(
if (redirectParams.get("cal.action") === "eventTypeRedirectUrl") {
// display booker with redirect URL
onDisplayBookerEmbed?.();
return (
<BookerEmbed
routingFormUrl={routerUrl}
customClassNames={bookerCustomClassNames}
bannerUrl={bookerBannerUrl}
/>
);
return <BookerEmbed routingFormUrl={routerUrl} {...bookerProps} />;
} else if (redirectParams.get("cal.action") === "externalRedirectUrl") {
onExternalRedirect?.();
window.location.href = routerUrl;