From f48ca1e7ad0c317e08d618e85db6c71197abcd71 Mon Sep 17 00:00:00 2001 From: Bill John Tran Date: Wed, 20 Mar 2024 10:10:57 -0700 Subject: [PATCH] add fix for redirect (#1997) * add fix for redirect * add regwall fix more mobile * update PB preview query param * remove requireConfigFile config --- .../identity-block/components/login/index.jsx | 18 ++++++++++-------- .../components/login/index.test.jsx | 8 ++++++-- blocks/subscriptions-block/_index.scss | 6 ++++++ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/blocks/identity-block/components/login/index.jsx b/blocks/identity-block/components/login/index.jsx index 1435763ee4..88a7f7fb01 100644 --- a/blocks/identity-block/components/login/index.jsx +++ b/blocks/identity-block/components/login/index.jsx @@ -22,13 +22,12 @@ const useLogin = ({ if (window?.location?.search) { const searchParams = new URLSearchParams(window.location.search.substring(1)); - //redirectURL could have additional params + // redirectURL could have additional params const params = ["paymentMethodID"]; - const aditionalParams = params.map((p) => { - const paramExist = searchParams.has(p) - if(paramExist){ - return {[p]:searchParams.get(p)} - } + const aditionalParams = params.filter((p) => { + const paramExist = searchParams.has(p); + + return paramExist; }) const fullURL = searchParams.get("redirect") ? appendURLParams(searchParams.get("redirect"), aditionalParams.filter(item => item !== undefined)) : null; @@ -37,7 +36,9 @@ const useLogin = ({ } if (redirectToPreviousPage && document?.referrer) { - setRedirectToURL(document.referrer); + const redirectUrl = new URL(document.referrer); + + setRedirectToURL(`${redirectUrl.pathname}${redirectUrl.search}`); } }, [redirectQueryParam, redirectToPreviousPage]); @@ -56,6 +57,7 @@ const useLogin = ({ const checkLoggedInStatus = async () => { const isLoggedIn = await Identity.isLoggedIn(); const validatedLoggedInPageLoc = validateURL(loggedInPageLocation); + if (isLoggedIn) { if (isOIDC) { loginByOIDC(); @@ -67,7 +69,7 @@ const useLogin = ({ if (Identity && !isAdmin) { checkLoggedInStatus(); } - }, [Identity, redirectQueryParam, loggedInPageLocation, isAdmin]); + }, [Identity, redirectQueryParam, loggedInPageLocation, isAdmin, loginByOIDC, isOIDC]); return { loginRedirect: redirectQueryParam || redirectToURL, diff --git a/blocks/identity-block/components/login/index.test.jsx b/blocks/identity-block/components/login/index.test.jsx index 55e5d5066d..f977f7076f 100644 --- a/blocks/identity-block/components/login/index.test.jsx +++ b/blocks/identity-block/components/login/index.test.jsx @@ -35,6 +35,10 @@ describe("useLogin()", () => { beforeEach(() => { Object.defineProperty(window, "location", { writable: true, + value: { + href: 'http://localhost', + search: '' + } }); useIdentity.mockImplementation(() => ({ isInitialized: true, @@ -68,14 +72,14 @@ describe("useLogin()", () => { }); it("uses document referrer", async () => { - const referrerURL = "http://referrer.com"; + const referrerURL = "http://referrer.com/article/1234"; Object.defineProperty(document, "referrer", { value: referrerURL, configurable: true, }); await render(); fireEvent.click(screen.getByRole("button")); - expect(window.location).toBe(referrerURL); + expect(window.location).toBe("/article/1234"); delete document.referrer; }); diff --git a/blocks/subscriptions-block/_index.scss b/blocks/subscriptions-block/_index.scss index 9110d00343..f58a46ee1c 100644 --- a/blocks/subscriptions-block/_index.scss +++ b/blocks/subscriptions-block/_index.scss @@ -281,3 +281,9 @@ @include scss.block-properties("paywall-subscription-dialog"); } } + +@media (min-width: 320px) and (max-width: 480px) { + .b-paywall__overlay { + inset-block-start: initial; + } +} \ No newline at end of file