diff --git a/.eslintrc.js b/.eslintrc.js index d80f5305e..482f7b690 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -29,6 +29,7 @@ module.exports = { }, ecmaVersion: 2020, sourceType: "module", + requireConfigFile: false, }, plugins: ["jest", "jest-dom", "jsx-a11y", "react", "react-hooks", "testing-library"], rules: { diff --git a/blocks/identity-block/components/login/index.jsx b/blocks/identity-block/components/login/index.jsx index 3e0cbcd30..0493e7c3f 100644 --- a/blocks/identity-block/components/login/index.jsx +++ b/blocks/identity-block/components/login/index.jsx @@ -22,13 +22,15 @@ 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 aditionalParams = params.filter((p) => { const paramExist = searchParams.has(p) if(paramExist){ return {[p]:searchParams.get(p)} } + + return null; }) const fullURL = searchParams.get("redirect") ? appendURLParams(searchParams.get("redirect"), aditionalParams.filter(item => item !== undefined)) : null; @@ -58,18 +60,27 @@ const useLogin = ({ const checkLoggedInStatus = async () => { const isLoggedIn = await Identity.isLoggedIn(); const validatedLoggedInPageLoc = validateURL(loggedInPageLocation); + if (isLoggedIn) { if (isOIDC) { loginByOIDC(); } else { - window.location = redirectQueryParam || validatedLoggedInPageLoc; + const curentUrl = new URL(window.location.href); + const redirectUrl = redirectQueryParam || validatedLoggedInPageLoc; + + // PB editor preview will redirect with the website query param. + if (curentUrl.searchParams.get('_website')) { + window.location = `${redirectUrl}?_website=${curentUrl.searchParams.get('_website')}`; + } else { + window.location = redirectUrl; + } } } }; 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 55e5d5066..77654e170 100644 --- a/blocks/identity-block/components/login/index.test.jsx +++ b/blocks/identity-block/components/login/index.test.jsx @@ -35,6 +35,9 @@ describe("useLogin()", () => { beforeEach(() => { Object.defineProperty(window, "location", { writable: true, + value: { + href: 'http://localhost', + } }); useIdentity.mockImplementation(() => ({ isInitialized: true, @@ -68,14 +71,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 6c2b55527..f58a46ee1 100644 --- a/blocks/subscriptions-block/_index.scss +++ b/blocks/subscriptions-block/_index.scss @@ -284,6 +284,6 @@ @media (min-width: 320px) and (max-width: 480px) { .b-paywall__overlay { - top: initial; + inset-block-start: initial; } } \ No newline at end of file