Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby
5.4 KB
Raw Blame
<%= turbo_frame_tag "hosted_usage" do %>
  <div class="space-y-4" data-testid="hosted-usage-report">
    <%= render DS::Card.new(class: "gap-4") do %>
      <div>
        <h2 class="text-lg font-semibold text-primary"><%= t(".title") %></h2>
        <p class="mt-1 text-sm text-secondary"><%= t(".snapshot", time: l(@hosted_usage.as_of, format: :long)) %></p>
      </div>
      <dl class="grid grid-cols-1 xl:grid-cols-2 gap-x-8 gap-y-4">
        <% @hosted_usage.summary.each do |metric, count| %>
          <%= render DS::DetailRow.new(
            label: t(".summary.#{metric}"), value: number_with_delimiter(count),
            class: "[&>dt]:min-w-0 [&>dt]:shrink", value_class: "font-medium tabular-nums shrink-0",
            data: { testid: "hosted-usage-#{metric}" }
          ) %>
        <% end %>
      </dl>
      <p class="text-sm text-secondary"><%= t(".summary_help") %></p>
    <% end %>

    <%= render DS::Alert.new(title: t(".limitations_title"), message: t(".limitations"), variant: :info) %>

    <%= render DS::Card.new(class: "gap-4", data: { testid: "hosted-usage-trials" }) do %>
      <div>
        <h2 class="text-lg font-semibold text-primary"><%= t(".trials.title") %></h2>
        <p class="mt-1 text-sm text-secondary"><%= t(".trials.description", date: l(@hosted_usage.window_start.to_date, format: :long), limit: @hosted_usage.row_limit) %></p>
        <p class="mt-1 text-sm text-secondary"><%= t(".trials.sessions_help") %></p>
      </div>
      <% if @hosted_usage.trials.empty? %>
        <%= render DS::EmptyState.new(icon: "users", title: t(".trials.empty")) %>
      <% else %>
        <%= render DS::Table.new(rows: @hosted_usage.trials, inset: true, label: t(".trials.title")) do |table| %>
          <% table.with_column(t(".columns.household")) do |trial| %>
            <%= render "hosted_usage_household", row: trial %>
          <% end %>
          <% table.with_column(t(".columns.recorded_at")) { |trial| l(trial.recorded_at.to_date, format: :long) } %>
          <% table.with_column(t(".columns.trial_ends_at")) { |trial| l(trial.trial_ends_at.to_date, format: :long) } %>
          <% table.with_column(t(".columns.status")) { |trial| t(".statuses.#{trial.status || :unknown}") } %>
          <% table.with_column(t(".columns.members"), numeric: true) { |trial| number_with_delimiter(trial.member_count) } %>
          <% table.with_column(t(".columns.retained_sessions"), numeric: true) { |trial| number_with_delimiter(trial.retained_sessions_count) } %>
          <% table.with_column(t(".columns.recent_sessions"), numeric: true) { |trial| number_with_delimiter(trial.sessions_created_in_window_count) } %>
          <% table.with_column(t(".columns.latest_session")) do |trial| %>
            <%= trial.latest_session_created_at ? l(trial.latest_session_created_at, format: :long) : t(".not_recorded") %>
          <% end %>
          <% table.with_column(t(".columns.cleanup_eligible")) { |trial| t(trial.cleanup_eligible ? ".eligible" : ".not_eligible") } %>
        <% end %>
      <% end %>
    <% end %>

    <%= render DS::Card.new(class: "gap-4", data: { testid: "hosted-usage-cleanup" }) do %>
      <div>
        <h2 class="text-lg font-semibold text-primary"><%= t(".cleanup.title") %></h2>
        <p class="mt-1 text-sm text-secondary"><%= t(".cleanup.description", limit: @hosted_usage.row_limit) %></p>
        <p class="mt-1 text-sm text-secondary"><%= t(".cleanup.eligibility_help") %></p>
      </div>
      <% unless @hosted_usage.cleanup_enabled? %>
        <%= render DS::Alert.new(message: t(".cleanup.disabled"), variant: :warning) %>
      <% end %>
      <% if @hosted_usage.cleanup_candidates.empty? %>
        <%= render DS::EmptyState.new(icon: "archive", title: t(".cleanup.empty")) %>
      <% else %>
        <%= render DS::Table.new(rows: @hosted_usage.cleanup_candidates, inset: true, label: t(".cleanup.title")) do |table| %>
          <% table.with_column(t(".columns.household")) do |candidate| %>
            <%= render "hosted_usage_household", row: candidate %>
          <% end %>
          <% table.with_column(t(".columns.status")) { |candidate| t(".statuses.#{candidate.status || :no_subscription}") } %>
          <% table.with_column(t(".columns.trial_ends_at")) do |candidate| %>
            <%= candidate.trial_ends_at ? l(candidate.trial_ends_at.to_date, format: :long) : t(".not_recorded") %>
          <% end %>
          <% table.with_column(t(".columns.cleanup_reason")) { |candidate| t(".cleanup.reasons.#{candidate.reason}") } %>
        <% end %>
      <% end %>
    <% end %>

    <%= render DS::Card.new(class: "gap-4", data: { testid: "hosted-usage-supporters" }) do %>
      <div>
        <h2 class="text-lg font-semibold text-primary"><%= t(".supporters.title") %></h2>
        <p class="mt-1 text-sm text-secondary"><%= t(".supporters.description") %></p>
      </div>
      <% if @hosted_usage.supporter_status_counts.values.sum.zero? %>
        <%= render DS::EmptyState.new(icon: "heart", title: t(".supporters.empty")) %>
      <% else %>
        <%= render DS::Table.new(rows: @hosted_usage.supporter_status_counts, inset: true, label: t(".supporters.title")) do |table| %>
          <% table.with_column(t(".columns.status")) { |(status, _count)| t(".statuses.#{status}") } %>
          <% table.with_column(t(".columns.subscription_rows"), numeric: true) { |(_status, count)| number_with_delimiter(count) } %>
        <% end %>
      <% end %>
    <% end %>
  </div>
<% end %>