feat(savings_goals/index): collapsed Archived section + archived-aware card

- Controller: @archived_goals exposes state=archived rows already pulled
  by the all_goals load. No extra query (sliced from the existing array).
- Index template: <details> disclosure under "Completed" so archived
  goals are reachable from the list without cluttering the active /
  completed sections. Collapsed by default.
- GoalCardComponent: uses display_status for the data attribute (so the
  card on the index reads as Archived instead of Behind), opacity-75
  applies to archived too, footer_line short-circuits to "Archived" and
  pace_line returns nil. Matches the show-page archived semantics
  shipped earlier.
- Locale: new savings_goals.index.archived_section.heading and
  savings_goals.goal_card.footer_archived.
This commit is contained in:
Guillem Arias
2026-05-11 19:52:52 +02:00
parent af41dcaf64
commit 560bff87d2
5 changed files with 28 additions and 4 deletions

View File

@@ -1,9 +1,9 @@
<%= link_to savings_goal_path(goal),
class: "group block bg-container rounded-xl shadow-border-xs hover:bg-surface-hover transition-colors p-6 #{"opacity-75" if goal.paused?}",
class: "group block bg-container rounded-xl shadow-border-xs hover:bg-surface-hover transition-colors p-6 #{"opacity-75" if goal.paused? || goal.archived?}",
data: {
savings_goals_filter_target: "card",
goal_name: goal.name,
goal_status: goal.paused? ? "paused" : goal.status
goal_status: goal.display_status
} do %>
<div class="flex items-start gap-3">
<%= render Savings::GoalAvatarComponent.new(goal: goal, size: "lg") %>

View File

@@ -58,7 +58,7 @@ class Savings::GoalCardComponent < ApplicationComponent
end
def pace_line
return nil if goal.paused? || goal.completed? || goal.status == :reached
return nil if goal.archived? || goal.paused? || goal.completed? || goal.status == :reached
avg = Money.new(goal.average_monthly_contribution, goal.currency).format
target = goal.monthly_target_amount ? Money.new(goal.monthly_target_amount, goal.currency).format : nil
@@ -70,7 +70,9 @@ class Savings::GoalCardComponent < ApplicationComponent
end
def footer_line
if goal.paused?
if goal.archived?
I18n.t("savings_goals.goal_card.footer_archived")
elsif goal.paused?
I18n.t("savings_goals.goal_card.footer_paused")
elsif goal.completed? || goal.status == :reached
I18n.t("savings_goals.goal_card.footer_reached")

View File

@@ -13,6 +13,7 @@ class SavingsGoalsController < ApplicationController
@active_goals = all_goals.reject { |g| %w[completed archived].include?(g.state) }
.sort_by { |g| [ g.paused? ? 3 : ACTIVE_STATUS_RANK.fetch(g.status, 4), g.name.downcase ] }
@completed_goals = all_goals.select { |g| g.state == "completed" }
@archived_goals = all_goals.select { |g| g.state == "archived" }
@linkable_account_count = Current.family.accounts.where(accountable_type: "Depository").visible.count
@kpi = kpi_payload(@active_goals)

View File

@@ -168,5 +168,23 @@
</div>
</section>
<% end %>
<% if @archived_goals.any? %>
<section>
<details class="group">
<summary class="inline-flex items-center gap-1.5 mb-4 text-[11px] font-medium uppercase tracking-wide text-secondary cursor-pointer list-none">
<span class="text-subdued group-open:rotate-90 transition-transform"><%= icon("chevron-right", size: "sm") %></span>
<span><%= t(".archived_section.heading") %></span>
<span class="text-subdued">·</span>
<span class="tabular-nums"><%= @archived_goals.size %></span>
</summary>
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3.5">
<% @archived_goals.each do |goal| %>
<%= render Savings::GoalCardComponent.new(goal: goal) %>
<% end %>
</div>
</details>
</section>
<% end %>
<% end %>
</div>

View File

@@ -37,6 +37,8 @@ en:
heading: Ongoing
completed_section:
heading: Completed
archived_section:
heading: Archived
search:
placeholder: Search goals…
aria_label: Search savings goals
@@ -199,6 +201,7 @@ en:
pace_with_target: "%{avg}/mo · target %{target}/mo"
pace_no_target: "%{avg}/mo avg"
footer_paused: Paused
footer_archived: Archived
footer_reached: Goal reached
footer_catch_up: "Save %{amount}/mo to catch up"
footer_no_deadline: No deadline set