Skip to content

Open-source live-chat, email support, omni-channel desk. An alternative to Intercom, Zendesk, Salesforce Service Cloud etc. 🔥💬

5.6 KB
Raw Blame
<%# The account page: a hero with the key facts, then one tab per concern. `page` is an Administrate::Page::Show. %>

<% content_for(:title) { t("administrate.actions.show_resource", name: page.page_title) } %>
<% content_for(:commands) { render "command_group", label: page.page_title, commands: record_commands(page.resource) } %>
<%
  account = page.resource
  fields = page.attributes.values.flatten.index_by(&:name)
  users_count = fields["account_users"].data.size
  tabs = [
    { key: "overview", label: t("super_admin.record.overview"), icon: "i-lucide-layout-list" },
    { key: "users", label: t("super_admin.accounts.users"), icon: "i-lucide-users", count: users_count },
    ({ key: "features", label: t("super_admin.features.title"), icon: "i-lucide-toggle-right" } if fields["all_features"]),
    ({ key: "captain", label: t("super_admin.accounts.captain_models"), icon: "i-lucide-sparkles" } if fields["captain_models"]),
    { key: "maintenance", label: t("super_admin.accounts.maintenance"), icon: "i-lucide-wrench" }
  ].compact
  active = active_tab(tabs)
%>

<%= render "hero",
           title: account.name,
           back: display_resource_name(page.resource_name),
           badges: render_field(fields["status"]),
           details: { "i-lucide-hash" => account.id, "i-lucide-languages" => account.locale },
           facts: [
             { label: t("super_admin.accounts.users"), value: number_with_delimiter(users_count), icon: "i-lucide-users text-n-iris-10" },
             { label: t("super_admin.accounts.conversations"), value: number_with_delimiter(fields["conversations"].to_s), icon: "i-lucide-messages-square text-n-amber-11" },
             { label: t("super_admin.record.created"), value: l(account.created_at.to_date, format: "%b %-d, %Y"), icon: "i-lucide-calendar text-n-teal-10" },
             { label: t("super_admin.record.last_updated"), value: t("super_admin.record.time_ago", time: time_ago_in_words(account.updated_at)).upcase_first, icon: "i-lucide-history text-n-blue-10" }
           ] do %>
  <%= render("button", label: t("administrate.actions.edit"), url: [:edit, namespace, page.resource]) if accessible_action?(page.resource, :edit) %>
<% end %>

<%= render "tabs", tabs: tabs, active: active %>

<div role="tabpanel" id="panel-overview" aria-labelledby="tab-overview" data-tab-panel="overview" <%= "hidden" unless active == "overview" %>>
  <div class="space-y-6 pt-6">
    <%= render "card", title: t("super_admin.record.profile") do %>
      <%= render "attributes", page: page, attributes: fields.values_at("id", "name", "locale", "status", "created_at", "updated_at") %>
    <% end %>

    <div class="grid grid-cols-1 items-start gap-6 lg:grid-cols-[repeat(auto-fit,minmax(20rem,1fr))]">
      <% if fields["limits"] %>
        <%= render "card", title: t("super_admin.accounts.limits") do %>
          <div class="px-4 text-body-main"><%= render_field fields["limits"], page: page %></div>
        <% end %>
      <% end %>

      <%= render "card", title: t("super_admin.accounts.suspension_history") do %>
        <%= render_field fields["suspension_history"], page: page %>
      <% end %>
    </div>

    <% if fields["custom_attributes"]&.data.present? %>
      <%= render "card", title: t("super_admin.accounts.custom_attributes") do %>
        <dl class="-mb-px grid grid-cols-1 overflow-hidden rounded-b-xl sm:grid-cols-2">
          <% fields["custom_attributes"].data.each do |key, value| %>
            <div class="min-w-0 border-b border-n-weak px-4 py-3 sm:odd:border-e">
              <dt class="font-mono text-xs text-n-slate-10"><%= key %></dt>
              <dd class="mt-1 break-all text-body-main text-n-slate-12"><%= value.nil? ? "–" : value %></dd>
            </div>
          <% end %>
        </dl>
      <% end %>
    <% end %>
  </div>
</div>

<div role="tabpanel" id="panel-users" aria-labelledby="tab-users" data-tab-panel="users" <%= "hidden" unless active == "users" %>>
  <div class="space-y-6 pt-6">
    <%= render_field fields["account_users"], page: page %>
    <%= render "super_admin/shared/account_user_form", page: page, resource_type: "account" %>
  </div>
</div>

<% if fields["all_features"] %>
  <div role="tabpanel" id="panel-features" aria-labelledby="tab-features" data-tab-panel="features" <%= "hidden" unless active == "features" %>>
    <div class="space-y-6 pt-6">
      <div class="text-body-main"><%= render_field fields["all_features"], page: page %></div>

      <% if fields["manually_managed_features"] %>
        <%= render "card", title: t("super_admin.accounts.manually_managed_features"), meta: fields["manually_managed_features"].selected_features.size, collapsible: true do %>
          <div class="p-4 text-body-main"><%= render_field fields["manually_managed_features"], page: page %></div>
        <% end %>
      <% end %>
    </div>
  </div>
<% end %>

<% if fields["captain_models"] %>
  <div role="tabpanel" id="panel-captain" aria-labelledby="tab-captain" data-tab-panel="captain" <%= "hidden" unless active == "captain" %>>
    <div class="rounded-xl border border-n-weak bg-n-solid-1 mt-6 p-4">
      <h2 class="text-xs font-medium uppercase tracking-wider text-n-slate-10 mb-2" id="captain_models"><%= t("super_admin.accounts.captain_models") %></h2>
      <%= render_field fields["captain_models"], page: page %>
    </div>
  </div>
<% end %>

<div role="tabpanel" id="panel-maintenance" aria-labelledby="tab-maintenance" data-tab-panel="maintenance" <%= "hidden" unless active == "maintenance" %>>
  <div class="rounded-xl border border-n-weak bg-n-solid-1 mt-6 divide-y divide-n-weak">
    <%= render "seed_data", page: page %>
    <%= render "reset_cache", page: page %>
  </div>
</div>