Ghost/ghost/admin/app/components/gh-members-segment-select.js
Kevin Ansfield da49dc4922 Added default newsletter recipients setting (#1946)
refs https://github.com/TryGhost/Team/issues/496
reqs https://github.com/TryGhost/Ghost/pull/12925

The publish menu was meant to default to matching post visibility but that wasn't working consistently and didn't make sense for sites which don't email every post to their members.

A "Default newsletter recipients" option has been added to the "Email newsletter" settings screen and the publish menu updated to reflect the option. The free/paid toggles in the publish menu have also been swapped out for a multi-select style component that will cater to more complex member segmentation.
2021-05-07 10:02:19 +01:00

63 lines
1.5 KiB
JavaScript

import Component from '@glimmer/component';
import {action} from '@ember/object';
import {inject as service} from '@ember/service';
import {task} from 'ember-concurrency-decorators';
import {tracked} from '@glimmer/tracking';
export default class GhMembersSegmentSelect extends Component {
@service store;
@tracked options = [];
get renderInPlace() {
return this.args.renderInPlace === undefined ? false : this.args.renderInPlace;
}
constructor() {
super(...arguments);
this.fetchOptionsTask.perform();
}
get flatOptions() {
const options = [];
function getOptions(option) {
if (option.options) {
return option.options.forEach(getOptions);
}
options.push(option);
}
this.options.forEach(getOptions);
return options;
}
get selectedOptions() {
const segments = (this.args.segment || '').split(',');
return this.flatOptions.filter(option => segments.includes(option.segment));
}
@action
setSegment(options) {
const segment = options.mapBy('segment').join(',') || null;
this.args.onChange?.(segment);
}
@task
*fetchOptionsTask() {
const options = yield [{
name: 'Free members',
segment: 'status:free',
class: 'segment-status'
}, {
name: 'Paid members',
segment: 'status:-free', // paid & comped
class: 'segment-status'
}];
this.options = options;
}
}