Scheduling infrastructure for absolutely everyone.
fix: Broken navigation after booking creation in some cases (#15664)
Hariom Balhara5ff7e65d6475
diff --git a/packages/app-store/routing-forms/pages/routing-link/[...appPages].tsx b/packages/app-store/routing-forms/pages/routing-link/[...appPages].tsxindex 7abc78a6d26..e69ffd0d564 100644--- a/packages/app-store/routing-forms/pages/routing-link/[...appPages].tsx+++ b/packages/app-store/routing-forms/pages/routing-link/[...appPages].tsx@@ -13,6 +13,7 @@ import useGetBrandingColours from "@calcom/lib/getBrandColours";import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams";import { useLocale } from "@calcom/lib/hooks/useLocale";import useTheme from "@calcom/lib/hooks/useTheme";+import { navigateInTopWindow } from "@calcom/lib/navigateInTopWindow";import { trpc } from "@calcom/trpc/react";import type { inferSSRProps } from "@calcom/types/inferSSRProps";import { Button, showToast, useCalcomTheme } from "@calcom/ui";@@ -115,7 +116,7 @@ function RoutingForm({ form, profile, ...restProps }: Props) {}));} else if (decidedAction.type === "externalRedirectUrl") {- window.parent.location.href = `${decidedAction.value}?${allURLSearchParams}`;+ navigateInTopWindow(`${decidedAction.value}?${allURLSearchParams}`);}// We don't want to show this message as it doesn't look good in Embed.// showToast("Form submitted successfully! Redirecting now ...", "success");diff --git a/packages/lib/bookingSuccessRedirect.ts b/packages/lib/bookingSuccessRedirect.tsindex 6bd4c71398c..d3c6b5b1c12 100644--- a/packages/lib/bookingSuccessRedirect.ts+++ b/packages/lib/bookingSuccessRedirect.ts@@ -4,6 +4,7 @@ import { useRouter } from "next/navigation";import type { PaymentPageProps } from "@calcom/ee/payments/pages/payment";import type { BookingResponse } from "@calcom/features/bookings/types";import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams";+import { navigateInTopWindow } from "@calcom/lib/navigateInTopWindow";function getNewSeachParams(args: {query: Record<string, string | null | undefined | boolean>;@@ -58,7 +59,7 @@ export const useBookingSuccessRedirect = () => {const url = new URL(successRedirectUrl);// Using parent ensures, Embed iframe would redirect outside of the iframe.if (!forwardParamsSuccessRedirect) {- window.parent.location.href = url.toString();+ navigateInTopWindow(url.toString());return;}const bookingExtraParams = getBookingRedirectExtraParams(booking);@@ -74,7 +75,7 @@ export const useBookingSuccessRedirect = () => {url.searchParams.append(key, value);});- window.parent.location.href = url.toString();+ navigateInTopWindow(url.toString());return;}const newSearchParams = getNewSeachParams({ query });diff --git a/packages/lib/navigateInTopWindow.ts b/packages/lib/navigateInTopWindow.tsnew file mode 100644index 00000000000..24e4b43eb6b--- /dev/null+++ b/packages/lib/navigateInTopWindow.ts@@ -0,0 +1,5 @@+export const navigateInTopWindow = (url: string) => {+ // In some weird unknown case, window.top.location could be null as per typescript. In such case, we still do the redirect but in same window+ const location = window.top ? window.top.location : window.location;+ location.href = url;+};