DEV: Convert group-default-notifications modal to component-based API (#22521)
This PR converts the `group-default-notifications` modal to make use of the new component-based API
This commit is contained in:
parent
80a1709965
commit
bdaecc90c4
|
@ -7,7 +7,7 @@
|
|||
{{/if}}
|
||||
<div class="control-group buttons group-manage-save-button">
|
||||
<DButton
|
||||
@action={{action "save"}}
|
||||
@action={{this.save}}
|
||||
@disabled={{or this.disabled this.saving}}
|
||||
@class="btn btn-primary group-manage-save"
|
||||
@translatedLabel={{this.savingText}}
|
||||
|
|
|
@ -3,10 +3,13 @@ import I18n from "I18n";
|
|||
import discourseComputed from "discourse-common/utils/decorators";
|
||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||
import { popupAutomaticMembershipAlert } from "discourse/controllers/groups-new";
|
||||
import showModal from "discourse/lib/show-modal";
|
||||
import { or } from "@ember/object/computed";
|
||||
import { action } from "@ember/object";
|
||||
import { inject as service } from "@ember/service";
|
||||
import GroupDefaultNotificationsModal from "discourse/components/modal/group-default-notifications";
|
||||
|
||||
export default Component.extend({
|
||||
modal: service(),
|
||||
saving: null,
|
||||
disabled: false,
|
||||
updateExistingUsers: null,
|
||||
|
@ -38,7 +41,12 @@ export default Component.extend({
|
|||
}
|
||||
},
|
||||
|
||||
actions: {
|
||||
@action
|
||||
setUpdateExistingUsers(value) {
|
||||
this.updateExistingUsers = value;
|
||||
},
|
||||
|
||||
@action
|
||||
save() {
|
||||
if (this.beforeSave) {
|
||||
this.beforeSave();
|
||||
|
@ -72,19 +80,22 @@ export default Component.extend({
|
|||
.catch((error) => {
|
||||
const json = error.jqXHR.responseJSON;
|
||||
if (error.jqXHR.status === 422 && json.user_count) {
|
||||
const controller = showModal("group-default-notifications", {
|
||||
model: { count: json.user_count },
|
||||
});
|
||||
|
||||
controller.set("onClose", () => {
|
||||
this.updateExistingUsers = controller.updateExistingUsers;
|
||||
this.send("save");
|
||||
});
|
||||
this.editGroupNotifications(json);
|
||||
} else {
|
||||
popupAjaxError(error);
|
||||
}
|
||||
})
|
||||
.finally(() => this.set("saving", false));
|
||||
},
|
||||
|
||||
@action
|
||||
async editGroupNotifications(json) {
|
||||
await this.modal.show(GroupDefaultNotificationsModal, {
|
||||
model: {
|
||||
count: json.user_count,
|
||||
setUpdateExistingUsers: this.setUpdateExistingUsers,
|
||||
},
|
||||
});
|
||||
this.save();
|
||||
},
|
||||
});
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
<DModal
|
||||
@title={{i18n "groups.default_notifications.modal_title"}}
|
||||
@closeModal={{@closeModal}}
|
||||
>
|
||||
<:body>
|
||||
{{i18n "groups.default_notifications.modal_description" count=@model.count}}
|
||||
</:body>
|
||||
<:footer>
|
||||
<DButton
|
||||
@action={{this.updateExistingUsers}}
|
||||
@label="groups.default_notifications.modal_yes"
|
||||
class="btn-primary"
|
||||
/>
|
||||
<DButton
|
||||
@action={{this.cancel}}
|
||||
@label="groups.default_notifications.modal_no"
|
||||
/>
|
||||
</:footer>
|
||||
</DModal>
|
|
@ -0,0 +1,16 @@
|
|||
import Component from "@glimmer/component";
|
||||
import { action } from "@ember/object";
|
||||
|
||||
export default class GroupDefaultNotifications extends Component {
|
||||
@action
|
||||
updateExistingUsers() {
|
||||
this.args.model.setUpdateExistingUsers(true);
|
||||
this.args.closeModal();
|
||||
}
|
||||
|
||||
@action
|
||||
cancel() {
|
||||
this.args.model.setUpdateExistingUsers(false);
|
||||
this.args.closeModal();
|
||||
}
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
import Controller from "@ember/controller";
|
||||
import ModalFunctionality from "discourse/mixins/modal-functionality";
|
||||
import ModalUpdateExistingUsers from "discourse/mixins/modal-update-existing-users";
|
||||
|
||||
export default Controller.extend(ModalFunctionality, ModalUpdateExistingUsers);
|
|
@ -1,18 +0,0 @@
|
|||
<DModalBody @title="groups.default_notifications.modal_title">
|
||||
{{i18n
|
||||
"groups.default_notifications.modal_description"
|
||||
count=this.model.count
|
||||
}}
|
||||
</DModalBody>
|
||||
|
||||
<div class="modal-footer">
|
||||
<DButton
|
||||
@action={{action "updateExistingUsers"}}
|
||||
@class="btn-primary"
|
||||
@label="groups.default_notifications.modal_yes"
|
||||
/>
|
||||
<DButton
|
||||
@action={{action "cancel"}}
|
||||
@label="groups.default_notifications.modal_no"
|
||||
/>
|
||||
</div>
|
Loading…
Reference in New Issue