2021-05-14 17:01:50 +03:00
|
|
|
import Component from '@glimmer/component';
|
|
|
|
import {action} from '@ember/object';
|
|
|
|
import {inject as service} from '@ember/service';
|
2021-07-16 16:01:23 +03:00
|
|
|
import {tracked} from '@glimmer/tracking';
|
2021-05-14 17:01:50 +03:00
|
|
|
|
|
|
|
export default class SettingsMembersDefaultPostAccess extends Component {
|
|
|
|
@service settings;
|
2021-07-02 19:30:14 +03:00
|
|
|
@service feature;
|
2021-07-16 16:01:23 +03:00
|
|
|
@tracked showSegmentError;
|
2021-05-14 17:01:50 +03:00
|
|
|
|
2021-05-14 17:44:10 +03:00
|
|
|
get options() {
|
2021-07-02 19:30:14 +03:00
|
|
|
const defaultOptions = [{
|
2021-05-14 17:44:10 +03:00
|
|
|
name: 'Public',
|
|
|
|
description: 'All site visitors to your site, no login required',
|
2021-05-17 11:42:44 +03:00
|
|
|
value: 'public',
|
|
|
|
icon: 'globe',
|
|
|
|
icon_color: 'green'
|
2021-05-14 17:44:10 +03:00
|
|
|
}, {
|
|
|
|
name: 'Members only',
|
|
|
|
description: 'All logged-in members',
|
2021-05-17 11:42:44 +03:00
|
|
|
value: 'members',
|
2021-05-18 16:10:42 +03:00
|
|
|
icon: 'members-all',
|
|
|
|
icon_color: 'blue'
|
2021-05-14 17:44:10 +03:00
|
|
|
}, {
|
|
|
|
name: 'Paid-members only',
|
2021-05-17 20:36:36 +03:00
|
|
|
description: 'Only logged-in members with an active Stripe subscription',
|
2021-05-17 11:42:44 +03:00
|
|
|
value: 'paid',
|
2021-05-18 16:10:42 +03:00
|
|
|
icon: 'members-paid',
|
|
|
|
icon_color: 'pink'
|
2021-05-14 17:44:10 +03:00
|
|
|
}];
|
2021-07-02 19:30:14 +03:00
|
|
|
if (this.feature.get('multipleProducts')) {
|
|
|
|
defaultOptions.push({
|
2021-08-20 13:14:37 +03:00
|
|
|
name: 'Specific tier(s)',
|
2021-07-19 13:38:51 +03:00
|
|
|
description: 'Members with any of the selected tiers',
|
2022-02-04 18:30:59 +03:00
|
|
|
value: 'tiers',
|
2021-07-06 15:46:33 +03:00
|
|
|
icon: 'members-segment',
|
2021-07-02 19:30:14 +03:00
|
|
|
icon_color: 'yellow'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return defaultOptions;
|
|
|
|
}
|
|
|
|
|
|
|
|
get hasVisibilityFilter() {
|
|
|
|
return this.feature.get('multipleProducts') && !['public', 'members', 'paid'].includes(this.settings.get('defaultContentVisibility'));
|
2021-05-14 17:44:10 +03:00
|
|
|
}
|
2021-05-14 17:01:50 +03:00
|
|
|
|
2022-02-04 18:30:59 +03:00
|
|
|
get visibilityTiers() {
|
|
|
|
const visibilityTiersData = this.settings.get('defaultContentVisibilityTiers');
|
2022-02-19 01:36:01 +03:00
|
|
|
return (visibilityTiersData || []).map((id) => {
|
2022-02-04 18:30:59 +03:00
|
|
|
return {id};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-05-14 17:44:10 +03:00
|
|
|
get selectedOption() {
|
|
|
|
if (this.settings.get('membersSignupAccess') === 'none') {
|
|
|
|
return this.options.find(o => o.value === 'public');
|
|
|
|
}
|
2022-02-04 18:30:59 +03:00
|
|
|
|
2021-05-14 17:44:10 +03:00
|
|
|
return this.options.find(o => o.value === this.settings.get('defaultContentVisibility'));
|
2021-05-14 17:01:50 +03:00
|
|
|
}
|
|
|
|
|
2021-07-02 19:30:14 +03:00
|
|
|
@action
|
|
|
|
setVisibility(segment) {
|
|
|
|
if (segment) {
|
2022-02-04 18:30:59 +03:00
|
|
|
const productIds = segment?.map((product) => {
|
|
|
|
return product.id;
|
|
|
|
});
|
|
|
|
this.settings.set('defaultContentVisibility', 'tiers');
|
|
|
|
this.settings.set('defaultContentVisibilityTiers', productIds);
|
2021-07-16 16:01:23 +03:00
|
|
|
this.showSegmentError = false;
|
|
|
|
} else {
|
|
|
|
this.settings.set('defaultContentVisibility', '');
|
|
|
|
this.showSegmentError = true;
|
2021-07-02 19:30:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-14 17:01:50 +03:00
|
|
|
@action
|
2021-05-14 17:44:10 +03:00
|
|
|
setDefaultContentVisibility(option) {
|
2021-05-14 17:01:50 +03:00
|
|
|
if (this.settings.get('membersSignupAccess') !== 'none') {
|
2022-02-04 18:30:59 +03:00
|
|
|
this.settings.set('defaultContentVisibility', option.value);
|
|
|
|
if (option.value === 'tiers') {
|
|
|
|
this.settings.set('defaultContentVisibilityTiers', []);
|
2021-07-02 19:30:14 +03:00
|
|
|
}
|
2021-05-14 17:01:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|