Skip to content

A platform for community discussion. Free, open, simple.

DEV: simplify and use reuable components in invite modal, fix bug, (#42273)

Kris665494fc53d4
diff --git a/app/assets/stylesheets/common/base/user.scss b/app/assets/stylesheets/common/base/user.scss
index 358a9786f5c..1f53c6df3f2 100644
--- a/app/assets/stylesheets/common/base/user.scss
+++ b/app/assets/stylesheets/common/base/user.scss
@@ -1381,15 +1381,14 @@
.user-additional-controls {
display: flex;
+ gap: var(--space-2);
flex-wrap: wrap;
- justify-content: end;
}
.user-invite-buttons {
display: flex;
flex-wrap: wrap;
gap: 0.5em;
- margin-left: auto;
}
.notification-schedule {
@@ -1457,8 +1456,12 @@
}
.user-invite-search {
+ min-width: 0;
+ margin-right: auto;
+
input {
margin: 0;
+ width: 100%;
}
}
diff --git a/app/assets/stylesheets/common/components/d-segmented-control.scss b/app/assets/stylesheets/common/components/d-segmented-control.scss
index 7a2dbd2bcc0..3b3a1e0ea8a 100644
--- a/app/assets/stylesheets/common/components/d-segmented-control.scss
+++ b/app/assets/stylesheets/common/components/d-segmented-control.scss
@@ -54,6 +54,15 @@
clip-path: inset(50%);
}
+ &.--full-width {
+ display: flex;
+ width: 100%;
+
+ .d-segmented-control__label {
+ flex: 1;
+ }
+ }
+
&--small {
gap: 2px;
padding: 1px;
diff --git a/app/assets/stylesheets/common/form-kit/_conditional-display.scss b/app/assets/stylesheets/common/form-kit/_conditional-display.scss
index 1f1db2ff774..045ff3effc4 100644
--- a/app/assets/stylesheets/common/form-kit/_conditional-display.scss
+++ b/app/assets/stylesheets/common/form-kit/_conditional-display.scss
@@ -3,7 +3,7 @@
.form-kit__conditional-display {
display: flex;
flex-direction: column;
- gap: var(--space-3);
+ gap: var(--space-4);
&-content {
display: flex;
diff --git a/app/assets/stylesheets/common/form-kit/_fieldset.scss b/app/assets/stylesheets/common/form-kit/_fieldset.scss
index 6e0eb80a1cd..936b0768182 100644
--- a/app/assets/stylesheets/common/form-kit/_fieldset.scss
+++ b/app/assets/stylesheets/common/form-kit/_fieldset.scss
@@ -3,6 +3,16 @@
display: flex;
flex-direction: column;
gap: 0.75rem;
+
+ &.--inline {
+ flex-flow: row wrap;
+ align-items: center;
+ gap: 0.5rem 1.5rem;
+
+ > :not(.form-kit__field) {
+ flex-basis: 100%;
+ }
+ }
}
&__fieldset-title {
diff --git a/app/assets/stylesheets/common/modal/create-invite-with-roles.scss b/app/assets/stylesheets/common/modal/create-invite-with-roles.scss
index fdd52d297aa..20fa9cb4909 100644
--- a/app/assets/stylesheets/common/modal/create-invite-with-roles.scss
+++ b/app/assets/stylesheets/common/modal/create-invite-with-roles.scss
@@ -1,104 +1,17 @@
.create-invite-with-roles-modal {
.d-modal__container {
- width: 32em;
- max-width: 100%;
+ width: 100%;
+ max-width: 32em;
}
&__role {
margin-bottom: 1em;
}
- &__role-toggle {
- display: flex;
- gap: 0.5em;
+ &__staff-role-description {
margin: 0;
- padding: 0;
- border: 0;
- }
-
- &__role-option {
- flex: 1;
- display: flex;
- align-items: center;
- justify-content: center;
- gap: 0.5em;
- padding: 0.5em 0.75em;
- margin: 0;
- border: 1px solid var(--primary-low);
- border-radius: var(--d-button-border-radius, 4px);
- background: var(--secondary);
- color: var(--primary-high);
- font-weight: 500;
- cursor: pointer;
-
- input {
- position: absolute;
- opacity: 0;
- pointer-events: none;
- }
-
- .d-icon {
- color: currentcolor;
- }
-
- &:hover {
- background: var(--d-hover);
- }
-
- &.--active {
- border-color: var(--tertiary);
- background: var(--tertiary);
- color: var(--secondary);
- font-weight: 600;
- }
-
- &.--disabled {
- opacity: 0.55;
- pointer-events: none;
- }
-
- &:focus-within {
- outline: 2px solid var(--tertiary);
- outline-offset: 1px;
- }
- }
-
- &__role-description {
- margin: 0.75em 0 0;
- color: var(--primary-high);
- }
-
- &__role-locked {
- color: var(--primary-medium);
font-size: var(--font-down-1);
- }
-
- &__delivery,
- &__staff-role {
- margin: 0 0 1em;
- padding: 0;
- border: 0;
- }
-
- &__delivery-label,
- &__staff-role-label {
- padding: 0;
- margin-bottom: 0.5em;
- font-weight: bold;
- }
-
- &__delivery-option,
- &__staff-role-option {
- display: inline-flex;
- align-items: center;
- gap: 0.5em;
- margin-right: 1.5em;
- font-weight: 500;
- cursor: pointer;
-
- input {
- margin: 0;
- }
+ color: var(--primary-high);
}
&__sent-to {
@@ -118,7 +31,6 @@
&__summary-rows {
margin: 0;
- border-top: 1px solid var(--content-border-color);
}
&__summary-row {
@@ -126,7 +38,10 @@
justify-content: space-between;
gap: 1em;
padding: 0.5em 0;
- border-bottom: 1px solid var(--content-border-color);
+
+ &:not(:last-child) {
+ border-bottom: 1px solid var(--content-border-color);
+ }
dt {
color: var(--primary-medium);
@@ -145,20 +60,4 @@
margin-top: 0;
}
}
-
- .d-modal__footer {
- .toggle-advanced {
- margin-left: auto;
-
- &.--active {
- --d-button-default-bg-color: var(--tertiary-low);
- --d-button-default-bg-color--hover: var(--tertiary-low);
- --d-button-default-text-color: var(--tertiary-high);
- --d-button-default-text-color--hover: var(--tertiary-hover);
- --d-button-default-icon-color: var(--tertiary-high);
- --d-button-default-icon-color--hover: var(--tertiary-hover);
- border-color: var(--tertiary);
- }
- }
- }
}
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 1e46bf8302e..08041e8df2f 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -2548,9 +2548,8 @@ en:
sent_title: "Invitation sent"
member_tab: "Members"
admin_tab: "Staff"
- member_description: "Invite people to join this site. Share a link or send an email invitation."
- admin_description: "Invite people to join your staff team. Admins have full access to this site."
- moderator_description: "Invite people to join your staff team. Moderators can help manage content and members."
+ admin_description: "Admins have full access to this site, its settings, and data."
+ moderator_description: "Moderators can help manage content and members."
staff_role_label: "Invite as"
staff_role_admin: "Admin"
staff_role_moderator: "Moderator"
@@ -2563,16 +2562,13 @@ en:
invite_by_email: "Email"
role_label: "Invite as"
restrict_domain: "Restrict to domain"
- restrict_domain_help: "Only people with an email at this domain can accept the link. To invite a specific person, use Email above."
+ restrict_domain_help: "Only people with an email at this domain can accept the link."
domain_placeholder: "example.com"
domain_invalid: "Enter a valid domain, e.g. example.com"
arrive_at_topic_help: "Send people to a specific topic after they accept."
- create_and_send: "Create & send"
- create_and_copy: "Create & copy link"
- more_options: "More options"
- fewer_options: "Fewer options"
+ create_and_send: "Send"
+ create_and_copy: "Copy link"
update: "Update"
- role_locked: "The invite type can't be changed after the invite is created."
summary:
sent_to: "An invitation was emailed to %{email}. You can also share this link directly:"
role: "Role"
@@ -2587,7 +2583,7 @@ en:
expires: "Expires"
topic: "Topic"
groups: "Groups"
- edit: "Edit invite"
+ edit: "Edit"
view_invites: "View invites"
email_sent:
body: "An invitation was emailed to %{email}."
diff --git a/frontend/discourse/app/components/advanced-mode-toggle.gjs b/frontend/discourse/app/components/advanced-mode-toggle.gjs
index 5aabcadf14e..ae217d47c48 100644
--- a/frontend/discourse/app/components/advanced-mode-toggle.gjs
+++ b/frontend/discourse/app/components/advanced-mode-toggle.gjs
@@ -1,17 +1,24 @@
+import Component from "@glimmer/component";
+import { service } from "@ember/service";
import DButton from "discourse/ui-kit/d-button";
-const AdvancedModeToggle = <template>
- <DButton
- class="btn-default advanced-mode-btn"
- @icon="gear"
- @label={{if
- @active
- "advanced_mode_toggle.simple_mode"
- "advanced_mode_toggle.advanced_mode"
- }}
- @action={{@onToggle}}
- ...attributes
- />
-</template>;
+export default class AdvancedModeToggle extends Component {
+ @service capabilities;
-export default AdvancedModeToggle;
+ get label() {
+ return this.args.active
+ ? "advanced_mode_toggle.simple_mode"
+ : "advanced_mode_toggle.advanced_mode";
+ }
+
+ <template>
+ <DButton
+ class="btn-default advanced-mode-btn"
+ @icon="gear"
+ @label={{if this.capabilities.viewport.sm this.label}}
+ @ariaLabel={{this.label}}
+ @action={{@onToggle}}
+ ...attributes
+ />
+ </template>
+}
diff --git a/frontend/discourse/app/components/modal/create-invite-with-roles.gjs b/frontend/discourse/app/components/modal/create-invite-with-roles.gjs
index c20d41fb493..3cc3646793e 100644
--- a/frontend/discourse/app/components/modal/create-invite-with-roles.gjs
+++ b/frontend/discourse/app/components/modal/create-invite-with-roles.gjs
@@ -1,11 +1,12 @@
import Component from "@glimmer/component";
import { cached, tracked } from "@glimmer/tracking";
import { array, fn, hash } from "@ember/helper";
-import { on } from "@ember/modifier";
import { action } from "@ember/object";
import { LinkTo } from "@ember/routing";
import { service } from "@ember/service";
import { trustHTML } from "@ember/template";
+import AdvancedModeToggle from "discourse/components/advanced-mode-toggle";
+import DSegmentedControl from "discourse/components/d-segmented-control";
import Form from "discourse/components/form";
import PluginOutlet from "discourse/components/plugin-outlet";
import lazyHash from "discourse/helpers/lazy-hash";
@@ -28,7 +29,6 @@ import DButton from "discourse/ui-kit/d-button";
import DCopyButton from "discourse/ui-kit/d-copy-button";
import DFutureDateInput from "discourse/ui-kit/d-future-date-input";
import DModal from "discourse/ui-kit/d-modal";
-import dIcon from "discourse/ui-kit/helpers/d-icon";
import { i18n } from "discourse-i18n";
const FORM = "form";
@@ -50,6 +50,7 @@ export default class CreateInviteWithRoles extends Component {
@tracked submitForcedDisabled = false;
@tracked flashText;
@tracked flashClass = "info";
+ @tracked linkAutoCopied = false;
@tracked topics = this.invite.topics ?? this.model.topics ?? [];
model = this.args.model;
@@ -57,6 +58,7 @@ export default class CreateInviteWithRoles extends Component {
allGroups = this.site.groups.filter((g) => !g.automatic);
cameFromSummary = false;
+ initialStaffRole;
formApi;
constructor() {
@@ -74,25 +76,29 @@ export default class CreateInviteWithRoles extends Component {
: "member";
this.delivery = "link";
}
+
+ this.initialStaffRole = this.staffRole;
}
get canInviteAdmins() {
return !!this.currentUser?.can_create_admin_invite;
}
+ get canChooseRole() {
+ return this.canInviteAdmins && !this.inviteCreated;
+ }
+
get roleItems() {
return [
{
value: "member",
label: i18n("user.invited.invite_roles.member_tab"),
icon: "user",
- disabled: this.inviteCreated && this.isAdminInvite,
},
{
value: "admin",
label: i18n("user.invited.invite_roles.admin_tab"),
icon: "shield-halved",
- disabled: this.inviteCreated && !this.isAdminInvite,
},
];
}
@@ -133,6 +139,10 @@ export default class CreateInviteWithRoles extends Component {
return this.isAdminInvite && this.staffRole === "moderator";
}
+ get staffRoleLabel() {
+ return i18n("user.invited.invite_roles.staff_role_label");
+ }
+
get staffRoleItems() {
return [
{
@@ -146,11 +156,7 @@ export default class CreateInviteWithRoles extends Component {
];
}
- get roleDescription() {
- if (!this.isAdminInvite) {
- return i18n("user.invited.invite_roles.member_description");
- }
-
+ get staffRoleDescription() {
return this.isModeratorInvite
? i18n("user.invited.invite_roles.moderator_description")
: i18n("user.invited.invite_roles.admin_description");
@@ -215,6 +221,9 @@ export default class CreateInviteWithRoles extends Component {
email: this.invite.email ?? "",
description: this.invite.description ?? "",
customMessage: this.invite.custom_message ?? "",
+ // seeded from the untracked copy: reading the tracked property here would
+ // give `<Form>` a new @data identity on every change, tearing the form down
+ staffRole: this.initialStaffRole,
};
if (this.inviteCreated) {
@@ -365,10 +374,8 @@ export default class CreateInviteWithRoles extends Component {
}
@action
- onStaffRoleChange(value) {
- if (this.inviteCreated) {
- return;
- }
+ onStaffRoleChange(value, { set }) {
+ set("staffRole", value);
this.staffRole = value;
}
@@ -441,7 +448,9 @@ export default class CreateInviteWithRoles extends Component {
nextScreen = EMAIL_SENT;
}
} else {
- submitData.domain = data.domain?.trim();
+ // a cleared field arrives as null, and an undefined value would be
+ // dropped from the request, leaving the existing domain in place
+ submitData.domain = data.domain?.trim() ?? "";
submitData.max_redemptions_allowed = data.maxRedemptions;
submitData.skip_email = true;
}
@@ -451,6 +460,8 @@ export default class CreateInviteWithRoles extends Component {
@action
async submitForm() {
+ this.linkAutoCopied = false;
+
if (this.isLinkCreation) {
// save and copy in one user gesture so the browser allows the
// clipboard write after the network round-trip
@@ -462,6 +473,8 @@ export default class CreateInviteWithRoles extends Component {
}
return new Blob([this.invite.link], { type: "text/plain" });
});
+
+ this.linkAutoCopied = true;
} catch {
// saving errors are surfaced via the form flash; clipboard errors
// are recoverable from the summary screen's copy button
@@ -524,41 +537,18 @@ export default class CreateInviteWithRoles extends Component {
</:belowHeader>
<:body>
{{#if (eq this.screen "form")}}
- <div class="create-invite-with-roles-modal__role">
- {{#if this.canInviteAdmins}}
- <fieldset class="create-invite-with-roles-modal__role-toggle">
- <legend class="sr-only">
- {{i18n "user.invited.invite_roles.role_label"}}
- </legend>
- {{#each this.roleItems as |item|}}
- <label
- class="create-invite-with-roles-modal__role-option
- {{if (eq this.role item.value) '--active'}}
- {{if item.disabled '--disabled'}}"
- >
- <input
- type="radio"
- name="invite-role"
- value={{item.value}}
- checked={{eq this.role item.value}}
- disabled={{item.disabled}}
- {{on "change" (fn this.onRoleChange item.value)}}
- />
- {{dIcon item.icon}}
- {{item.label}}
- </label>
- {{/each}}
- </fieldset>
- {{/if}}
- <p class="create-invite-with-roles-modal__role-description">
- {{this.roleDescription}}
- {{#if this.inviteCreated}}
- <span class="create-invite-with-roles-modal__role-locked">
- {{i18n "user.invited.invite_roles.role_locked"}}
- </span>
- {{/if}}
- </p>
- </div>
+ {{#if this.canChooseRole}}
+ <div class="create-invite-with-roles-modal__role">
+ <DSegmentedControl
+ class="--full-width"
+ @items={{this.roleItems}}
+ @value={{this.role}}
+ @name="invite-role"
+ @onSelect={{this.onRoleChange}}
+ @label="user.invited.invite_roles.role_label"
+ />
+ </div>
+ {{/if}}
{{#if this.isAdminInvite}}
<PluginOutlet
@@ -578,27 +568,33 @@ export default class CreateInviteWithRoles extends Component {
as |form|
>
{{#unless this.inviteCreated}}
- <fieldset class="create-invite-with-roles-modal__staff-role">
- <legend
- class="create-invite-with-roles-modal__staff-role-label"
- >{{i18n
- "user.invited.invite_roles.staff_role_label"
- }}</legend>
- {{#each this.staffRoleItems as |item|}}
- <label
- class="create-invite-with-roles-modal__staff-role-option"
+ <form.Field
+ @name="staffRole"
+ @type="radio-group"
+ @title={{this.staffRoleLabel}}
+ @showTitle={{false}}
+ @format="full"
+ @onSet={{this.onStaffRoleChange}}
+ as |field|
+ >
+ <field.Control
+ @title={{this.staffRoleLabel}}
+ class="--inline"
+ as |radioGroup|
+ >
+ {{#each this.staffRoleItems as |item|}}
+ <radioGroup.Radio
+ @value={{item.value}}
+ >{{item.label}}</radioGroup.Radio>
+ {{/each}}
+
+ <p
+ class="create-invite-with-roles-modal__staff-role-description"
>
- <input
- type="radio"
- name="invite-staff-role"
- value={{item.value}}
- checked={{eq this.staffRole item.value}}
- {{on "change" (fn this.onStaffRoleChange item.value)}}
- />
- {{item.label}}
- </label>
- {{/each}}
- </fieldset>
+ {{this.staffRoleDescription}}
+ </p>
+ </field.Control>
+ </form.Field>
{{/unless}}
<form.Field
@@ -667,83 +663,83 @@ export default class CreateInviteWithRoles extends Component {
class="create-invite-with-roles-modal__member-form"
as |form|
>
- {{#unless this.inviteCreated}}
- <fieldset class="create-invite-with-roles-modal__delivery">
- <legend
- class="create-invite-with-roles-modal__delivery-label"
- >{{i18n "user.invited.invite_roles.invite_by"}}</legend>
- {{#each
- (array
- (hash
- value="link"
- label=(i18n "user.invited.invite_roles.invite_by_link")
- )
- (hash
- value="email"
- label=(i18n "user.invited.invite_roles.invite_by_email")
- )
- )
- as |item|
- }}
- <label
- class="create-invite-with-roles-modal__delivery-option"
+ <form.ConditionalContent
+ @activeName={{this.delivery}}
+ @onChange={{this.setDelivery}}
+ as |conditional|
+ >
+ {{#unless this.inviteCreated}}
+ <fieldset>
+ <legend class="form-kit__fieldset-title">{{i18n
+ "user.invited.invite_roles.invite_by"
+ }}</legend>
+ <conditional.Conditions as |Condition|>
+ <Condition @name="link">{{i18n
+ "user.invited.invite_roles.invite_by_link"
+ }}</Condition>
+ <Condition @name="email">{{i18n
+ "user.invited.invite_roles.invite_by_email"
+ }}</Condition>
+ </conditional.Conditions>
+ </fieldset>
+ {{/unless}}
+
+ <conditional.Contents as |Content|>
+ <Content @name="link">
+ <form.Field
+ @name="domain"
+ @type="input"
+ @title={{i18n
+ "user.invited.invite_roles.restrict_domain"
+ }}
+ @description={{i18n
+ "user.invited.invite_roles.restrict_domain_help"
+ }}
+ @validate={{if
+ (eq this.delivery "link")
+ this.validateDomain
+ }}
+ @format="full"
+ as |field|
>
- <input
- type="radio"
- name="invite-delivery"
- value={{item.value}}
- checked={{eq this.delivery item.value}}
- {{on "change" (fn this.setDelivery item.value)}}
+ <field.Control
+ autofocus="autofocus"
+ placeholder={{i18n
+ "user.invited.invite_roles.domain_placeholder"
+ }}
/>
- {{item.label}}
- </label>
- {{/each}}
- </fieldset>
- {{/unless}}
-
- {{#if (eq this.delivery "email")}}
- <form.Field
- @name="email"
- @type="input-email"
- @title={{this.emailFieldLabel}}
- @description={{i18n
- "user.invited.invite_roles.member_email_help"
- }}
- @validation="required"
- @validate={{this.validateEmail}}
- @format="full"
- @disabled={{this.inviteCreated}}
- as |field|
- >
- <field.Control
- autocomplete="off"
- data-1p-ignore
- data-lpignore="true"
- placeholder={{i18n
- "user.invited.invite_roles.email_placeholder"
- }}
- />
- </form.Field>
- {{else}}
- <form.Field
- @name="domain"
- @type="input"
- @title={{i18n "user.invited.invite_roles.restrict_domain"}}
- @description={{i18n
- "user.invited.invite_roles.restrict_domain_help"
- }}
- @validate={{this.validateDomain}}
- @format="full"
- as |field|
- >
- <field.Control
- autofocus="autofocus"
- placeholder={{i18n
- "user.invited.invite_roles.domain_placeholder"
- }}
- />
- </form.Field>
- {{/if}}
+ </form.Field>
+ </Content>
+
+ <Content @name="email">
+ <form.Field
+ @name="email"
+ @type="input-email"
+ @title={{this.emailFieldLabel}}
+ @description={{i18n
+ "user.invited.invite_roles.member_email_help"
+ }}
+ @validation={{if (eq this.delivery "email") "required"}}
+ @validate={{if
+ (eq this.delivery "email")
+ this.validateEmail
+ }}
+ @format="full"
+ @disabled={{this.inviteCreated}}
+ as |field|
+ >
+ <field.Control
+ autocomplete="off"
+ data-1p-ignore
+ data-lpignore="true"
+ placeholder={{i18n
+ "user.invited.invite_roles.email_placeholder"
+ }}
+ />
+ </form.Field>
+ </Content>
+ </conditional.Contents>
+ </form.ConditionalContent>
{{#if this.showAdvanced}}
{{#if (eq this.delivery "email")}}
@@ -855,7 +851,10 @@ export default class CreateInviteWithRoles extends Component {
{{/if}}
<div class="create-invite-with-roles-modal__link-share">
- <ShareOrCopyInviteLink @invite={{this.invite}} />
+ <ShareOrCopyInviteLink
+ @invite={{this.invite}}
+ @isCopied={{this.linkAutoCopied}}
+ />
</div>
<dl class="create-invite-with-roles-modal__summary-rows">
@@ -904,16 +903,9 @@ export default class CreateInviteWithRoles extends Component {
@action={{this.cancel}}
class="btn-transparent cancel-button"
/>
- <DButton
- @icon="gear"
- @translatedTitle={{if
- this.showAdvanced
- (i18n "user.invited.invite_roles.fewer_options")
- (i18n "user.invited.invite_roles.more_options")
- }}
- @action={{this.toggleAdvanced}}
- class="btn-default toggle-advanced
- {{if this.showAdvanced '--active'}}"
+ <AdvancedModeToggle
+ @active={{this.showAdvanced}}
+ @onToggle={{this.toggleAdvanced}}
/>
{{else if (eq this.screen "summary")}}
<DButton
@@ -924,7 +916,7 @@ export default class CreateInviteWithRoles extends Component {
<LinkTo
@route="userInvited.show"
@models={{array this.currentUser.username_lower "pending"}}
- class="btn btn-transparent view-invites"
+ class="btn btn-default view-invites"
>
{{i18n "user.invited.invite_roles.summary.view_invites"}}
</LinkTo>
@@ -932,7 +924,7 @@ export default class CreateInviteWithRoles extends Component {
<LinkTo
@route="userInvited.show"
@models={{array this.currentUser.username_lower "pending"}}
- class="btn btn-transparent view-invites"
+ class="btn btn-default view-invites"
>
{{i18n "user.invited.invite_roles.summary.view_invites"}}
</LinkTo>
@@ -1007,6 +999,7 @@ class ShareOrCopyInviteLink extends Component {
@selector="input.invite-link"
@translatedLabel={{i18n "user.invited.invite.copy_link"}}
@translatedLabelAfterCopy={{i18n "user.invited.invite.link_copied"}}
+ @isCopied={{@isCopied}}
/>
{{/if}}
</template>
diff --git a/frontend/discourse/app/components/modal/create-invite.gjs b/frontend/discourse/app/components/modal/create-invite.gjs
index 96a80273ada..573686e92f4 100644
--- a/frontend/discourse/app/components/modal/create-invite.gjs
+++ b/frontend/discourse/app/components/modal/create-invite.gjs
@@ -100,21 +100,28 @@ export default class CreateInvite extends Component {
async save(data) {
let isLink = true;
+ const restrictTo = data.emailOrDomain;
+ delete data.emailOrDomain;
- if (data.emailOrDomain) {
+ if (restrictTo) {
if (this.isEmailInvite) {
isLink = false;
- data.email = data.emailOrDomain;
- } else if (hostnameValid(data.emailOrDomain)) {
- data.domain = data.emailOrDomain;
+ data.email = restrictTo;
+ } else if (hostnameValid(restrictTo)) {
+ data.domain = restrictTo;
}
- delete data.emailOrDomain;
}
if (isLink) {
if (this.invite.email) {
data.email = data.custom_message = "";
}
+
+ // the server only touches the column when the key is present, so an
+ // emptied field has to send a blank value to drop the restriction
+ if (!restrictTo && this.invite.domain) {
+ data.domain = "";
+ }
} else {
if (data.max_redemptions_allowed > 1) {
data.max_redemptions_allowed = 1;
diff --git a/frontend/discourse/app/ui-kit/d-copy-button.gjs b/frontend/discourse/app/ui-kit/d-copy-button.gjs
index 9e6dad18979..60dd0a6f163 100644
--- a/frontend/discourse/app/ui-kit/d-copy-button.gjs
+++ b/frontend/discourse/app/ui-kit/d-copy-button.gjs
@@ -18,6 +18,25 @@ export default class DCopyButton extends Component {
this.copyTranslatedLabel = this.translatedLabel;
}
+ didReceiveAttrs() {
+ super.didReceiveAttrs(...arguments);
+
+ if (this.isCopied && !this._wasCopied) {
+ this._showCopied();
+ }
+
+ this._wasCopied = this.isCopied;
+ }
+
+ _showCopied() {
+ this.set("copyIcon", "check");
+ this.set("copyClass", "btn-primary ok");
+ this.set("copyTranslatedLabel", this.translatedLabelAfterCopy);
+ this.set("announcement", this.translatedLabelAfterCopy);
+
+ discourseDebounce(this._restoreButton, 3000);
+ }
+
@bind
_restoreButton() {
if (this.isDestroying || this.isDestroyed) {
@@ -43,12 +62,7 @@ export default class DCopyButton extends Component {
this.copied();
}
- this.set("copyIcon", "check");
- this.set("copyClass", "btn-primary ok");
- this.set("copyTranslatedLabel", this.translatedLabelAfterCopy);
- this.set("announcement", this.translatedLabelAfterCopy);
-
- discourseDebounce(this._restoreButton, 3000);
+ this._showCopied();
} catch {}
}
diff --git a/frontend/discourse/tests/acceptance/admin-onboarding-banner-test.gjs b/frontend/discourse/tests/acceptance/admin-onboarding-banner-test.gjs
index 857d84cdb80..4d4fc909fde 100644
--- a/frontend/discourse/tests/acceptance/admin-onboarding-banner-test.gjs
+++ b/frontend/discourse/tests/acceptance/admin-onboarding-banner-test.gjs
@@ -306,7 +306,9 @@ acceptance("Admin - Onboarding Banner - admin invites", function (needs) {
.dom(".create-invite-with-roles-modal")
.exists("opens the role-based invite modal");
assert
- .dom(".create-invite-with-roles-modal__role-toggle input[value='admin']")
+ .dom(
+ ".create-invite-with-roles-modal input[name='invite-role'][value='admin']"
+ )
.isChecked("defaults to the admins tab");
await fillIn(
diff --git a/frontend/discourse/tests/integration/components/advanced-mode-toggle-test.gjs b/frontend/discourse/tests/integration/components/advanced-mode-toggle-test.gjs
index 9634a564c65..4da8cdc49dc 100644
--- a/frontend/discourse/tests/integration/components/advanced-mode-toggle-test.gjs
+++ b/frontend/discourse/tests/integration/components/advanced-mode-toggle-test.gjs
@@ -36,4 +36,22 @@ module("Integration | Component | AdvancedModeToggle", function (hooks) {
"shows 'Simple mode' once active"
);
});
+
+ test("keeps an accessible name for when the label is hidden", async function (assert) {
+ const noop = () => {};
+
+ await render(
+ <template>
+ <AdvancedModeToggle @active={{false}} @onToggle={{noop}} />
+ </template>
+ );
+
+ assert
+ .dom(".advanced-mode-btn")
+ .hasAria(
+ "label",
+ i18n("advanced_mode_toggle.advanced_mode"),
+ "below the sm breakpoint the label is hidden, so the name has to come from aria-label"
+ );
+ });
});
diff --git a/frontend/discourse/tests/integration/components/create-invite-test.gjs b/frontend/discourse/tests/integration/components/create-invite-test.gjs
index 9a3e6a3bd5b..6f17ef78348 100644
--- a/frontend/discourse/tests/integration/components/create-invite-test.gjs
+++ b/frontend/discourse/tests/integration/components/create-invite-test.gjs
@@ -1,6 +1,7 @@
import { click, render } from "@ember/test-helpers";
import { module, test } from "qunit";
import CreateInvite from "discourse/components/modal/create-invite";
+import Invite from "discourse/models/invite";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import pretender, { response } from "discourse/tests/helpers/create-pretender";
import formKit from "discourse/tests/helpers/form-kit-helper";
@@ -216,6 +217,66 @@ module("Integration | Component | CreateInvite", function (hooks) {
);
});
+ test("clearing the restrictTo field of a domain invite", async function (assert) {
+ const model = {
+ editing: true,
+ invite: Invite.create({
+ id: 42,
+ domain: "example.com",
+ expires_at: "2030-01-01",
+ }),
+ };
+
+ let requestBody;
+ pretender.put("/invites/42", (request) => {
+ requestBody = new URLSearchParams(request.requestBody);
+ return response({ id: 42, domain: null });
+ });
+
+ await render(
+ <template><CreateInvite @inline={{true}} @model={{model}} /></template>
+ );
+
+ await formKit().field("restrictTo").fillIn("");
+ await click(".save-invite");
+
+ assert.strictEqual(
+ requestBody.get("domain"),
+ "",
+ "sends a blank domain so the server drops the restriction"
+ );
+ });
+
+ test("changing the restrictTo field of a domain invite", async function (assert) {
+ const model = {
+ editing: true,
+ invite: Invite.create({
+ id: 42,
+ domain: "example.com",
+ expires_at: "2030-01-01",
+ }),
+ };
+
+ let requestBody;
+ pretender.put("/invites/42", (request) => {
+ requestBody = new URLSearchParams(request.requestBody);
+ return response({ id: 42, domain: "other.com" });
+ });
+
+ await render(
+ <template><CreateInvite @inline={{true}} @model={{model}} /></template>
+ );
+
+ await formKit().field("restrictTo").fillIn("other.com");
+ await click(".save-invite");
+
+ assert.strictEqual(
+ requestBody.get("domain"),
+ "other.com",
+ "sends the new domain"
+ );
+ });
+
test("the expiresAfterDays field", async function (assert) {
const model = {};
this.siteSettings.invite_expiry_days = 3;
diff --git a/frontend/discourse/tests/integration/components/create-invite-with-roles-test.gjs b/frontend/discourse/tests/integration/components/create-invite-with-roles-test.gjs
index 9f8e612d2f0..af3f3870ea0 100644
--- a/frontend/discourse/tests/integration/components/create-invite-with-roles-test.gjs
+++ b/frontend/discourse/tests/integration/components/create-invite-with-roles-test.gjs
@@ -8,6 +8,7 @@ import Invite from "discourse/models/invite";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import pretender, { response } from "discourse/tests/helpers/create-pretender";
import formKit from "discourse/tests/helpers/form-kit-helper";
+import { i18n } from "discourse-i18n";
module("Integration | Component | CreateInviteWithRoles", function (hooks) {
setupRenderingTest(hooks);
@@ -22,7 +23,7 @@ module("Integration | Component | CreateInviteWithRoles", function (hooks) {
);
assert
- .dom(".create-invite-with-roles-modal__role-toggle")
+ .dom("input[name='invite-role']")
.doesNotExist("role toggle is not shown");
assert.true(formKit().hasField("domain"), "defaults to member link mode");
});
@@ -37,9 +38,9 @@ module("Integration | Component | CreateInviteWithRoles", function (hooks) {
</template>
);
- assert.dom(".create-invite-with-roles-modal__role-toggle").exists();
+ assert.dom("input[name='invite-role']").exists();
assert
- .dom(".create-invite-with-roles-modal__role-toggle input[value='member']")
+ .dom("input[name='invite-role'][value='member']")
.isChecked("defaults to the members tab");
});
@@ -54,14 +55,16 @@ module("Integration | Component | CreateInviteWithRoles", function (hooks) {
);
assert
- .dom(".create-invite-with-roles-modal__role-toggle input[value='admin']")
+ .dom("input[name='invite-role'][value='admin']")
.isChecked("defaults to the admins tab");
assert.true(formKit().hasField("email"), "shows the email field");
assert.false(
formKit().hasField("domain"),
"does not show the domain field"
);
- assert.dom(".save-invite").hasText("Create & send");
+ assert
+ .dom(".save-invite")
+ .hasText(i18n("user.invited.invite_roles.create_and_send"));
});
test("ignores defaultRole for users who can't create admin invites", async function (assert) {
@@ -148,9 +151,19 @@ module("Integration | Component | CreateInviteWithRoles", function (hooks) {
</template>
);
- await click(
- ".create-invite-with-roles-modal__staff-role input[value='moderator']"
- );
+ assert
+ .dom(".create-invite-with-roles-modal__staff-role-description")
+ .hasText(i18n("user.invited.invite_roles.admin_description"));
+
+ await click("input[name='staffRole'][value='moderator']");
+
+ assert
+ .dom(".create-invite-with-roles-modal__staff-role-description")
+ .hasText(
+ i18n("user.invited.invite_roles.moderator_description"),
+ "the description tracks the selected staff role"
+ );
+
await formKit().field("email").fillIn("[email protected]");
await click(".save-invite");
@@ -261,9 +274,7 @@ module("Integration | Component | CreateInviteWithRoles", function (hooks) {
</template>
);
- await click(
- ".create-invite-with-roles-modal__delivery input[value='email']"
- );
+ await click(".form-kit__inline-radio input[value='email']");
await formKit().field("email").fillIn("[email protected]");
await click(".save-invite");
@@ -275,7 +286,7 @@ module("Integration | Component | CreateInviteWithRoles", function (hooks) {
.doesNotExist("no copy link UI for email invites");
});
- test("editing an existing admin invite locks the role toggle", async function (assert) {
+ test("editing an existing admin invite hides the role toggle", async function (assert) {
this.currentUser.set("can_create_admin_invite", true);
const invite = Invite.create({
id: 45,
@@ -294,12 +305,16 @@ module("Integration | Component | CreateInviteWithRoles", function (hooks) {
);
assert
- .dom(".create-invite-with-roles-modal__role-toggle input[value='admin']")
- .isChecked("admin tab selected");
+ .dom("input[name='invite-role']")
+ .doesNotExist(
+ "the role can't be changed after creation, so it is hidden"
+ );
+ assert
+ .dom(".create-invite-with-roles-modal__staff-role-description")
+ .doesNotExist("the staff role description follows its radios");
assert
- .dom(".create-invite-with-roles-modal__role-toggle input[value='member']")
- .isDisabled("member tab is locked");
- assert.dom(".save-invite").hasText("Update");
+ .dom(".save-invite")
+ .hasText(i18n("user.invited.invite_roles.update"));
});
test("plugin outlet can disable the submit button in admin mode", async function (assert) {
@@ -331,4 +346,49 @@ module("Integration | Component | CreateInviteWithRoles", function (hooks) {
assert.dom(".save-invite").isDisabled();
});
+
+ test("clearing the domain of an existing link invite", async function (assert) {
+ const model = {
+ editing: true,
+ invite: Invite.create({
+ id: 42,
+ invite_key: "ghi789",
+ link: "http://example.com/invites/ghi789",
+ domain: "google.com",
+ max_redemptions_allowed: 100,
+ expires_at: "2100-01-01 00:00",
+ }),
+ };
+
+ let requestBody;
+ pretender.put("/invites/42", (request) => {
+ requestBody = new URLSearchParams(request.requestBody);
+ return response({
+ id: 42,
+ invite_key: "ghi789",
+ link: "http://example.com/invites/ghi789",
+ domain: null,
+ max_redemptions_allowed: 100,
+ expires_at: "2100-01-01 00:00",
+ });
+ });
+
+ await render(
+ <template>
+ <CreateInviteWithRoles @inline={{true}} @model={{model}} />
+ </template>
+ );
+
+ await formKit().field("domain").fillIn("");
+ await click(".save-invite");
+
+ assert.strictEqual(
+ requestBody.get("domain"),
+ "",
+ "sends a blank domain so the server drops the restriction"
+ );
+ assert
+ .dom(".create-invite-with-roles-modal__summary-rows")
+ .doesNotIncludeText("google.com", "the restriction is gone");
+ });
});
diff --git a/frontend/discourse/tests/integration/components/d-copy-button-test.gjs b/frontend/discourse/tests/integration/components/d-copy-button-test.gjs
index 656020e3c0d..06099ec1dc4 100644
--- a/frontend/discourse/tests/integration/components/d-copy-button-test.gjs
+++ b/frontend/discourse/tests/integration/components/d-copy-button-test.gjs
@@ -1,4 +1,5 @@
-import { render } from "@ember/test-helpers";
+import { tracked } from "@glimmer/tracking";
+import { render, rerender } from "@ember/test-helpers";
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import DCopyButton from "discourse/ui-kit/d-copy-button";
@@ -24,4 +25,35 @@ module("Integration | Component | DCopyButton", function (hooks) {
"a visually-hidden polite live region is rendered so screen readers can announce copy success"
);
});
+
+ test("@isCopied shows the confirmation for a copy made by the caller", async function (assert) {
+ const state = new (class {
+ @tracked isCopied = false;
+ })();
+
+ await render(
+ <template>
+ <input class="test-input" value="hello" readonly />
+ <DCopyButton
+ @selector="input.test-input"
+ @translatedLabel="Copy"
+ @translatedLabelAfterCopy="Copied!"
+ @isCopied={{state.isCopied}}
+ />
+ </template>
+ );
+
+ assert.dom(".copy-button").hasText("Copy");
+ assert.dom(".copy-button").doesNotHaveClass("ok");
+
+ state.isCopied = true;
+
+ await rerender();
+
+ assert.dom(".copy-button").hasText("Copied!");
+ assert.dom(".copy-button").hasClass("ok");
+ assert
+ .dom(".sr-only[aria-live='polite']")
+ .hasText("Copied!", "the confirmation is announced");
+ });
});
diff --git a/spec/system/create_invite_with_roles_spec.rb b/spec/system/create_invite_with_roles_spec.rb
index fa0920c87c3..a1c439ff640 100644
--- a/spec/system/create_invite_with_roles_spec.rb
+++ b/spec/system/create_invite_with_roles_spec.rb
@@ -109,6 +109,8 @@ describe "Creating invites with roles" do
modal.save_button.click
expect(modal).to have_summary
+ cdp.clipboard_has_text?(Invite.last.link)
+ expect(page).to have_css(".copy-button.ok")
screenshot_marker(label: "invite-created", only: :desktop)
invite = Invite.last
@@ -143,8 +145,7 @@ describe "Creating invites with roles" do
modal.edit_button.click
- expect(modal.selected_role).to eq("admin")
- expect(modal.role_option_disabled?("member")).to eq(true)
+ expect(modal).to have_no_role_toggle
expect(modal.save_button).to have_text(I18n.t("js.user.invited.invite_roles.update"))
modal.cancel_button.click
diff --git a/spec/system/page_objects/modals/create_invite_with_roles.rb b/spec/system/page_objects/modals/create_invite_with_roles.rb
index 29d5aeb79d1..d8299a145c7 100644
--- a/spec/system/page_objects/modals/create_invite_with_roles.rb
+++ b/spec/system/page_objects/modals/create_invite_with_roles.rb
@@ -22,43 +22,30 @@ module PageObjects
end
def has_role_toggle?
- within(modal) { has_css?(".create-invite-with-roles-modal__role-toggle") }
+ within(modal) { has_css?(".d-segmented-control") }
end
def has_no_role_toggle?
- within(modal) { has_no_css?(".create-invite-with-roles-modal__role-toggle") }
+ within(modal) { has_no_css?(".d-segmented-control") }
end
def selected_role
- within(modal) do
- find(".create-invite-with-roles-modal__role-toggle input:checked", visible: false)[:value]
- end
+ within(modal) { find(".d-segmented-control input:checked", visible: false)[:value] }
end
def select_role(role)
within(modal) do
- find(
- ".create-invite-with-roles-modal__role-toggle input[value='#{role}']",
- visible: false,
- ).ancestor("label").click
- end
- end
-
- def role_option_disabled?(role)
- within(modal) do
- find(
- ".create-invite-with-roles-modal__role-toggle input[value='#{role}']",
- visible: false,
- ).disabled?
+ find(".d-segmented-control input[value='#{role}']", visible: false).ancestor(
+ "label",
+ ).click
end
end
def select_delivery(delivery)
within(modal) do
- find(
- ".create-invite-with-roles-modal__delivery input[value='#{delivery}']",
- visible: false,
- ).ancestor("label").click
+ find(".form-kit__inline-radio input[value='#{delivery}']", visible: false).ancestor(
+ "label",
+ ).click
end
end
@@ -67,7 +54,7 @@ module PageObjects
end
def toggle_advanced_options
- within(modal) { find(".toggle-advanced").click }
+ within(modal) { find(".advanced-mode-btn").click }
end
def edit_button