FEATURE: Copying invite link triggers a save (#12581)

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.

diff --git a/app/assets/javascripts/discourse/app/controllers/create-invite.js b/app/assets/javascripts/discourse/app/controllers/create-invite.js
index 9107bbb..04310fa 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 07fd2fc..fd27c38 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 75e8239..8770604 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."

GitHub sha: bfd0c009

This commit appears in #12581 which was approved by ZogStriP and eviltrout. It was merged by udan11.