mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-30 01:42:29 +03:00
bf134efa1f
no issue - relocated the screen-specific modals from `modals/` to `members/modals/` directory as part of a on-going reorganisation of components into screen-specific directories
61 lines
1.6 KiB
JavaScript
61 lines
1.6 KiB
JavaScript
import Component from '@glimmer/component';
|
|
import {action} from '@ember/object';
|
|
import {inject as service} from '@ember/service';
|
|
import {task} from 'ember-concurrency';
|
|
import {tracked} from '@glimmer/tracking';
|
|
|
|
export default class BulkAddMembersLabelModal extends Component {
|
|
@service ajax;
|
|
@service ghostPaths;
|
|
|
|
@tracked error;
|
|
@tracked response;
|
|
@tracked selectedLabel;
|
|
|
|
get isDisabled() {
|
|
return !this.args.data.query || !this.selectedLabel;
|
|
}
|
|
|
|
get hasRun() {
|
|
return !!(this.error || this.response);
|
|
}
|
|
|
|
@action
|
|
setLabel(label) {
|
|
this.selectedLabel = label;
|
|
}
|
|
|
|
@task({drop: true})
|
|
*addLabelTask() {
|
|
try {
|
|
const query = new URLSearchParams(this.args.data.query);
|
|
const addLabelUrl = `${this.ghostPaths.url.api('members/bulk')}?${query}`;
|
|
const response = yield this.ajax.put(addLabelUrl, {
|
|
data: {
|
|
bulk: {
|
|
action: 'addLabel',
|
|
meta: {
|
|
label: {
|
|
id: this.selectedLabel
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
this.args.data.onComplete?.();
|
|
|
|
this.response = response?.bulk?.meta;
|
|
|
|
return true;
|
|
} catch (e) {
|
|
if (e.payload?.errors) {
|
|
this.error = e.payload.errors[0].message;
|
|
} else {
|
|
this.error = 'An unknown error occurred. Please try again.';
|
|
}
|
|
throw e;
|
|
}
|
|
}
|
|
}
|