Ghost/ghost/admin/app/components/settings/members-default-post-access.js
Rishabh 450ad78f61 Added custom segment option for default post access setting
refs https://github.com/TryGhost/Team/issues/803

With multiple products we'll re-enable segmentation by product for posts, which also means need to add a new option to the default post access setting in Membership settings. This change -

- adds new `A segment` option to default post access dropdown behind the alpha flag for multiple products
- shows member segment select dropdown for `A segment` option
- handles update of `defaultContentVisibility` to allow setting custom filter
2021-07-05 17:14:26 +05:30

73 lines
2.4 KiB
JavaScript

import Component from '@glimmer/component';
import {action} from '@ember/object';
import {inject as service} from '@ember/service';
export default class SettingsMembersDefaultPostAccess extends Component {
@service settings;
@service feature;
get options() {
const defaultOptions = [{
name: 'Public',
description: 'All site visitors to your site, no login required',
value: 'public',
icon: 'globe',
icon_color: 'green'
}, {
name: 'Members only',
description: 'All logged-in members',
value: 'members',
icon: 'members-all',
icon_color: 'blue'
}, {
name: 'Paid-members only',
description: 'Only logged-in members with an active Stripe subscription',
value: 'paid',
icon: 'members-paid',
icon_color: 'pink'
}];
if (this.feature.get('multipleProducts')) {
defaultOptions.push({
name: 'A segment',
description: 'Members with any of the selected products',
value: 'filter',
icon: 'members-paid',
icon_color: 'yellow'
});
}
return defaultOptions;
}
get hasVisibilityFilter() {
return this.feature.get('multipleProducts') && !['public', 'members', 'paid'].includes(this.settings.get('defaultContentVisibility'));
}
get selectedOption() {
if (this.settings.get('membersSignupAccess') === 'none') {
return this.options.find(o => o.value === 'public');
}
if (!['public', 'members', 'paid'].includes(this.settings.get('defaultContentVisibility'))) {
return this.options.find(o => o.value === 'filter');
}
return this.options.find(o => o.value === this.settings.get('defaultContentVisibility'));
}
@action
setVisibility(segment) {
if (segment) {
this.settings.set('defaultContentVisibility', segment);
}
}
@action
setDefaultContentVisibility(option) {
if (this.settings.get('membersSignupAccess') !== 'none') {
if (option.value === 'filter') {
this.settings.set('defaultContentVisibility', '');
} else {
this.settings.set('defaultContentVisibility', option.value);
}
}
}
}