Skip to content

fix: improve redirect parameter handling for success page #20764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
27 changes: 27 additions & 0 deletions packages/lib/bookingSuccessRedirect.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { describe, expect, it } from "vitest";

import { getNewSearchParams } from "./bookingSuccessRedirect";

describe("getNewSearchParams", () => {
it("should remove 'embed' param when isEmbed is true", () => {
const searchParams = new URLSearchParams({ embed: "true", foo: "bar" });
const query = { bookingId: "123" };

const result = getNewSearchParams({ query, searchParams, isEmbed: true });

expect(result.get("embed")).toBeNull();
expect(result.get("foo")).toBe("bar");
expect(result.get("bookingId")).toBe("123");
});

it("should keep 'embed' param when isEmbed is false", () => {
const searchParams = new URLSearchParams({ embed: "true", foo: "bar" });
const query = { bookingId: "456" };

const result = getNewSearchParams({ query, searchParams, isEmbed: false });

expect(result.get("embed")).toBe("true");
expect(result.get("foo")).toBe("bar");
expect(result.get("bookingId")).toBe("456");
});
});
10 changes: 8 additions & 2 deletions packages/lib/bookingSuccessRedirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@ import { navigateInTopWindow } from "@calcom/lib/navigateInTopWindow";

import { getSafe } from "./getSafe";

function getNewSearchParams(args: {
export function getNewSearchParams(args: {
query: Record<string, string | null | undefined | boolean>;
searchParams?: URLSearchParams;
isEmbed?: boolean;
}) {
const { query, searchParams } = args;
const { query, searchParams, isEmbed } = args;
const newSearchParams = new URLSearchParams(searchParams);

if (isEmbed) {
newSearchParams.delete("embed");
}
Object.entries(query).forEach(([key, value]) => {
if (value === null || value === undefined) {
return;
Expand Down Expand Up @@ -184,6 +189,7 @@ export const useBookingSuccessRedirect = () => {
query: {
...query,
...bookingExtraParams,
isEmbed,
},
searchParams: new URLSearchParams(searchParams.toString()),
});
Expand Down
Loading