[deploy] Only show user count for large userbases (#11021)

This is a request from one of our early adopter Forems. We should only
render the user count that appears on most of our sign up CTAs when a
Forem has a large userbase (initially, I'm setting that to 1000 users).

The change also removes a lot of duplicated markup by using some
partials to render the copy in the various auth CTAs.

Hopefully, this is written in such a way that changing opening up more
fine-grained control of these partials is trivial.
This commit is contained in:
Jacob Herrington 2020-10-23 09:00:59 -05:00 committed by GitHub
parent 5b1f058764
commit ff177b0c09
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 32 additions and 42 deletions

View file

@ -2,8 +2,6 @@ class RegistrationsController < Devise::RegistrationsController
prepend_before_action :require_no_authentication, only: []
def new
@registered_users_count = User.registered.estimated_count
if user_signed_in?
redirect_to root_path(signin: "true")
else

View file

@ -11,6 +11,8 @@ module ApplicationHelper
)
# rubocop:enable Performance/OpenStruct
LARGE_USERBASE_THRESHOLD = 1000
def user_logged_in_status
user_signed_in? ? "logged-in" : "logged-out"
end
@ -281,6 +283,14 @@ module ApplicationHelper
HTMLEntities.new.decode(sanitize(str).to_str)
end
def estimated_user_count
User.registered.estimated_count
end
def display_estimated_user_count?
estimated_user_count > LARGE_USERBASE_THRESHOLD
end
# rubocop:disable Rails/OutputSafety
def admin_config_label(method, content = nil)
content ||= raw("<span>#{method.to_s.humanize}</span>")

View file

@ -10,22 +10,13 @@
</figure>
<div class="authentication-widget__content">
<h3 class="authentication-widget__title">
<a href="/"><%= community_name %></a> is a community of <%= number_with_delimiter User.registered.estimated_count %> amazing <%= community_members_label %>
<%= render "shared/authentication_title" %>
</h3>
<p class="authentication-widget__description">
<% if SiteConfig.tagline.present? %>
<%= SiteConfig.tagline %>
<% else %>
Log in to customize your experience and get involved.
<% end %>
<%= render "shared/authentication_description" %>
</p>
<div class="authentication-widget__actions">
<a href="<%= sign_up_path(state: "new-user") %>" class="crayons-btn" aria-label="Create new account">
Create new account
</a>
<a href="<%= sign_up_path %>" class="crayons-btn crayons-btn--ghost-brand" aria-label="Log in">
Log in
</a>
<%= render "shared/authentication_actions" %>
</div>
</div>
</div>

View file

@ -9,9 +9,7 @@
<% end %>
</h1>
<p class="registration__description">
<a href="/"><%= community_name %></a> is a community of
<%= number_with_delimiter(@registered_users_count) %>
amazing <%= community_members_label %>.
<%= render "shared/authentication_title" %>
</p>
</div>

View file

@ -29,22 +29,13 @@
</figure>
<div class="authentication-header__content">
<h2 class="authentication-header__title">
<a href="/"><%= community_name %></a> is a community of <%= number_with_delimiter User.registered.estimated_count %> amazing <%= community_members_label %>
<%= render "shared/authentication_title" %>
</h2>
<p class="authentication-header__description">
<% if SiteConfig.tagline.present? %>
<%= SiteConfig.tagline %>
<% else %>
Log in to customize your experience and get involved.
<% end %>
<%= render "shared/authentication_description" %>
</p>
<div class="authentication-header__actions">
<a href="<%= sign_up_path(state: "new-user") %>" class="crayons-btn" aria-label="Create new account">
Create new account
</a>
<a href="<%= sign_up_path %>" class="crayons-btn crayons-btn--ghost-brand" aria-label="Log in">
Log in
</a>
<%= render "shared/authentication_actions" %>
</div>
</div>
</div>

View file

@ -0,0 +1,6 @@
<a href="<%= sign_up_path(state: "new-user") %>" class="crayons-btn" aria-label="Create new account">
Create new account
</a>
<a href="<%= sign_up_path %>" class="crayons-btn crayons-btn--ghost-brand" aria-label="Log in">
Log in
</a>

View file

@ -0,0 +1,5 @@
<% if SiteConfig.tagline.present? %>
<%= SiteConfig.tagline %>
<% else %>
Log in to customize your experience and get involved.
<% end %>

View file

@ -0,0 +1 @@
<a href="/"><%= community_name %></a> is a community of <%= display_estimated_user_count? ? number_with_delimiter(estimated_user_count) : "" %> amazing <%= community_members_label %>

View file

@ -6,25 +6,15 @@
</figure>
<div class="authentication-feed__content">
<h2 class="authentication-feed__title">
<a href="/"><%= community_name %></a> is a community of <br />
<%= number_with_delimiter User.registered.estimated_count %> amazing <%= community_members_label %>
<%= render "shared/authentication_title" %>
</h2>
<p class="authentication-feed__description">
<% if SiteConfig.tagline.present? %>
<%= SiteConfig.tagline %>
<% else %>
Log in to customize your experience and get involved.
<% end %>
<%= render "shared/authentication_description" %>
</p>
</div>
</div>
<div class="authentication-feed__actions">
<a href="<%= sign_up_path %>" class="crayons-btn" aria-label="Create new account">
Create new account
</a>
<a href="<%= sign_up_path %>" class="crayons-btn crayons-btn--ghost-brand" aria-label="Log in">
Log in
</a>
<%= render "shared/authentication_actions" %>
</div>
</div>