This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/plugins/chat/assets/javascripts/discourse/components/chat-channel-delete-modal-inner.js
Roman Rizzi 0a5f548635
DEV: Move discourse-chat to the core repo. (#18776)
As part of this move, we are also renaming `discourse-chat` to `chat`.
2022-11-02 10:41:30 -03:00

69 lines
1.9 KiB
JavaScript

import Component from "@ember/component";
import { isEmpty } from "@ember/utils";
import I18n from "I18n";
import discourseComputed from "discourse-common/utils/decorators";
import { action } from "@ember/object";
import { ajax } from "discourse/lib/ajax";
import { inject as service } from "@ember/service";
import { popupAjaxError } from "discourse/lib/ajax-error";
import discourseLater from "discourse-common/lib/later";
import { htmlSafe } from "@ember/template";
export default Component.extend({
chat: service(),
router: service(),
tagName: "",
chatChannel: null,
channelNameConfirmation: null,
deleting: false,
confirmed: false,
@discourseComputed("deleting", "channelNameConfirmation", "confirmed")
buttonDisabled(deleting, channelNameConfirmation, confirmed) {
if (deleting || confirmed) {
return true;
}
if (
isEmpty(channelNameConfirmation) ||
channelNameConfirmation.toLowerCase() !==
this.chatChannel.title.toLowerCase()
) {
return true;
}
return false;
},
@action
deleteChannel() {
this.set("deleting", true);
return ajax(`/chat/chat_channels/${this.chatChannel.id}.json`, {
method: "DELETE",
data: { channel_name_confirmation: this.channelNameConfirmation },
})
.then(() => {
this.set("confirmed", true);
this.appEvents.trigger("modal-body:flash", {
text: I18n.t("chat.channel_delete.process_started"),
messageClass: "success",
});
discourseLater(() => {
this.closeModal();
this.router.transitionTo("chat");
}, 3000);
})
.catch(popupAjaxError)
.finally(() => this.set("deleting", false));
},
@discourseComputed()
instructionsText() {
return htmlSafe(
I18n.t("chat.channel_delete.instructions", {
name: this.chatChannel.escapedTitle,
})
);
},
});