2023-04-19 18:45:34 +03:00
|
|
|
import Component from '@glimmer/component';
|
|
|
|
import {action} from '@ember/object';
|
|
|
|
import {inject as service} from '@ember/service';
|
|
|
|
|
|
|
|
export default class AnnouncementSettingsVisibilityComponent extends Component {
|
|
|
|
@service settings;
|
2023-04-21 11:49:29 +03:00
|
|
|
@service membersUtils;
|
2023-04-19 18:45:34 +03:00
|
|
|
|
2023-04-21 11:49:29 +03:00
|
|
|
visibilityOptions = {
|
|
|
|
freeMembers: 'free_members',
|
|
|
|
paidMembers: 'paid_members',
|
|
|
|
visitors: 'visitors'
|
|
|
|
};
|
|
|
|
|
|
|
|
get visibilitySettings() {
|
2023-05-05 13:11:26 +03:00
|
|
|
return this.settings.announcementVisibility || [];
|
2023-04-19 18:45:34 +03:00
|
|
|
}
|
|
|
|
|
2023-04-21 11:49:29 +03:00
|
|
|
get isPaidAvailable() {
|
|
|
|
return this.membersUtils.isStripeEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
get isFreeMembersChecked() {
|
|
|
|
return this.visibilitySettings.includes(this.visibilityOptions.freeMembers);
|
|
|
|
}
|
|
|
|
|
|
|
|
get isPaidMembersChecked() {
|
|
|
|
return this.visibilitySettings.includes(this.visibilityOptions.paidMembers);
|
|
|
|
}
|
|
|
|
|
|
|
|
get isVisitorsChecked() {
|
|
|
|
return this.visibilitySettings.includes(this.visibilityOptions.visitors);
|
2023-04-19 18:45:34 +03:00
|
|
|
}
|
|
|
|
|
2023-04-26 16:39:25 +03:00
|
|
|
get isMembersEnabled() {
|
|
|
|
return this.settings.membersEnabled;
|
|
|
|
}
|
|
|
|
|
2023-04-19 18:45:34 +03:00
|
|
|
@action
|
2023-04-21 11:49:29 +03:00
|
|
|
updateVisibility(event) {
|
|
|
|
let updatedVisibilityOptions = [...this.visibilitySettings];
|
|
|
|
const value = event.target.value;
|
|
|
|
|
|
|
|
if (event.target.checked) {
|
|
|
|
updatedVisibilityOptions.push(value);
|
|
|
|
} else {
|
|
|
|
updatedVisibilityOptions = updatedVisibilityOptions.filter(item => item !== value);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.settings.announcementVisibility = updatedVisibilityOptions;
|
2023-04-27 15:40:11 +03:00
|
|
|
// update preview if there are no visibility options or just one to avoid update flickering on every check
|
|
|
|
if (!updatedVisibilityOptions.length || updatedVisibilityOptions.length === 1) {
|
|
|
|
this.args.onChange?.();
|
|
|
|
}
|
2023-04-19 18:45:34 +03:00
|
|
|
}
|
|
|
|
}
|