mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-29 13:52:10 +03:00
🐛 Fixed broken portal link for yearly tier price signup
closes https://github.com/TryGhost/Team/issues/1142 Portal signup URLs for yearly plans of a tier were broken and resulted in "Failed to signup error", due to incorrect parsing of the yearly query. - fixes regex for parsing yearly price id for tiers from portal url - adds unit test to cover parsing of price id from page query
This commit is contained in:
parent
2c49e37170
commit
2536204c71
@ -10,7 +10,7 @@ import * as Fixtures from './utils/fixtures';
|
||||
import ActionHandler from './actions';
|
||||
import './App.css';
|
||||
import NotificationParser from './utils/notifications';
|
||||
import {createPopupNotification, getAvailablePrices, getCurrencySymbol, getFirstpromoterId, getProductFromId, getQueryPrice, getSiteDomain, isComplimentaryMember, isInviteOnlySite, isSentryEventAllowed, removePortalLinkFromUrl} from './utils/helpers';
|
||||
import {createPopupNotification, getAvailablePrices, getCurrencySymbol, getFirstpromoterId, getPriceIdFromPageQuery, getQueryPrice, getSiteDomain, isComplimentaryMember, isInviteOnlySite, isSentryEventAllowed, removePortalLinkFromUrl} from './utils/helpers';
|
||||
|
||||
const handleDataAttributes = require('./data-attributes');
|
||||
const React = require('react');
|
||||
@ -334,7 +334,7 @@ export default class App extends React.Component {
|
||||
/** Fetch state from Portal Links */
|
||||
fetchLinkData() {
|
||||
const productMonthlyPriceQueryRegex = /^(?:(\w+?))?\/monthly$/;
|
||||
const productYearlyPriceQueryRegex = /^(?:(\w+?))?\/monthly$/;
|
||||
const productYearlyPriceQueryRegex = /^(?:(\w+?))?\/yearly$/;
|
||||
const offersRegex = /^offers\/(\w+?)\/?$/;
|
||||
const [path] = window.location.hash.substr(1).split('?');
|
||||
const linkRegex = /^\/portal\/?(?:\/(\w+(?:\/\w+)*))?\/?$/;
|
||||
@ -530,22 +530,15 @@ export default class App extends React.Component {
|
||||
|
||||
/** Handle direct signup link for a price */
|
||||
handleSignupQuery({site, pageQuery}) {
|
||||
const productMonthlyPriceQueryRegex = /^(?:(\w+?))?\/monthly$/;
|
||||
const productYearlyPriceQueryRegex = /^(?:(\w+?))?\/monthly$/;
|
||||
const offerQueryRegex = /^offers\/(\w+?)\/?$/;
|
||||
let priceId = pageQuery;
|
||||
if (offerQueryRegex.test(pageQuery || '')) {
|
||||
const [, offerId] = pageQuery.match(offerQueryRegex);
|
||||
this.handleOfferQuery({site, offerId});
|
||||
return;
|
||||
} else if (productMonthlyPriceQueryRegex.test(pageQuery || '')) {
|
||||
const [, productId] = pageQuery.match(productMonthlyPriceQueryRegex);
|
||||
const product = getProductFromId({site, productId});
|
||||
priceId = product?.monthlyPrice?.id;
|
||||
} else if (productYearlyPriceQueryRegex.test(pageQuery || '')) {
|
||||
const [, productId] = pageQuery.match(productYearlyPriceQueryRegex);
|
||||
const product = getProductFromId({site, productId});
|
||||
priceId = product?.yearlyPrice?.id;
|
||||
}
|
||||
if (getPriceIdFromPageQuery({site, pageQuery})) {
|
||||
priceId = getPriceIdFromPageQuery({site, pageQuery});
|
||||
}
|
||||
const queryPrice = getQueryPrice({site: site, priceId});
|
||||
if (!this.state.member
|
||||
|
@ -492,3 +492,19 @@ export const createPopupNotification = ({type, status, autoHide, duration, close
|
||||
count
|
||||
};
|
||||
};
|
||||
|
||||
export function getPriceIdFromPageQuery({site, pageQuery}) {
|
||||
const productMonthlyPriceQueryRegex = /^(?:(\w+?))?\/monthly$/;
|
||||
const productYearlyPriceQueryRegex = /^(?:(\w+?))?\/yearly$/;
|
||||
|
||||
if (productMonthlyPriceQueryRegex.test(pageQuery || '')) {
|
||||
const [, productId] = pageQuery.match(productMonthlyPriceQueryRegex);
|
||||
const product = getProductFromId({site, productId});
|
||||
return product?.monthlyPrice?.id;
|
||||
} else if (productYearlyPriceQueryRegex.test(pageQuery || '')) {
|
||||
const [, productId] = pageQuery.match(productYearlyPriceQueryRegex);
|
||||
const product = getProductFromId({site, productId});
|
||||
return product?.yearlyPrice?.id;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
10
ghost/portal/src/utils/helpers.test.js
Normal file
10
ghost/portal/src/utils/helpers.test.js
Normal file
@ -0,0 +1,10 @@
|
||||
import {getPriceIdFromPageQuery} from './helpers';
|
||||
import {site} from './fixtures';
|
||||
|
||||
describe('Helpers - ', () => {
|
||||
test('can correctly fetch price id from page query ', () => {
|
||||
const mockPriceIdFn = jest.fn(getPriceIdFromPageQuery);
|
||||
const value = mockPriceIdFn({site, pageQuery: 'product_1/yearly'});
|
||||
expect(value).toBe('6086eff0823dd7345afc8083');
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user