A platform for community discussion. Free, open, simple.
FEATURE: welcome banner shouldn't say "welcome back" to new users (#35777)
Kris1ecbca54853c
diff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex 3bf26f7c20e..1d231fe0947 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -319,6 +319,7 @@ en:welcome_banner:header:+ new_members: "Welcome, %{preferred_display_name}!"logged_in_members: "Welcome back, %{preferred_display_name}!"anonymous_members: "Welcome to %{site_name}!"subheader:diff --git a/frontend/discourse/app/components/welcome-banner.gjs b/frontend/discourse/app/components/welcome-banner.gjsindex 45cb6a669ae..babf58ac8e8 100644--- a/frontend/discourse/app/components/welcome-banner.gjs+++ b/frontend/discourse/app/components/welcome-banner.gjs@@ -94,7 +94,12 @@ export default class WelcomeBanner extends Component {});}- return i18n("welcome_banner.header.logged_in_members", {+ const isNewUser = !this.currentUser.previous_visit_at;+ const key = isNewUser+ ? "welcome_banner.header.new_members"+ : "welcome_banner.header.logged_in_members";++ return i18n(key, {preferred_display_name: sanitize(prioritizeNameFallback(this.currentUser.name, this.currentUser.username)),diff --git a/frontend/discourse/tests/integration/components/welcome-banner-test.gjs b/frontend/discourse/tests/integration/components/welcome-banner-test.gjsindex 2d1e11b5d2e..36e35230fd5 100644--- a/frontend/discourse/tests/integration/components/welcome-banner-test.gjs+++ b/frontend/discourse/tests/integration/components/welcome-banner-test.gjs@@ -26,6 +26,7 @@ module(});test("shows the logged in user message with the user's username", async function (assert) {+ this.currentUser.previous_visit_at = new Date("2025-01-01");await render(<template><WelcomeBanner /></template>);assert.dom(".welcome-banner").containsText(@@ -37,6 +38,7 @@ module(});test("shows the logged in user message with the user's display name", async function (assert) {+ this.currentUser.previous_visit_at = new Date("2025-01-01");this.siteSettings.display_name_on_posts = true;this.siteSettings.prioritize_username_in_ux = false;@@ -61,6 +63,18 @@ module(assert.dom(".welcome-banner .welcome-banner__title input").doesNotExist();});+ test("shows the new member message for users without previous_visit_at", async function (assert) {+ this.currentUser.previous_visit_at = null;+ await render(<template><WelcomeBanner /></template>);++ assert.dom(".welcome-banner").containsText(+ i18n("welcome_banner.header.new_members", {+ preferred_display_name: "eviltrout",+ }),+ "banner contains the correct message for new users"+ );+ });+test("uses the welcome_banner.search_placeholder translation for placeholder", async function (assert) {await render(<template><WelcomeBanner /></template>);diff --git a/spec/fabricators/user_fabricator.rb b/spec/fabricators/user_fabricator.rbindex 4fad20d96e1..0c147430cba 100644--- a/spec/fabricators/user_fabricator.rb+++ b/spec/fabricators/user_fabricator.rb@@ -7,6 +7,7 @@ Fabricator(:user, class_name: :user) dotransient trust_level: niltransient search_index: falsetransient composition_mode: UserOption.composition_mode_types[:markdown]+ transient seen_before: falsename "Bruce Wayne"username { sequence(:username) { |i| "bruce#{i}" } }@@ -28,6 +29,10 @@ Fabricator(:user, class_name: :user) do# of specs failing when setting SiteSetting.rich_editor default to true and SiteSetting.default_composition_mode# default to richuser.user_option.update!(composition_mode: transients[:composition_mode])++ if transients[:seen_before]+ user.update!(last_seen_at: 2.days.ago, previous_visit_at: 2.days.ago)+ endendbefore_create { |user, transients| SearchIndexer.enable if transients[:search_index] }diff --git a/spec/system/page_objects/components/welcome_banner.rb b/spec/system/page_objects/components/welcome_banner.rbindex 5e809b06a89..5fb58da5919 100644--- a/spec/system/page_objects/components/welcome_banner.rb+++ b/spec/system/page_objects/components/welcome_banner.rb@@ -30,6 +30,13 @@ module PageObjects)end+ def has_new_user_title?(username)+ has_css?(+ ".welcome-banner .welcome-banner__title",+ text: I18n.t("js.welcome_banner.header.new_members", preferred_display_name: username),+ )+ end+def has_no_subheader?has_no_css?(".welcome-banner .welcome-banner__subheader")enddiff --git a/spec/system/welcome_banner_spec.rb b/spec/system/welcome_banner_spec.rbindex 56af23b59b4..3077c1ae875 100644--- a/spec/system/welcome_banner_spec.rb+++ b/spec/system/welcome_banner_spec.rb@@ -1,7 +1,7 @@# frozen_string_literal: truedescribe "Welcome banner", type: :system do- fab!(:current_user, :user)+ fab!(:current_user) { Fabricate(:user, seen_before: true) }let(:banner) { PageObjects::Components::WelcomeBanner.new }let(:search_page) { PageObjects::Pages::Search.new }@@ -24,6 +24,16 @@ describe "Welcome banner", type: :system doexpect(banner).to have_logged_in_title(current_user.username)end+ context "for new users who have not visited before" do+ fab!(:current_user, :user)++ it "shows a new user title" do+ sign_in(current_user)+ visit "/"+ expect(banner).to have_new_user_title(current_user.username)+ end+ end+context "with subheader translations" doit "shows subheader for logged in and anonymous members" dovisit "/"