fix: Broken navigation after booking creation in some cases (#15664)

Co-authored-by: Keith Williams <keithwillcode@gmail.com>
This commit is contained in:
Hariom BalharaandKeith Williams authored and GitHub committed 2024-07-08 13:56:58 +00:00
1 parent 5bbc025494
commit 5ff7e65d64
3 files changed
+10 -3

No files matched your search

@@ -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");
+3 -2
View File
@@ -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 });
+5
View File
@@ -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;
};