Joffrey JAFFEUX f29b956339
DEV: introduces documentation for chat ()
Note this commit also slightly changes internal API: channel instead of getChannel and updateCurrentUserChannelNotificationsSettings instead of updateCurrentUserChatChannelNotificationsSettings.

Also destroyChannel takes a second param which is the name confirmation instead of an optional object containing this confirmation. This is to enforce the fact that it's required.

In the future a top level jsdoc config file could be used instead of the hack tempfile, but while it's only an experiment for chat, it's probably good enough.
2023-01-18 12:36:16 +01:00

66 lines
1.8 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 { 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";
import ModalFunctionality from "discourse/mixins/modal-functionality";
export default Component.extend(ModalFunctionality, {
chat: service(),
chatApi: 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 this.chatApi
.destroyChannel(this.chatChannel.id, this.channelNameConfirmation)
.then(() => {
this.set("confirmed", true);
this.flash(I18n.t("chat.channel_delete.process_started"), "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,
})
);
},
});