From bfd0c009444d1e1dddf297badd988163ff110ffa Mon Sep 17 00:00:00 2001 From: Dan Ungureanu Date: Fri, 2 Apr 2021 11:19:30 +0300 Subject: [PATCH] FEATURE: Copying invite link triggers a save (#12581) Changing the invite type from link to email and then copying it was confusing because it gave user the impression that the invite was updated and the invite link will reflect the latest changes, but it did not. --- .../discourse/app/controllers/create-invite.js | 16 ++++++++++------ .../tests/acceptance/create-invite-modal-test.js | 13 +++++++++++++ config/locales/client.en.yml | 1 + 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/discourse/app/controllers/create-invite.js b/app/assets/javascripts/discourse/app/controllers/create-invite.js index 9107bbb7063..04310faeaa4 100644 --- a/app/assets/javascripts/discourse/app/controllers/create-invite.js +++ b/app/assets/javascripts/discourse/app/controllers/create-invite.js @@ -101,7 +101,9 @@ export default Controller.extend( this.send("closeModal"); } else { this.appEvents.trigger("modal-body:flash", { - text: I18n.t("user.invited.invite.invite_saved"), + text: opts.copy + ? I18n.t("user.invited.invite.invite_copied") + : I18n.t("user.invited.invite.invite_saved"), messageClass: "success", }); } @@ -156,12 +158,14 @@ export default Controller.extend( @action copied() { - this.appEvents.trigger("modal-body:flash", { - text: I18n.t("user.invited.invite.invite_copied"), - messageClass: "success", - }); + if (this.type === "email" && !this.buffered.get("email")) { + return this.appEvents.trigger("modal-body:flash", { + text: I18n.t("user.invited.invite.blank_email"), + messageClass: "error", + }); + } - this.setAutogenerated(false); + this.save({ sendEmail: false, copy: true }); }, @action diff --git a/app/assets/javascripts/discourse/tests/acceptance/create-invite-modal-test.js b/app/assets/javascripts/discourse/tests/acceptance/create-invite-modal-test.js index 07fd2fc2623..fd27c389b47 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/create-invite-modal-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/create-invite-modal-test.js @@ -1,6 +1,7 @@ import { click, fillIn, visit } from "@ember/test-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { test } from "qunit"; +import I18n from "I18n"; acceptance("Invites - Create & Edit Invite Modal", function (needs) { let deleted; @@ -89,6 +90,18 @@ acceptance("Invites - Create & Edit Invite Modal", function (needs) { await click(".modal-footer .btn:last-child"); assert.notOk(deleted, "does not delete invite on close"); }); + + test("copying an email invite without an email shows error message", async function (assert) { + await visit("/u/eviltrout/invited/pending"); + await click(".invite-controls .btn:first-child"); + + await click("#invite-type-email"); + await click(".invite-link-field .btn"); + assert.equal( + find("#modal-alert").text(), + I18n.t("user.invited.invite.blank_email") + ); + }); }); acceptance("Invites - Link Invites", function (needs) { diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 75e823951ca..87706042279 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -1526,6 +1526,7 @@ en: invite_saved: "Invite was saved." invite_copied: "Invite link was copied." + blank_email: "The email field cannot be empty." bulk_invite: none: "No invitations to display on this page."