mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-25 09:03:12 +03:00
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:
parent
fda3726b93
commit
a8f6ea6aa9
@ -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) {
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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'
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user