Added portal products handling (#151)

refs https://github.com/TryGhost/Team/issues/768

- handles new `portal_products` to filter products shown on Portal UI (behind the flag for multiple products)
This commit is contained in:
Rishabh Garg 2021-06-21 14:37:53 +05:30 committed by GitHub
parent fda3726b93
commit a8f6ea6aa9
4 changed files with 19 additions and 2 deletions

View File

@ -211,6 +211,7 @@ export default class App extends React.Component {
const allowedPlans = [];
let portalPrices;
let portalProducts = [];
let monthlyPrice, yearlyPrice, currency;
// Handle the query params key/value pairs
for (let pair of qsParams.entries()) {
@ -228,6 +229,8 @@ export default class App extends React.Component {
allowedPlans.push('yearly');
} else if (key === 'portalPrices') {
portalPrices = value ? value.split(',') : [];
} else if (key === 'portalProducts') {
portalProducts = value ? value.split(',') : [];
} else if (key === 'page' && value) {
data.page = value;
} else if (key === 'accentColor' && (value === '' || value)) {
@ -258,6 +261,7 @@ export default class App extends React.Component {
}
}
data.site.portal_plans = allowedPlans;
data.site.portal_products = portalProducts;
if (portalPrices) {
data.site.portal_plans = portalPrices;
} else if (monthlyPrice && yearlyPrice && currency) {

View File

@ -459,6 +459,11 @@ function ProductsSection({onPlanSelect, products}) {
if (!portalPlans.includes('monthly') && !portalPlans.includes('yearly')) {
return null;
}
if (products.length === 0) {
return null;
}
return (
<ProductsContext.Provider value={{
selectedInterval: activeInterval,

View File

@ -191,6 +191,7 @@ export const site = {
yearly: 150000,
currency: 'USD'
},
portal_products: ['product_1', 'product_2', 'product_3'],
products,
prices,
allow_self_signup: false,

View File

@ -161,8 +161,15 @@ export function getSiteProducts({site = {}}) {
}
export function getAllProducts({site}) {
const products = getSiteProducts({site});
if (hasFreeProduct({site})) {
const {portal_products: portalProducts} = site;
const siteProducts = getSiteProducts({site});
const products = getSiteProducts({site}).filter((product) => {
if (portalProducts && siteProducts.length > 1) {
return portalProducts.includes(product.id);
}
return true;
});
if (hasFreeProduct({site}) && products.length > 0) {
products.unshift({
id: 'free'
});