FIX: Resolve computed property override when inviting to PM (#24823)

This was raising a deprecation under Ember 3, and an error under Ember 4+
This commit is contained in:
David Taylor 2023-12-11 15:39:50 +00:00 committed by GitHub
parent dacb06842e
commit b5fb8e89eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 17 deletions

View File

@ -267,8 +267,11 @@ export default Component.extend({
}
},
@discourseComputed("isPM")
errorMessage(isPM) {
@discourseComputed("isPM", "ajaxError")
errorMessage(isPM, ajaxError) {
if (ajaxError) {
return ajaxError;
}
return isPM
? I18n.t("topic.invite_private.error")
: I18n.t("topic.invite_reply.error");
@ -326,14 +329,9 @@ export default Component.extend({
const onerror = (e) => {
if (e.jqXHR.responseJSON && e.jqXHR.responseJSON.errors) {
this.set("errorMessage", e.jqXHR.responseJSON.errors[0]);
this.set("ajaxError", e.jqXHR.responseJSON.errors[0]);
} else {
this.set(
"errorMessage",
this.isPM
? I18n.t("topic.invite_private.error")
: I18n.t("topic.invite_reply.error")
);
this.set("ajaxError", null);
}
model.setProperties({ saving: false, error: true });
};
@ -397,14 +395,9 @@ export default Component.extend({
})
.catch((e) => {
if (e.jqXHR.responseJSON && e.jqXHR.responseJSON.errors) {
this.set("errorMessage", e.jqXHR.responseJSON.errors[0]);
this.set("ajaxError", e.jqXHR.responseJSON.errors[0]);
} else {
this.set(
"errorMessage",
this.isPM
? I18n.t("topic.invite_private.error")
: I18n.t("topic.invite_reply.error")
);
this.set("ajaxError", null);
}
model.setProperties({ saving: false, error: true });
});

View File

@ -13,6 +13,7 @@ import {
query,
} from "discourse/tests/helpers/qunit-helpers";
import I18n from "discourse-i18n";
import selectKit from "../helpers/select-kit-helper";
acceptance("Personal Message", function (needs) {
needs.user();
@ -75,8 +76,19 @@ acceptance("Personal Message (regular user)", function (needs) {
acceptance("Personal Message - invite", function (needs) {
needs.user();
needs.pretender((server, helper) => {
server.get("/u/search/users", () =>
helper.response({ users: [{ username: "example" }] })
);
test("suggested messages", async function (assert) {
server.post("/t/12/invite", () =>
helper.response(422, {
errors: ["Some validation error"],
})
);
});
test("can open invite modal", async function (assert) {
await visit("/t/pm-for-testing/12");
await click(".add-remove-participant-btn");
await click(".private-message-map .controls .add-participant-btn");
@ -85,4 +97,23 @@ acceptance("Personal Message - invite", function (needs) {
.dom(".d-modal.add-pm-participants .invite-user-control")
.exists("invite modal is displayed");
});
test("shows errors correctly", async function (assert) {
await visit("/t/pm-for-testing/12");
await click(".add-remove-participant-btn");
await click(".private-message-map .controls .add-participant-btn");
assert
.dom(".d-modal.add-pm-participants .invite-user-control")
.exists("invite modal is displayed");
const input = selectKit(".invite-user-input");
await input.expand();
await input.fillInFilter("example");
await input.selectRowByValue("example");
await click(".send-invite");
assert.dom(".d-modal.add-pm-participants .alert-error").exists();
});
});