fix: improve redirect parameter handling for success page (#20764)
* improve redirect parameter * test --------- Co-authored-by: Kartik Saini <41051387+kart1ka@users.noreply.github.com>
This commit is contained in:
co-authored by
Kartik Saini
parent
52940ce254
commit
4404699fa6
@@ -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,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;
|
||||
@@ -184,6 +189,7 @@ export const useBookingSuccessRedirect = () => {
|
||||
query: {
|
||||
...query,
|
||||
...bookingExtraParams,
|
||||
isEmbed,
|
||||
},
|
||||
searchParams: new URLSearchParams(searchParams.toString()),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user