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() {
|
2022-05-16 18:25:03 +03:00
|
|
|
return [{
|
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'
|
2022-05-16 18:25:03 +03:00
|
|
|
}, {
|
|
|
|
name: 'Specific tier(s)',
|
|
|
|
description: 'Members with any of the selected tiers',
|
|
|
|
value: 'tiers',
|
|
|
|
icon: 'members-segment',
|
|
|
|
icon_color: 'yellow'
|
2021-05-14 17:44:10 +03:00
|
|
|
}];
|
2021-07-02 19:30:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
get hasVisibilityFilter() {
|
2022-05-16 18:25:03 +03:00
|
|
|
return !['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-05-11 20:11:54 +03:00
|
|
|
const tierIds = segment?.map((tier) => {
|
|
|
|
return tier.id;
|
2022-02-04 18:30:59 +03:00
|
|
|
});
|
|
|
|
this.settings.set('defaultContentVisibility', 'tiers');
|
2022-05-11 20:11:54 +03:00
|
|
|
this.settings.set('defaultContentVisibilityTiers', tierIds);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|