Skip to content

Commit

Permalink
update PB preview query param
Browse files Browse the repository at this point in the history
  • Loading branch information
accbjt committed Mar 20, 2024
1 parent 9b72933 commit 75cbab7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module.exports = {
},
ecmaVersion: 2020,
sourceType: "module",
requireConfigFile: false,
},
plugins: ["jest", "jest-dom", "jsx-a11y", "react", "react-hooks", "testing-library"],
rules: {
Expand Down
24 changes: 16 additions & 8 deletions blocks/identity-block/components/login/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -58,18 +57,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 searchParams = new URLSearchParams(window.location.search.substring(1));
const redirectUrl = redirectQueryParam || validatedLoggedInPageLoc;

// PB editor preview will redirect with the website query param.
if (searchParams.get('_website')) {
window.location = validateURL(`${redirectUrl}?_website=${searchParams.get('_website')}`);
} else {
window.location = redirectQueryParam || validatedLoggedInPageLoc;
}
}
}
};
if (Identity && !isAdmin) {
checkLoggedInStatus();
}
}, [Identity, redirectQueryParam, loggedInPageLocation, isAdmin]);
}, [Identity, redirectQueryParam, loggedInPageLocation, isAdmin, loginByOIDC, isOIDC]);

return {
loginRedirect: redirectQueryParam || redirectToURL,
Expand Down
8 changes: 6 additions & 2 deletions blocks/identity-block/components/login/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ describe("useLogin()", () => {
beforeEach(() => {
Object.defineProperty(window, "location", {
writable: true,
value: {
href: 'http://localhost',
search: ''
}
});
useIdentity.mockImplementation(() => ({
isInitialized: true,
Expand Down Expand Up @@ -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(<Test />);
fireEvent.click(screen.getByRole("button"));
expect(window.location).toBe(referrerURL);
expect(window.location).toBe("/article/1234");
delete document.referrer;
});

Expand Down
2 changes: 1 addition & 1 deletion blocks/subscriptions-block/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,6 @@

@media (min-width: 320px) and (max-width: 480px) {
.b-paywall__overlay {
top: initial;
inset-block-start: initial;
}
}

0 comments on commit 75cbab7

Please sign in to comment.