Ghost/ghost/admin/app/components/gh-members-segment-count.js
Kevin Ansfield 0caa539330 Added label and product options for email recipients (#1947)
refs https://github.com/TryGhost/Team/issues/581
requires https://github.com/TryGhost/Ghost/pull/12932

- added segment option and select to default newsletter recipients setting
- updated segment selector to fetch labels/products and show as options
- updated segment selector and count component to call an action when count changes so we can use it in the email confirmation modal
- removed usage and mapping of older `'none'`, `'all'`, `'free'`, and `'paid'` email recipient filter values
2021-05-07 11:58:05 +01:00

34 lines
1009 B
JavaScript

import Component from '@glimmer/component';
import {inject as service} from '@ember/service';
import {task, taskGroup} from 'ember-concurrency-decorators';
import {tracked} from '@glimmer/tracking';
export default class GhMembersSegmentCountComponent extends Component {
@service store;
@service session;
@tracked total = 0;
@tracked segmentTotal = 0;
@taskGroup fetchTasks;
@task({group: 'fetchTasks'})
*fetchTotalsTask() {
this.fetchSegmentTotalTask.perform();
const members = yield this.store.query('member', {limit: 1});
this.total = members.meta.pagination.total;
}
@task({group: 'fetchTasks'})
*fetchSegmentTotalTask() {
if (!this.args.segment) {
return this.segmentTotal = 0;
}
const members = yield this.store.query('member', {limit: 1, filter: this.args.segment});
this.segmentTotal = members.meta.pagination.total;
this.args.onSegmentCountChange?.(this.segmentTotal);
}
}