Move admin header partial to a component

This way it's easier to refactor it.

Note we're using `with_request_url` in the tests because the component
renders the locale switcher, which needs a URL in order to work. This
doesn't affect whether we're in the management section or not.
This commit is contained in:
Javi Martín
2023-01-05 14:12:19 +01:00
parent d27bfb2afd
commit 86fd14f8f0
9 changed files with 153 additions and 142 deletions

View File

@@ -0,0 +1,50 @@
<header class="header">
<div class="top-links">
<%= render "shared/locale_switcher" %>
<%= link_to root_path do %>
<%= t("admin.dashboard.index.back", org: setting["org_name"]) %>
<% end %>
</div>
<div class="expanded row admin-top-bar">
<div class="title-bar" data-responsive-toggle="responsive_menu" data-hide-for="medium">
<button class="menu-button" type="button" data-toggle="responsive_menu">
<span class="menu-icon"></span>
<span class="title-bar-title"><%= t("application.menu") %></span>
</button>
</div>
<div class="top-bar">
<div class="top-bar-left">
<% if namespace == "officing" %>
<h1>
<%= link_to "#" do %>
<%= setting["org_name"] %>
<br><small><%= namespaced_header_title %></small>
<% end %>
</h1>
<% else %>
<h1>
<%= link_to namespaced_root_path do %>
<%= setting["org_name"] %>
<br><small><%= namespaced_header_title %></small>
<% end %>
</h1>
<% end %>
</div>
<% if show_admin_menu?(user) || namespace != "management" %>
<div id="responsive_menu">
<div class="top-bar-right">
<ul class="menu" data-responsive-menu="medium-dropdown">
<%= render "shared/admin_login_items", current_user: user %>
<%= render "layouts/notification_item", current_user: user %>
<%= render "devise/menu/login_items", current_user: user %>
</ul>
</div>
</div>
<% end %>
</div>
</div>
</header>

View File

@@ -0,0 +1,20 @@
class Layout::AdminHeaderComponent < ApplicationComponent
attr_reader :user
delegate :namespace, :namespaced_root_path, :show_admin_menu?, to: :helpers
def initialize(user)
@user = user
end
private
def namespaced_header_title
if namespace == "moderation/budgets"
t("moderation.header.title")
elsif namespace == "management"
t("management.dashboard.index.title")
else
t("#{namespace}.header.title")
end
end
end