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

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

import { filterEmbedParameter } from "./bookingSuccessRedirect";

describe("Booking Success Redirect", () => {
it(" removes embed parameter", () => {
const params = new URLSearchParams();
params.append("embed", "namespace");
params.append("param1", "value1");

const filtered = filterEmbedParameter(params, true);

expect(filtered.has("embed")).toBe(false);
expect(filtered.get("param1")).toBe("value1");
});

it("keeps embed parameter ", () => {
const params = new URLSearchParams();
params.append("embed", "namespace");
params.append("param1", "value1");

const filtered = filterEmbedParameter(params, false);

expect(filtered.has("embed")).toBe(true);
expect(filtered.get("embed")).toBe("namespace");
expect(filtered.get("param1")).toBe("value1");
});
});
11 changes: 10 additions & 1 deletion packages/lib/bookingSuccessRedirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ export const getBookingRedirectExtraParams = (booking: SuccessRedirectBookingTyp
return queryCompatibleParams;
};

export const filterEmbedParameter = (params: URLSearchParams, isEmbed: boolean | undefined) => {
// Only filter embed parameter if we're in an embedded context
if (!isEmbed) return new URLSearchParams(params.toString());

const filteredParams = new URLSearchParams(params.toString());
filteredParams.delete("embed");
return filteredParams;
};

export const useBookingSuccessRedirect = () => {
const router = useRouter();
const searchParams = useCompatSearchParams();
Expand Down Expand Up @@ -185,7 +194,7 @@ export const useBookingSuccessRedirect = () => {
...query,
...bookingExtraParams,
},
searchParams: new URLSearchParams(searchParams.toString()),
searchParams: filterEmbedParameter(searchParams, isEmbed),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of making it embed specific we should handle removing the param in getBookingRedirectExtraParams and unit test that function as that function has the responidbility of building what params to send

});

newSearchParams.forEach((value, key) => {
Expand Down
Loading