mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 01:41:46 +03:00
85d7932e45
refs https://github.com/TryGhost/Team/issues/559
refs 054a5f15f5
- with the update of `ember-promise-modals` we started to get deprecation warnings when using `modals.open('modal-component-name')`
- upcoming Ember build updates will introduce tree shaking but using run-time lookup of modal components by name works against that because it's not statically analysable
- switched to importing components and passing the component class directly, eg. `modals.open(ModalComponent)`
- standardized modal component class names with a `MyModal` style to get better behaviour in code editors when it auto generates imports
- dropped the modal defaults from the modals service because we can now use a static `modalOptions` property on the modal components themselves when we want to override the defaults
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 BulkRemoveMembersLabelModal 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})
|
|
*removeLabelTask() {
|
|
try {
|
|
const query = new URLSearchParams(this.args.data.query);
|
|
const removeLabelUrl = `${this.ghostPaths.url.api('members/bulk')}?${query}`;
|
|
const response = yield this.ajax.put(removeLabelUrl, {
|
|
data: {
|
|
bulk: {
|
|
action: 'removeLabel',
|
|
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;
|
|
}
|
|
}
|
|
}
|