Skip to content

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

UX: Add post event host controls (#43130)

Gabriel Grubba923d0e3e17c0
diff --git a/plugins/discourse-events/assets/javascripts/discourse/components/compact-event-editor.gjs b/plugins/discourse-events/assets/javascripts/discourse/components/compact-event-editor.gjs
index 9a13a99cf65..607b1f034ef 100644
--- a/plugins/discourse-events/assets/javascripts/discourse/components/compact-event-editor.gjs
+++ b/plugins/discourse-events/assets/javascripts/discourse/components/compact-event-editor.gjs
@@ -51,6 +51,7 @@ export default class CompactEventEditor extends Component {
@tracked url;
@tracked image;
@tracked allowedGroups;
+ @tracked hosts;
@tracked closed;
@tracked customFields;
@tracked linkify;
@@ -96,6 +97,7 @@ export default class CompactEventEditor extends Component {
this.#startedWithUrl ||= !!s.url;
this.image = s.image;
this.allowedGroups = s.allowedGroups;
+ this.hosts = s.hosts;
this.closed = s.closed;
this.customFields = { ...s.customFields };
@@ -126,6 +128,7 @@ export default class CompactEventEditor extends Component {
url: this.url,
image: this.image,
allowedGroups: this.allowedGroups,
+ hosts: this.hosts,
closed: this.closed,
customFields: this.customFields,
};
@@ -613,6 +616,7 @@ export default class CompactEventEditor extends Component {
all_day: this.allDay,
reminders: this.reminders,
raw_invitees: this.allowedGroups?.split(",") || [],
+ hosts: this.hosts?.split(",").map((username) => ({ username })) || [],
custom_fields: { ...this.customFields },
starts_at: this.startsAt,
ends_at: this.endsAt,
@@ -651,6 +655,9 @@ export default class CompactEventEditor extends Component {
this.#startedWithUrl ||= !!this.url;
this.allowedGroups =
(updatedEvent.rawInvitees || []).join(",") || null;
+ this.hosts =
+ (updatedEvent.hosts || []).map((host) => host.username).join(",") ||
+ null;
this.image = updatedEvent.imageUpload?.short_url
? updatedEvent.imageUpload.short_url
: updatedEvent.imageUpload?.url || null;
diff --git a/plugins/discourse-events/assets/javascripts/discourse/components/discourse-post-event/creator.gjs b/plugins/discourse-events/assets/javascripts/discourse/components/discourse-post-event/creator.gjs
index 999a687f0e6..b17fa071c08 100644
--- a/plugins/discourse-events/assets/javascripts/discourse/components/discourse-post-event/creator.gjs
+++ b/plugins/discourse-events/assets/javascripts/discourse/components/discourse-post-event/creator.gjs
@@ -1,16 +1,108 @@
import Component from "@glimmer/component";
+import { tracked } from "@glimmer/tracking";
+import { action } from "@ember/object";
+import DMenu from "discourse/float-kit/components/d-menu";
import { formatUsername } from "discourse/lib/utilities";
+import DButton from "discourse/ui-kit/d-button";
+import DUserLink from "discourse/ui-kit/d-user-link";
import dAvatar from "discourse/ui-kit/helpers/d-avatar";
+import dOnResize from "discourse/ui-kit/modifiers/d-on-resize";
import { i18n } from "discourse-i18n";
+const INITIAL_HOSTS_COUNT = 2;
+
export default class DiscoursePostEventCreator extends Component {
+ @tracked hostsCollapsed = false;
+
+ #collapsedAtWidth = null;
+
+ get creatorIsHost() {
+ return this.args.hosts?.some(
+ (host) => host.username === this.args.user?.username
+ );
+ }
+
+ get hasHosts() {
+ return this.hosts.length > 0;
+ }
+
+ get hosts() {
+ return (this.args.hosts || []).filter(
+ (host) => host.username !== this.args.user?.username
+ );
+ }
+
+ get displayedHosts() {
+ return this.hostsCollapsed ? [] : this.hosts.slice(0, INITIAL_HOSTS_COUNT);
+ }
+
+ get hasHostsMenu() {
+ return this.hostsCollapsed || this.hosts.length > INITIAL_HOSTS_COUNT;
+ }
+
+ get hostsMenuLabel() {
+ if (this.hostsCollapsed) {
+ return this.allHostsTitle;
+ }
+
+ return i18n("discourse_post_event.other_hosts", {
+ count: this.hosts.length - INITIAL_HOSTS_COUNT,
+ });
+ }
+
+ get allHostsTitle() {
+ return i18n("discourse_post_event.all_hosts", {
+ count: this.hosts.length,
+ });
+ }
+
+ get hostsLabel() {
+ return this.creatorIsHost
+ ? "discourse_post_event.co_hosted_by"
+ : "discourse_post_event.hosted_by";
+ }
+
get username() {
return this.args.user.name || formatUsername(this.args.user.username);
}
+ // Collapses every host into the menu once the hosts line wraps below the
+ // creator, and only tries the inline layout again once the row is wider than
+ // it was when it wrapped, so resizing cannot flip-flop between the two.
+ @action
+ syncHostsLayout([entry]) {
+ const row = entry.target;
+ const width = row.clientWidth;
+
+ if (this.hostsCollapsed) {
+ if (width > this.#collapsedAtWidth) {
+ this.#collapsedAtWidth = null;
+ this.hostsCollapsed = false;
+ }
+ return;
+ }
+
+ const creator = row.querySelector(".event-creator");
+ const hosts = row.querySelector(".event-hosts");
+ if (creator && hosts && hosts.offsetTop > creator.offsetTop) {
+ this.#collapsedAtWidth = width;
+ this.hostsCollapsed = true;
+ }
+ }
+
+ usernameFor(user) {
+ return user.name || formatUsername(user.username);
+ }
+
<template>
- <span class="creators">
- <span class="created-by">{{i18n "discourse_post_event.created_by"}}</span>
+ <span class="creators" {{dOnResize this.syncHostsLayout}}>
+ <span class="created-by">{{i18n
+ (if
+ this.creatorIsHost
+ "discourse_post_event.created_and_hosted_by"
+ "discourse_post_event.created_by"
+ )
+ }}</span>
<span class="event-creator">
<a class="topic-invitee-avatar" data-user-card={{@user.username}}>
@@ -18,6 +110,63 @@ export default class DiscoursePostEventCreator extends Component {
<span class="username">{{this.username}}</span>
</a>
</span>
+
+ {{#if this.hasHosts}}
+ <span class="separator">·</span>
+ <span class="event-hosts">
+ <span class="hosted-by">{{i18n this.hostsLabel}}</span>
+
+ {{#each this.displayedHosts as |host|}}
+ <span class="event-host">
+ <a class="topic-invitee-avatar" data-user-card={{host.username}}>
+ {{dAvatar host imageSize="tiny"}}
+ <span class="username">{{this.usernameFor host}}</span>
+ </a>
+ </span>
+ {{/each}}
+
+ {{#if this.hasHostsMenu}}
+ <DMenu
+ class="event-hosts__toggle"
+ @identifier="discourse-post-event-hosts"
+ @modalForMobile={{true}}
+ @triggerComponent={{component
+ DButton
+ display="link"
+ translatedLabel=this.hostsMenuLabel
+ }}
+ >
+ <:content>
+ <div class="event-hosts-menu">
+ <h3
+ class="event-hosts-menu__title"
+ >{{this.allHostsTitle}}</h3>
+ <ul class="event-hosts-menu__list">
+ {{#each this.hosts as |host|}}
+ <li class="event-hosts-menu__item">
+ <DUserLink
+ class="event-hosts-menu__host"
+ @user={{host}}
+ >
+ {{dAvatar host imageSize="small"}}
+ <span class="event-hosts-menu__name">
+ {{this.usernameFor host}}
+ </span>
+ {{#if host.name}}
+ <span class="event-hosts-menu__username">
+ {{formatUsername host.username}}
+ </span>
+ {{/if}}
+ </DUserLink>
+ </li>
+ {{/each}}
+ </ul>
+ </div>
+ </:content>
+ </DMenu>
+ {{/if}}
+ </span>
+ {{/if}}
</span>
</template>
}
diff --git a/plugins/discourse-events/assets/javascripts/discourse/components/discourse-post-event/index.gjs b/plugins/discourse-events/assets/javascripts/discourse/components/discourse-post-event/index.gjs
index 2a18e82f36d..7fff36a3b10 100644
--- a/plugins/discourse-events/assets/javascripts/discourse/components/discourse-post-event/index.gjs
+++ b/plugins/discourse-events/assets/javascripts/discourse/components/discourse-post-event/index.gjs
@@ -311,13 +311,15 @@ export default class DiscoursePostEvent extends Component {
event=event
Separator=StatusSeparator
Status=(component EventStatus event=event)
- Creator=(component Creator user=event.creator)
+ Creator=(component
+ Creator hosts=event.hosts user=event.creator
+ )
}}
>
{{#if event.creator}}
<EventStatus @event={{event}} />
<StatusSeparator />
- <Creator @user={{event.creator}} />
+ <Creator @hosts={{event.hosts}} @user={{event.creator}} />
{{else if this.loadingDetails}}
<CreatorPlaceholder />
{{/if}}
diff --git a/plugins/discourse-events/assets/javascripts/discourse/components/event-node-view.gjs b/plugins/discourse-events/assets/javascripts/discourse/components/event-node-view.gjs
index 6dd75c342da..917edf01813 100644
--- a/plugins/discourse-events/assets/javascripts/discourse/components/event-node-view.gjs
+++ b/plugins/discourse-events/assets/javascripts/discourse/components/event-node-view.gjs
@@ -30,6 +30,7 @@ const CLEARABLE_ATTRS = [
"reminders",
"image",
"closed",
+ "hosts",
];
export default class EventNodeView extends Component {
diff --git a/plugins/discourse-events/assets/javascripts/discourse/components/modal/post-event-builder.gjs b/plugins/discourse-events/assets/javascripts/discourse/components/modal/post-event-builder.gjs
index 9e346798b4b..5a2f06bb3fd 100644
--- a/plugins/discourse-events/assets/javascripts/discourse/components/modal/post-event-builder.gjs
+++ b/plugins/discourse-events/assets/javascripts/discourse/components/modal/post-event-builder.gjs
@@ -1,6 +1,6 @@
import Component from "@glimmer/component";
import { cached, tracked } from "@glimmer/tracking";
-import { concat, fn } from "@ember/helper";
+import { concat, fn, hash } from "@ember/helper";
import EmberObject, { action } from "@ember/object";
import { service } from "@ember/service";
import AdvancedModeToggle from "discourse/components/advanced-mode-toggle";
@@ -11,6 +11,7 @@ import lazyHash from "discourse/helpers/lazy-hash";
import { extractError } from "discourse/lib/ajax-error";
import Group from "discourse/models/group";
import TimezoneInput from "discourse/select-kit/components/timezone-input";
+import UserChooser from "discourse/select-kit/components/user-chooser";
import { eq, not } from "discourse/truth-helpers";
import DButton from "discourse/ui-kit/d-button";
import DConditionalLoadingSection from "discourse/ui-kit/d-conditional-loading-section";
@@ -18,6 +19,7 @@ import DDateInput from "discourse/ui-kit/d-date-input";
import DDateTimeInput from "discourse/ui-kit/d-date-time-input";
import DModal from "discourse/ui-kit/d-modal";
import { i18n } from "discourse-i18n";
+import { MAX_HOSTS } from "../../lib/constants";
import { recurrenceContext } from "../../lib/event-recurrence";
import {
attendanceTransition,
@@ -121,6 +123,7 @@ export default class PostEventBuilder extends Component {
? this.previousRsvpStatus || "public"
: this.event.status || "public",
rawInvitees: this.event.rawInvitees ?? [],
+ hosts: (this.event.hosts ?? []).map((host) => host.username),
recurrence: this.event.recurrence ?? null,
imageUpload: this.event.imageUpload?.url ?? null,
timezone: this.event.timezone ?? null,
@@ -227,6 +230,12 @@ export default class PostEventBuilder extends Component {
this.event.rawInvitees = newInvitees;
}
+ @action
+ handleHostsChange(usernames, { set }) {
+ set("hosts", usernames);
+ this.event.hosts = usernames.map((username) => ({ username }));
+ }
+
@action
handleRecurrenceChange(value, { set }) {
set("recurrence", value);
@@ -452,6 +461,8 @@ export default class PostEventBuilder extends Component {
this.event.imageUpload?.url ??
null,
allowedGroups: (this.event.rawInvitees || []).join(",") || null,
+ hosts:
+ (this.event.hosts || []).map((host) => host.username).join(",") || null,
closed: !!this.event.isClosed,
customFields: { ...(this.event.customFields || {}) },
};
@@ -476,6 +487,9 @@ export default class PostEventBuilder extends Component {
this.event.rawInvitees = state.allowedGroups
? state.allowedGroups.split(",")
: [];
+ this.event.hosts = state.hosts
+ ? state.hosts.split(",").map((username) => ({ username }))
+ : [];
this.event.allDay = state.allDay;
this.event.startsAt = state.startsAt;
this.event.endsAt = state.endsAt;
@@ -1057,6 +1071,28 @@ export default class PostEventBuilder extends Component {
{{/if}}
{{/if}}
+ <form.Field
+ @name="hosts"
+ @title={{i18n
+ "discourse_post_event.builder_modal.hosts.label"
+ }}
+ @description={{i18n
+ "discourse_post_event.builder_modal.hosts.description"
+ }}
+ @type="custom"
+ @format="full"
+ @onSet={{this.handleHostsChange}}
+ as |field|
+ >
+ <field.Control>
+ <UserChooser
+ @value={{field.value}}
+ @onChange={{field.set}}
+ @options={{hash maximum=MAX_HOSTS}}
+ />
+ </field.Control>
+ </form.Field>
+
<form.Field
@name="timezone"
@title={{i18n
diff --git a/plugins/discourse-events/assets/javascripts/discourse/lib/constants.js b/plugins/discourse-events/assets/javascripts/discourse/lib/constants.js
new file mode 100644
index 00000000000..0798515f71b
--- /dev/null
+++ b/plugins/discourse-events/assets/javascripts/discourse/lib/constants.js
@@ -0,0 +1,4 @@
+// DO NOT EDIT THIS FILE!!!
+// Update it by running `rake javascript:update_constants`
+
+export const MAX_HOSTS = 10;
diff --git a/plugins/discourse-events/assets/javascripts/discourse/lib/raw-event-helper.js b/plugins/discourse-events/assets/javascripts/discourse/lib/raw-event-helper.js
index 2f5734c214d..1a401723151 100644
--- a/plugins/discourse-events/assets/javascripts/discourse/lib/raw-event-helper.js
+++ b/plugins/discourse-events/assets/javascripts/discourse/lib/raw-event-helper.js
@@ -256,6 +256,13 @@ export function buildParams(startsAt, endsAt, event, siteSettings) {
params.allowedGroups = (event.rawInvitees || []).join(",");
}
+ const hosts = (event.hosts || [])
+ .map((host) => (typeof host === "string" ? host : host?.username))
+ .filter(Boolean);
+ if (hosts.length) {
+ params.hosts = hosts.join(",");
+ }
+
if (event.reminders && event.reminders.length) {
params.reminders = event.reminders
.map((r) => {
@@ -386,6 +393,7 @@ export function defaultEventState() {
allowedGroups: null,
closed: false,
customFields: {},
+ hosts: null,
};
}
@@ -424,6 +432,7 @@ export function parseEventAttrs(
allowedGroups: attrs.allowedGroups || null,
closed: attrs.closed === "true",
customFields,
+ hosts: attrs.hosts || null,
};
}
@@ -447,6 +456,7 @@ export function stateToEventInput(state) {
reminders: state.reminders,
imageUpload: state.image ? { url: state.image } : null,
customFields: state.customFields,
+ hosts: state.hosts ? state.hosts.split(",") : [],
};
}
diff --git a/plugins/discourse-events/assets/javascripts/discourse/models/discourse-post-event-event.js b/plugins/discourse-events/assets/javascripts/discourse/models/discourse-post-event-event.js
index d6101300918..324a5a90848 100644
--- a/plugins/discourse-events/assets/javascripts/discourse/models/discourse-post-event-event.js
+++ b/plugins/discourse-events/assets/javascripts/discourse/models/discourse-post-event-event.js
@@ -111,6 +111,7 @@ export default class DiscoursePostEventEvent {
@tracked _sampleInvitees;
@tracked _stats;
@tracked _creator;
+ @tracked _hosts;
@tracked _reminders;
constructor(args = {}) {
@@ -134,6 +135,7 @@ export default class DiscoursePostEventEvent {
this.showLocalTime = args.show_local_time;
this.status = args.status;
this.creator = args.creator;
+ this.hosts = args.hosts || [];
this.post = args.post;
this.isClosed = args.is_closed;
this.isExpired = args.is_expired;
@@ -206,6 +208,16 @@ export default class DiscoursePostEventEvent {
this._creator = this.#initUserModel(user);
}
+ get hosts() {
+ return this._hosts;
+ }
+
+ set hosts(users = []) {
+ this._hosts = trackedArray(
+ (users ?? []).map((user) => this.#initUserModel(user))
+ );
+ }
+
get isPublic() {
return this.status === "public";
}
@@ -238,6 +250,7 @@ export default class DiscoursePostEventEvent {
this.descriptionHtml = event.descriptionHtml;
this.status = event.status;
this.creator = event.creator;
+ this.hosts = event.hosts || [];
this.isClosed = event.isClosed;
this.isExpired = event.isExpired;
this.isStandalone = event.isStandalone;
diff --git a/plugins/discourse-events/assets/javascripts/discourse/pre-initializers/rich-editor-extension.js b/plugins/discourse-events/assets/javascripts/discourse/pre-initializers/rich-editor-extension.js
index 61ac7f3d3f5..ab16d9f0e26 100644
--- a/plugins/discourse-events/assets/javascripts/discourse/pre-initializers/rich-editor-extension.js
+++ b/plugins/discourse-events/assets/javascripts/discourse/pre-initializers/rich-editor-extension.js
@@ -31,6 +31,7 @@ export const EVENT_ATTRIBUTES = {
livestream: { default: null },
allDay: { default: null },
image: { default: null },
+ hosts: { default: null },
};
/** @returns {RichEditorExtension} */
diff --git a/plugins/discourse-events/assets/stylesheets/common/discourse-post-event.scss b/plugins/discourse-events/assets/stylesheets/common/discourse-post-event.scss
index 153a2bd5175..299c8bd46c2 100644
--- a/plugins/discourse-events/assets/stylesheets/common/discourse-post-event.scss
+++ b/plugins/discourse-events/assets/stylesheets/common/discourse-post-event.scss
@@ -125,6 +125,7 @@ $show-interested: inherit;
.event-info {
display: flex;
+ flex: 1 1 auto;
flex-direction: column;
min-width: 0;
margin-right: 0.5rem;
@@ -146,8 +147,10 @@ $show-interested: inherit;
margin: 0 0.25em;
}
- .created-by {
+ .created-by,
+ .hosted-by {
margin-right: 0.25em;
+ white-space: nowrap;
@media screen and (width <= 450px) {
display: none;
@@ -155,7 +158,7 @@ $show-interested: inherit;
}
.username {
- margin-left: 0.25em;
+ margin-inline-start: 0.25em;
color: var(--primary);
@include ellipsis;
@@ -163,9 +166,13 @@ $show-interested: inherit;
.creators {
display: flex;
+ flex: 1 1 auto;
align-items: center;
+ flex-wrap: wrap;
+ min-width: 0;
- .event-creator {
+ .event-creator,
+ .event-host {
@include ellipsis;
.topic-invitee-avatar {
@@ -175,6 +182,23 @@ $show-interested: inherit;
@include ellipsis;
}
}
+
+ .event-hosts {
+ display: flex;
+ align-items: center;
+ gap: 0.25em;
+ min-width: 0;
+
+ .hosted-by {
+ margin-right: 0;
+ }
+ }
+
+ .event-hosts__toggle {
+ padding: 0;
+ font-size: inherit;
+ white-space: nowrap;
+ }
}
.status {
@@ -470,3 +494,49 @@ $show-interested: inherit;
margin-right: 0.5em;
}
}
+
+.event-hosts-menu {
+ min-width: 14em;
+ padding: 0.5em 0;
+
+ &__title {
+ margin: 0;
+ padding: 0.25em 1em 0.5em;
+ color: var(--primary-medium);
+ font-size: var(--font-down-1);
+ font-weight: 600;
+ text-transform: uppercase;
+ letter-spacing: 0.02em;
+ }
+
+ &__list {
+ list-style: none;
+ margin: 0;
+ padding: 0;
+ }
+
+ &__host {
+ display: flex;
+ align-items: center;
+ gap: 0.75em;
+ padding: 0.5em 1em;
+ color: var(--primary);
+
+ &:hover,
+ &:focus-visible {
+ background: var(--d-hover);
+ text-decoration: none;
+ }
+ }
+
+ &__name {
+ @include ellipsis;
+ }
+
+ &__username {
+ color: var(--primary-medium);
+ font-size: var(--font-down-1);
+
+ @include ellipsis;
+ }
+}
diff --git a/plugins/discourse-events/config/locales/client.en.yml b/plugins/discourse-events/config/locales/client.en.yml
index fa03262c9cd..6b22d2c09ad 100644
--- a/plugins/discourse-events/config/locales/client.en.yml
+++ b/plugins/discourse-events/config/locales/client.en.yml
@@ -384,6 +384,15 @@ en:
edit_event: "Edit event"
export_event: "Export event"
created_by: "Created by"
+ created_and_hosted_by: "Created and hosted by"
+ hosted_by: "Hosted by"
+ co_hosted_by: "Co-hosted by"
+ other_hosts:
+ one: "and %{count} other"
+ other: "and %{count} others"
+ all_hosts:
+ one: "%{count} host"
+ other: "%{count} hosts"
bulk_invite: "Bulk Invite"
close_event: "Close event"
open_event: "Open event"
@@ -600,6 +609,9 @@ en:
placeholder: "Optional, defaults to topic title"
invitees:
label: "Invited groups"
+ hosts:
+ label: "Hosts"
+ description: "Hosts are shown on the event alongside its creator."
event_type:
label: "Attendance type"
public:
diff --git a/plugins/discourse-events/lib/tasks/javascript.rake b/plugins/discourse-events/lib/tasks/javascript.rake
index 295f1eb62a7..da5ebf918c1 100644
--- a/plugins/discourse-events/lib/tasks/javascript.rake
+++ b/plugins/discourse-events/lib/tasks/javascript.rake
@@ -3,6 +3,14 @@
require "open-uri"
task "javascript:update_constants" => :environment do
+ write_template(
+ "../plugins/discourse-events/assets/javascripts/discourse/lib/constants.js",
+ "update_constants",
+ <<~JS,
+ export const MAX_HOSTS = #{DiscourseEvents::Events::Event::MAX_HOSTS};
+ JS
+ )
+
timezone_definitions =
"https://raw.githubusercontent.com/moment/moment-timezone/develop/data/meta/latest.json"
diff --git a/plugins/discourse-events/spec/system/page_objects/discourse_events/post_event.rb b/plugins/discourse-events/spec/system/page_objects/discourse_events/post_event.rb
index 8fcc7b5e1bc..1a8317ac549 100644
--- a/plugins/discourse-events/spec/system/page_objects/discourse_events/post_event.rb
+++ b/plugins/discourse-events/spec/system/page_objects/discourse_events/post_event.rb
@@ -66,6 +66,33 @@ module PageObjects
has_css?(".event-invitees-avatars [data-user-card='#{username}']")
end
+ def has_hosts?(hosts, cohosted: false)
+ host_label = cohosted ? "co_hosted_by" : "hosted_by"
+
+ has_css?(".event-hosts", text: I18n.t("js.discourse_post_event.#{host_label}")) &&
+ hosts.all? { |host| has_host?(host) }
+ end
+
+ # Hosts collapse into a menu once their row would wrap, so a host may
+ # only be visible after opening it. Only positive waits are used here,
+ # since CI fails a spec that lets a negative check run out its wait.
+ def has_host?(host)
+ name = host.name.presence || host.username
+ inline = ".event-host [data-user-card='#{host.username}']"
+
+ return false unless has_css?("#{inline}, .event-hosts__toggle")
+ return true if has_css?(inline, text: name, wait: 0)
+
+ find(".event-hosts__toggle").click unless has_css?(".event-hosts-menu", wait: 0)
+ has_css?(".event-hosts-menu__host[data-user-card='#{host.username}']", text: name)
+ end
+
+ def has_creator_host?(user)
+ has_css?(".created-by", text: I18n.t("js.discourse_post_event.created_and_hosted_by")) &&
+ has_css?(".event-creator [data-user-card='#{user.username}']") &&
+ has_no_css?(".event-hosts")
+ end
+
def has_no_invitee_avatar?(username)
has_no_css?(".event-invitees-avatars [data-user-card='#{username}']")
end
diff --git a/plugins/discourse-events/spec/system/post_event_spec.rb b/plugins/discourse-events/spec/system/post_event_spec.rb
index cf6ddf6cd4d..477994dfd01 100644
--- a/plugins/discourse-events/spec/system/post_event_spec.rb
+++ b/plugins/discourse-events/spec/system/post_event_spec.rb
@@ -36,6 +36,29 @@ describe "Post event" do
end
end
+ it "shows the event hosts" do
+ first_host = Fabricate(:user, username: "event_host_maya")
+ second_host = Fabricate(:user, username: "event_host_noah")
+ raw = <<~EVENT
+ [event start='2222-02-22 14:22' hosts='#{admin.username},#{first_host.username},#{second_host.username}']
+ [/event]
+ EVENT
+ post = PostCreator.create!(admin, title: "Community meetup", raw:)
+
+ visit(post.topic.url)
+
+ expect(post_event_page).to have_hosts([first_host, second_host], cohosted: true)
+ end
+
+ it "joins the creator and host roles for the same user" do
+ raw = "[event start='2222-02-22 14:22' hosts='#{admin.username}']\n[/event]"
+ post = PostCreator.create!(admin, title: "Community meetup", raw:)
+
+ visit(post.topic.url)
+
+ expect(post_event_page).to have_creator_host(admin)
+ end
+
context "with description" do
it "can save a description" do
title = "My descriptive meetup event"
@@ -478,7 +501,7 @@ describe "Post event" do
form = PageObjects::Components::FormKit.new(".d-modal form")
form.field("eventType").select("private")
- find(".group-selector").click
+ form.field("rawInvitees").component.find(".group-selector").click
find(".d-multi-select__search-input").send_keys(group.name)
find(".d-multi-select__result", text: group.name).click
form.field("customFields.custom").fill_in("custom value")
@@ -494,7 +517,12 @@ describe "Post event" do
form = PageObjects::Components::FormKit.new(".d-modal form")
expect(form.field("eventType")).to have_value("private")
- expect(find(".group-selector .d-multi-select-trigger__selection")).to have_text(group.name)
+ expect(
+ form
+ .field("rawInvitees")
+ .component
+ .find(".group-selector .d-multi-select-trigger__selection"),
+ ).to have_text(group.name)
expect(form.field("customFields.custom")).to have_value("custom value")
expect(page).to have_selector(".d-modal .recurrence-until .date-picker") do |input|
input.value == "#{1.year.from_now.year}-12-30"
diff --git a/plugins/discourse-events/test/javascripts/integration/components/discourse-post-event-test.gjs b/plugins/discourse-events/test/javascripts/integration/components/discourse-post-event-test.gjs
index c2fafdedde6..29f52a3c763 100644
--- a/plugins/discourse-events/test/javascripts/integration/components/discourse-post-event-test.gjs
+++ b/plugins/discourse-events/test/javascripts/integration/components/discourse-post-event-test.gjs
@@ -53,6 +53,42 @@ module("Integration | Component | DiscoursePostEvent", function (hooks) {
);
});
+ test("lists additional event hosts in a menu", async function (assert) {
+ stubApi.call(
+ this,
+ buildEvent({
+ hosts: [
+ { id: 6, username: "alex" },
+ { id: 7, username: "blake" },
+ { id: 8, username: "casey" },
+ { id: 9, username: "drew" },
+ ],
+ })
+ );
+
+ const event = { id: 1 };
+ await render(<template><DiscoursePostEvent @event={{event}} /></template>);
+ await waitFor(".event-hosts");
+
+ assert
+ .dom(".event-host")
+ .exists({ count: 2 }, "shows the first two hosts initially");
+ assert.dom(".event-hosts__toggle").hasText("and 2 others");
+
+ await click(".event-hosts__toggle");
+
+ assert
+ .dom(".event-host")
+ .exists({ count: 2 }, "keeps the row compact while the menu is open");
+ assert.dom(".event-hosts-menu__title").hasText("4 hosts");
+ assert
+ .dom(".event-hosts-menu__host")
+ .exists({ count: 4 }, "lists every host in the menu");
+ assert
+ .dom(".event-hosts-menu__host[data-user-card='drew']")
+ .hasText("drew");
+ });
+
test("interpolates the ordinal and weekday into the monthly recurrence label", async function (assert) {
stubApi.call(this, buildEvent({ recurrence: "every_month" }));