Skip to content

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

FEATURE: Add "Use Predefined Topics" modal to admin onboarding banner (#37826)

Gabriel Grubbacba702c88f03
diff --git a/app/assets/stylesheets/common/components/admin-onboarding-banner.scss b/app/assets/stylesheets/common/components/admin-onboarding-banner.scss
index 4622de376fe..a66a8d04bd9 100644
--- a/app/assets/stylesheets/common/components/admin-onboarding-banner.scss
+++ b/app/assets/stylesheets/common/components/admin-onboarding-banner.scss
@@ -103,3 +103,37 @@
}
}
}
+
+.start-posting-options-modal {
+ .option {
+ padding-bottom: var(--space-4);
+ }
+}
+
+.predefined-topic-options-modal {
+ .d-modal__subtitle-text {
+ padding: var(--space-2) 0;
+ }
+
+ &__header {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ }
+
+ &__card {
+ margin-bottom: var(--space-4);
+ }
+
+ &__content {
+ border-bottom: 1px solid var(--content-border-color);
+ }
+
+ &__card:last-child > &__content {
+ border-bottom: none;
+ }
+
+ &__body {
+ max-width: var(--modal-max-width);
+ }
+}
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 65f23daaed1..c9cb91857b4 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -467,6 +467,13 @@ en:
title: "Start Posting"
description: "Give people something to talk about together"
action: "Icebreaker ideas"
+ choose_option: "How would you like to start?"
+ predefined_topics: "Pre-defined Topics"
+ predefined_topics_subtitle: "Break the ice with one of the following conversation starters. <br/> Pick one and customize it to your liking:"
+ predefined_topics_description: "Pick from a collection of conversation starters to get discussions going"
+ use_predefined: "Use pre-defined Topics"
+ start_with_this: "Start with this"
+ back: "Back"
icebreakers:
fun_facts:
title: "What are some fun facts about you?"
@@ -481,7 +488,6 @@ en:
title: "What is your favorite food?"
body: "Share your favorite food with the community! I'll start: I love pizza, especially with extra cheese and pepperoni."
-
spread_the_word:
title: "Spread the Word!"
description: "Share a link with everyone in your network"
diff --git a/frontend/discourse/app/components/admin-onboarding/banner.gjs b/frontend/discourse/app/components/admin-onboarding/banner.gjs
index 860d8695b7a..aa32203eca9 100644
--- a/frontend/discourse/app/components/admin-onboarding/banner.gjs
+++ b/frontend/discourse/app/components/admin-onboarding/banner.gjs
@@ -5,10 +5,14 @@ import { action } from "@ember/object";
import { service } from "@ember/service";
import { TrackedArray } from "@ember-compat/tracked-built-ins";
import SiteSetting from "discourse/admin/models/site-setting";
+import PredefinedTopicsOptionsModal from "discourse/components/admin-onboarding/modal/predefined-topics-options";
+import StartPostingOptions from "discourse/components/admin-onboarding/modal/start-posting-options";
+import PredefinedTopicOption from "discourse/components/admin-onboarding/predefined-topics-option";
import OnboardingStep from "discourse/components/admin-onboarding/step";
import DButton from "discourse/components/d-button";
import CreateInvite from "discourse/components/modal/create-invite";
import { getAbsoluteURL } from "discourse/lib/get-url";
+import { applyValueTransformer } from "discourse/lib/transformer";
import { clipboardCopy, defaultHomepage } from "discourse/lib/utilities";
import { i18n } from "discourse-i18n";
@@ -43,45 +47,70 @@ const STEPS = [
@service composer;
@service appEvents;
+ @service modal;
+ @service siteSettings;
icon = "comments";
- icebreaker_topics = [
- "fun_facts",
- "coolest_thing_you_have_seen_today",
- "introduce_yourself",
- "what_is_your_favorite_food",
- ];
constructor() {
super(...arguments);
- this.appEvents.on("topic:created", this, this.checkIfPosted);
+
+ this.appEvents.on("topic:created", this, this.completeStep);
+ this.appEvents.on(
+ "admin-onboarding:posting-complete",
+ this,
+ this.completeStep
+ );
}
willDestroy() {
super.willDestroy(...arguments);
- this.appEvents.off("topic:created", this, this.checkIfPosted);
+
+ this.appEvents.off("topic:created", this, this.completeStep);
+ this.appEvents.off(
+ "admin-onboarding:posting-complete",
+ this,
+ this.completeStep
+ );
}
- checkIfPosted() {
+ completeStep() {
this.markAsCompleted();
}
- @action
- async performAction() {
- const randomTopic =
- this.icebreaker_topics[
- Math.floor(Math.random() * this.icebreaker_topics.length)
- ];
+ showStartPostingOptions() {
+ const options = applyValueTransformer(
+ "admin-onboarding-start-posting-options",
+ [PredefinedTopicOption]
+ );
+
+ if (options.length === 1) {
+ // show predefined topics directly if it's the only option available
+ return this.modal.show(PredefinedTopicsOptionsModal);
+ }
+
+ this.modal.show(StartPostingOptions, {
+ model: {
+ options,
+ },
+ });
+ }
+ openTopic(topicKey) {
this.composer.openNewTopic({
title: i18n(
- `admin_onboarding_banner.start_posting.icebreakers.${randomTopic}.title`
+ `admin_onboarding_banner.start_posting.icebreakers.${topicKey}.title`
),
body: i18n(
- `admin_onboarding_banner.start_posting.icebreakers.${randomTopic}.body`
+ `admin_onboarding_banner.start_posting.icebreakers.${topicKey}.body`
),
});
}
+
+ @action
+ async performAction() {
+ this.showStartPostingOptions();
+ }
},
class SpreadTheWord extends OnboardingStep {
static name = "spread_the_word";
diff --git a/frontend/discourse/app/components/admin-onboarding/modal/predefined-topics-options.gjs b/frontend/discourse/app/components/admin-onboarding/modal/predefined-topics-options.gjs
new file mode 100644
index 00000000000..b0c840f4e3c
--- /dev/null
+++ b/frontend/discourse/app/components/admin-onboarding/modal/predefined-topics-options.gjs
@@ -0,0 +1,97 @@
+import Component from "@glimmer/component";
+import { concat, fn } from "@ember/helper";
+import { action } from "@ember/object";
+import { service } from "@ember/service";
+import { htmlSafe } from "@ember/template";
+import DButton from "discourse/components/d-button";
+import DModal from "discourse/components/d-modal";
+import { i18n } from "discourse-i18n";
+
+export default class PredefinedTopicOptions extends Component {
+ @service composer;
+
+ icebreakerTopics = [
+ "fun_facts",
+ "coolest_thing_you_have_seen_today",
+ "introduce_yourself",
+ "what_is_your_favorite_food",
+ ];
+
+ openTopic(topicKey) {
+ this.composer.openNewTopic({
+ title: i18n(
+ `admin_onboarding_banner.start_posting.icebreakers.${topicKey}.title`
+ ),
+ body: i18n(
+ `admin_onboarding_banner.start_posting.icebreakers.${topicKey}.body`
+ ),
+ });
+ }
+
+ @action
+ cancel() {
+ this.args.closeModal();
+ }
+
+ @action
+ handleSelectTopic(topic) {
+ this.args.closeModal();
+ this.openTopic(topic);
+ }
+
+ <template>
+ <DModal
+ class="predefined-topic-options-modal"
+ @title={{i18n "admin_onboarding_banner.start_posting.predefined_topics"}}
+ @subtitle={{htmlSafe
+ (i18n
+ "admin_onboarding_banner.start_posting.predefined_topics_subtitle"
+ )
+ }}
+ @closeModal={{this.cancel}}
+ >
+ <:body>
+ <div class="predefined-topic-options-modal__list">
+ {{#each this.icebreakerTopics as |topic|}}
+ <div class="predefined-topic-options-modal__card">
+ <div class="predefined-topic-options-modal__content">
+ <div class="predefined-topic-options-modal__header">
+ <h4 class="predefined-topic-options-modal__title">
+ {{i18n
+ (concat
+ "admin_onboarding_banner.start_posting.icebreakers."
+ topic
+ ".title"
+ )
+ }}
+ </h4>
+ <DButton
+ @icon="far-pen-to-square"
+ @action={{fn this.handleSelectTopic topic}}
+ class="predefined-topic-options-modal__select-btn btn-primary"
+ />
+ </div>
+ <p class="predefined-topic-options-modal__body">
+ {{i18n
+ (concat
+ "admin_onboarding_banner.start_posting.icebreakers."
+ topic
+ ".body"
+ )
+ }}
+ </p>
+ </div>
+ </div>
+ {{/each}}
+ </div>
+ </:body>
+ <:footer>
+ <DButton
+ @label="cancel"
+ @action={{this.cancel}}
+ class="predefined-topic-options-modal__cancel-button btn-transparent"
+ />
+ </:footer>
+ </DModal>
+ </template>
+}
diff --git a/frontend/discourse/app/components/admin-onboarding/modal/start-posting-options.gjs b/frontend/discourse/app/components/admin-onboarding/modal/start-posting-options.gjs
new file mode 100644
index 00000000000..ccdc7e21c7a
--- /dev/null
+++ b/frontend/discourse/app/components/admin-onboarding/modal/start-posting-options.gjs
@@ -0,0 +1,28 @@
+import DButton from "discourse/components/d-button";
+import DModal from "discourse/components/d-modal";
+import { i18n } from "discourse-i18n";
+
+const StartPostingOptions = <template>
+ <DModal
+ class="start-posting-options-modal"
+ @title={{i18n "admin_onboarding_banner.start_posting.choose_option"}}
+ @closeModal={{@closeModal}}
+ >
+ <:body>
+ <div class="modal-options">
+ {{#each @model.options as |Option|}}
+ <Option @closeModal={{@closeModal}} />
+ {{/each}}
+ </div>
+ </:body>
+ <:footer>
+ <DButton
+ @label="cancel"
+ @action={{@closeModal}}
+ class="btn-transparent cancel-button"
+ />
+ </:footer>
+ </DModal>
+</template>;
+
+export default StartPostingOptions;
diff --git a/frontend/discourse/app/components/admin-onboarding/predefined-topics-option.gjs b/frontend/discourse/app/components/admin-onboarding/predefined-topics-option.gjs
new file mode 100644
index 00000000000..60ee9170555
--- /dev/null
+++ b/frontend/discourse/app/components/admin-onboarding/predefined-topics-option.gjs
@@ -0,0 +1,18 @@
+import { action } from "@ember/object";
+import { service } from "@ember/service";
+import PredefinedTopicsOptionsModal from "discourse/components/admin-onboarding/modal/predefined-topics-options";
+import StartPostingOption from "discourse/components/admin-onboarding/start-posting-option";
+
+export default class PredefinedTopicsOption extends StartPostingOption {
+ @service modal;
+
+ name = "predefined-option";
+ title = "admin_onboarding_banner.start_posting.predefined_topics";
+ body = "admin_onboarding_banner.start_posting.predefined_topics_description";
+ actionLabel = "admin_onboarding_banner.start_posting.use_predefined";
+
+ @action
+ onSelect() {
+ this.modal.show(PredefinedTopicsOptionsModal);
+ }
+}
diff --git a/frontend/discourse/app/components/admin-onboarding/start-posting-option.gjs b/frontend/discourse/app/components/admin-onboarding/start-posting-option.gjs
new file mode 100644
index 00000000000..3de3172f244
--- /dev/null
+++ b/frontend/discourse/app/components/admin-onboarding/start-posting-option.gjs
@@ -0,0 +1,42 @@
+import Component from "@glimmer/component";
+import { action } from "@ember/object";
+import DButton from "discourse/components/d-button";
+import concatClass from "discourse/helpers/concat-class";
+import { i18n } from "discourse-i18n";
+
+export default class StartPostingOption extends Component {
+ get name() {
+ throw new Error("Name is required for StartPostingOption");
+ }
+
+ get title() {
+ throw new Error("Title is required for StartPostingOption");
+ }
+
+ get body() {
+ throw new Error("Body is required for StartPostingOption");
+ }
+
+ get actionLabel() {
+ throw new Error("ButtonLabel is required for StartPostingOption");
+ }
+
+ @action
+ onSelect() {
+ throw new Error("onSelect is required for StartPostingOption");
+ }
+
+ <template>
+ <div class={{concatClass "option" this.name}}>
+ <h3>{{i18n this.title}}</h3>
+ <p>
+ {{i18n this.body}}
+ </p>
+ <DButton
+ @label={{this.actionLabel}}
+ @action={{this.onSelect}}
+ class="btn-primary"
+ />
+ </div>
+ </template>
+}
diff --git a/frontend/discourse/app/lib/transformer/registry.js b/frontend/discourse/app/lib/transformer/registry.js
index c47ae2f880e..48e9a7c2ebc 100644
--- a/frontend/discourse/app/lib/transformer/registry.js
+++ b/frontend/discourse/app/lib/transformer/registry.js
@@ -14,6 +14,7 @@ export const VALUE_TRANSFORMERS = Object.freeze([
// use only lowercase names
"admin-plugin-icon",
"admin-reports-show-query-params",
+ "admin-onboarding-start-posting-options",
"bulk-select-in-nav-controls",
"category-available-views",
"category-default-colors",
diff --git a/frontend/discourse/tests/acceptance/admin-onboarding-banner-test.js b/frontend/discourse/tests/acceptance/admin-onboarding-banner-test.gjs
similarity index 68%
rename from frontend/discourse/tests/acceptance/admin-onboarding-banner-test.js
rename to frontend/discourse/tests/acceptance/admin-onboarding-banner-test.gjs
index cbd5406f6ad..b396a952096 100644
--- a/frontend/discourse/tests/acceptance/admin-onboarding-banner-test.js
+++ b/frontend/discourse/tests/acceptance/admin-onboarding-banner-test.gjs
@@ -1,7 +1,11 @@
+import { action } from "@ember/object";
+import { service } from "@ember/service";
import { click, settled, visit } from "@ember/test-helpers";
import { test } from "qunit";
import sinon from "sinon";
+import StartPostingOption from "discourse/components/admin-onboarding/start-posting-option";
import { AUTO_GROUPS } from "discourse/lib/constants";
+import { withPluginApi } from "discourse/lib/plugin-api";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Admin - Onboarding Banner", function (needs) {
@@ -74,19 +78,65 @@ acceptance("Admin - Onboarding Banner", function (needs) {
assert.dom(".admin-onboarding-banner").doesNotExist();
});
- test("it can complete `start_posting` step", async function (assert) {
+ test("it can complete `start_posting` step with predefined data", async function (assert) {
const step = withStep("start_posting", assert);
await visit("/");
step.isNotChecked();
await step.clickAction();
+
+ assert.dom(".predefined-topic-options-modal__card").exists({ count: 4 });
+ await click(
+ ".predefined-topic-options-modal__card:last-child .predefined-topic-options-modal__select-btn"
+ );
+
await click(".create");
await visit("/");
step.isChecked();
});
+ test("it can complete `start_posting` step with registered posting-options", async function (assert) {
+ withPluginApi((api) => {
+ api.registerValueTransformer(
+ "admin-onboarding-start-posting-options",
+ ({ value }) => {
+ value.push(
+ class ExtraOption extends StartPostingOption {
+ @service appEvents;
+
+ name = "extra-option";
+ title = "admin_onboarding_banner.start_posting.extra_option";
+ body =
+ "admin_onboarding_banner.start_posting.extra_option_description";
+ actionLabel = "admin_onboarding_banner.start_posting.use_extra";
+
+ @action
+ onSelect() {
+ this.appEvents.trigger("admin-onboarding:posting-complete");
+ this.args.closeModal();
+ }
+ }
+ );
+ return value;
+ }
+ );
+ });
+
+ const step = withStep("start_posting", assert);
+ await visit("/");
+
+ step.isNotChecked();
+
+ await step.clickAction();
+
+ assert.dom(".option").exists({ count: 2 });
+ await click(".extra-option .btn");
+
+ step.isChecked();
+ });
+
test("it can complete `invite_collaborators` step", async function (assert) {
const step = withStep("invite_collaborators", assert);
await visit("/");
diff --git a/spec/system/admin_onboarding_banner_spec.rb b/spec/system/admin_onboarding_banner_spec.rb
new file mode 100644
index 00000000000..2754d0d7f1e
--- /dev/null
+++ b/spec/system/admin_onboarding_banner_spec.rb
@@ -0,0 +1,166 @@
+# frozen_string_literal: true
+
+describe "Admin Onboarding Banner", type: :system do
+ fab!(:admin)
+
+ let(:banner) { PageObjects::Components::AdminOnboardingBanner.new }
+ let(:predefined_topics_modal) { PageObjects::Modals::AdminOnboardingPredefinedTopics.new }
+ let(:create_invite_modal) { PageObjects::Modals::CreateInvite.new }
+ let(:composer) { PageObjects::Components::Composer.new }
+ let(:toasts) { PageObjects::Components::Toasts.new }
+
+ before do
+ SiteSetting.enable_site_owner_onboarding = true
+
+ sign_in(admin)
+ end
+
+ describe "banner visibility" do
+ it "shows the onboarding banner for admin users" do
+ visit("/")
+ expect(banner).to be_visible
+ end
+
+ it "shows all three onboarding steps" do
+ visit("/")
+ expect(banner.step("start_posting")).to be_present
+ expect(banner.step("invite_collaborators")).to be_present
+ expect(banner.step("spread_the_word")).to be_present
+ end
+
+ it "can close the banner prematurely" do
+ visit("/")
+ expect(banner).to be_visible
+
+ banner.close
+
+ expect(toasts).to have_success(I18n.t("js.admin_onboarding_banner.skipped"))
+
+ expect(SiteSetting.enable_site_owner_onboarding).to eq(false)
+ end
+ end
+
+ describe "start posting step" do
+ it "opens composer with selected topic and marks step as complete when topic is created" do
+ visit("/")
+ expect(banner.step_not_completed?("start_posting")).to eq(true)
+
+ banner.click_step_action("start_posting")
+ expect(predefined_topics_modal).to be_open
+ expect(predefined_topics_modal.topic_card_count).to eq(4)
+
+ predefined_topics_modal.select_topic(0)
+
+ expect(composer).to be_opened
+ expect(composer.composer_input.value).not_to be_empty
+
+ composer.composer_input.set("Testing topic selection")
+ composer.create
+ expect(page).to have_content("Testing topic selection")
+
+ visit("/")
+ expect(banner.step_completed?("start_posting")).to eq(true)
+ end
+
+ it "can cancel topic selection without completing step" do
+ visit("/")
+ banner.click_step_action("start_posting")
+ expect(predefined_topics_modal).to be_open
+
+ predefined_topics_modal.cancel
+
+ expect(predefined_topics_modal).to be_closed
+ expect(banner.step_not_completed?("start_posting")).to eq(true)
+ end
+ end
+
+ describe "invite collaborators step" do
+ it "marks step as complete after creating invite" do
+ visit("/")
+ expect(banner.step_not_completed?("invite_collaborators")).to eq(true)
+
+ banner.click_step_action("invite_collaborators")
+
+ expect(create_invite_modal).to be_open
+ create_invite_modal.save_button.click
+ expect(create_invite_modal).to have_copy_button
+
+ create_invite_modal.close
+
+ expect(banner.step_completed?("invite_collaborators")).to eq(true)
+ end
+
+ it "does not mark step complete if modal is cancelled" do
+ visit("/")
+ expect(banner.step_not_completed?("invite_collaborators")).to eq(true)
+ banner.click_step_action("invite_collaborators")
+
+ expect(create_invite_modal).to be_open
+ create_invite_modal.close
+
+ expect(banner.step_not_completed?("invite_collaborators")).to eq(true)
+ end
+ end
+
+ describe "spread the word step" do
+ it "copies site URL to clipboard and marks step complete" do
+ visit("/")
+ expect(banner.step_not_completed?("spread_the_word")).to eq(true)
+
+ banner.click_step_action("spread_the_word")
+
+ expect(banner.step_completed?("spread_the_word")).to eq(true)
+ expect(toasts).to have_success(
+ I18n.t("js.admin_onboarding_banner.spread_the_word.copied_to_clipboard"),
+ )
+ end
+ end
+
+ describe "completing all steps" do
+ it "disables onboarding when all steps are complete" do
+ visit("/")
+
+ banner.click_step_action("start_posting")
+ predefined_topics_modal.select_topic(0)
+ composer.create
+ visit("/")
+
+ expect(banner.step_completed?("start_posting")).to eq(true)
+
+ banner.click_step_action("invite_collaborators")
+ create_invite_modal.save_button.click
+ expect(create_invite_modal).to have_copy_button
+ create_invite_modal.close
+
+ expect(banner.step_completed?("invite_collaborators")).to eq(true)
+
+ banner.click_step_action("spread_the_word")
+
+ # banner is hidden after all steps are complete; No need to check for `spread_the_word` step completion
+
+ expect(banner).to be_not_visible
+ expect(SiteSetting.enable_site_owner_onboarding).to eq(false)
+ end
+ end
+
+ describe "when user is not an admin" do
+ fab!(:regular_user, :user)
+
+ it "does not show the banner" do
+ sign_in(regular_user)
+ visit("/")
+
+ expect(banner).to be_not_visible
+ end
+ end
+
+ describe "when setting is disabled" do
+ before { SiteSetting.enable_site_owner_onboarding = false }
+
+ it "does not show the banner" do
+ visit("/")
+
+ expect(banner).to be_not_visible
+ end
+ end
+end
diff --git a/spec/system/page_objects/components/admin_onboarding_banner.rb b/spec/system/page_objects/components/admin_onboarding_banner.rb
new file mode 100644
index 00000000000..918c370caf3
--- /dev/null
+++ b/spec/system/page_objects/components/admin_onboarding_banner.rb
@@ -0,0 +1,39 @@
+# frozen_string_literal: true
+
+module PageObjects
+ module Components
+ class AdminOnboardingBanner < PageObjects::Components::Base
+ def visible?
+ has_css?(".admin-onboarding-banner")
+ end
+
+ def not_visible?
+ has_no_css?(".admin-onboarding-banner")
+ end
+
+ def close
+ find(".admin-onboarding-banner .btn-close").click
+ end
+
+ def step(step_id)
+ find("div##{step_id}")
+ end
+
+ def step_checkbox(step_id)
+ find("div##{step_id} .onboarding-step__checkbox > svg")
+ end
+
+ def step_completed?(step_id)
+ step_checkbox(step_id)[:class].include?("checked")
+ end
+
+ def step_not_completed?(step_id)
+ !step_completed?(step_id)
+ end
+
+ def click_step_action(step_id)
+ find("div##{step_id} .onboarding-step__action .btn").click
+ end
+ end
+ end
+end
diff --git a/spec/system/page_objects/modals/admin_onboarding_predefined_topics.rb b/spec/system/page_objects/modals/admin_onboarding_predefined_topics.rb
new file mode 100644
index 00000000000..c8f7fdc73e6
--- /dev/null
+++ b/spec/system/page_objects/modals/admin_onboarding_predefined_topics.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+module PageObjects
+ module Modals
+ class AdminOnboardingPredefinedTopics < PageObjects::Modals::Base
+ MODAL_SELECTOR = ".predefined-topic-options-modal"
+
+ def open?
+ has_css?("#{MODAL_SELECTOR}")
+ end
+
+ def closed?
+ has_no_css?("#{MODAL_SELECTOR}")
+ end
+
+ def topic_cards
+ all(".predefined-topic-options-modal__card")
+ end
+
+ def topic_card_count
+ topic_cards.count
+ end
+
+ def select_topic(index)
+ topic_cards[index].find(".predefined-topic-options-modal__select-btn").click
+ end
+
+ def cancel
+ find(".predefined-topic-options-modal__cancel-button").click
+ end
+ end
+ end
+end