Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby
4.9 KB
Raw Blame
<%= content_for :page_title, t("auto_matches.title") %>

<div class="space-y-4 flex flex-col">
  <div class="bg-container rounded-xl shadow-border-xs p-4">
    <div class="flex items-center justify-between">
      <div>
        <p class="text-sm font-medium text-primary"><%= t("auto_matches.settings.enable_label") %></p>
        <p class="text-xs text-secondary"><%= t("auto_matches.settings.enable_description") %></p>
        <% unless Current.user.admin? %>
          <p class="text-xs text-subdued"><%= t("auto_matches.settings.admin_only") %></p>
        <% end %>
      </div>
      <% toggle = render DS::Toggle.new(
        id: "auto_match_transfers_enabled",
        name: "toggle_display",
        checked: !@family.auto_match_transfers_disabled?,
        disabled: !Current.user.admin?,
        data: { auto_submit_form_target: "auto" }
      ) %>
      <% if Current.user.admin? %>
        <%= form_with url: update_settings_auto_matches_path, method: :patch, data: { turbo_frame: "_top", controller: "auto-submit-form" } do |f| %>
          <%= f.hidden_field :auto_match_transfers_disabled, value: @family.auto_match_transfers_disabled? ? "false" : "true" %>
          <%= toggle %>
        <% end %>
      <% else %>
        <%= toggle %>
      <% end %>
    </div>
  </div>

  <div class="bg-container rounded-xl shadow-border-xs p-4">
    <% if @pending_transfers.empty? %>
      <%= render DS::EmptyState.new(
        icon: "link-2",
        title: t("auto_matches.empty.title"),
        description: t("auto_matches.empty.description")
      ) %>
    <% else %>
      <div class="rounded-xl bg-container-inset space-y-1 p-1" data-controller="auto-match-bulk-select">
        <div class="flex items-center gap-1.5 px-4 py-2 text-xs font-medium text-secondary uppercase">
          <p><%= t("auto_matches.title") %></p>
          <span class="text-subdued"><%= t("auto_matches.table.separator") %></span>
          <p><%= @pagy.count %></p>
        </div>

        <%# Deliberately NOT wrapping the table: each row's Confirm/Reject
            button renders its own button_to form (DS::Button#href), and a
            <form> cannot legally contain another <form> -- browsers flatten
            nested forms, which merged every row's authenticity_token into
            this one and broke individual confirm/reject with a CSRF error. %>
        <%= form_with url: bulk_update_auto_matches_path, method: :patch, data: { turbo_frame: "_top", action: "submit->auto-match-bulk-select#populateIds" } do %>
          <div class="hidden items-center justify-between gap-2 px-4 py-2 mb-1 rounded-lg bg-container shadow-border-xs"
               data-auto-match-bulk-select-target="bar">
            <p class="text-xs text-secondary">
              <span data-auto-match-bulk-select-target="count">0</span> <%= t("auto_matches.bulk_actions.selected_label") %>
            </p>
            <div class="flex items-center gap-2">
              <button type="submit" name="status" value="confirmed" class="text-xs font-medium text-primary hover:underline">
                <%= t("auto_matches.bulk_actions.confirm_selected") %>
              </button>
              <button type="submit" name="status" value="rejected" class="text-xs font-medium text-destructive hover:underline">
                <%= t("auto_matches.bulk_actions.reject_selected") %>
              </button>
            </div>
          </div>
        <% end %>

        <div class="bg-container rounded-lg shadow-border-xs overflow-x-auto">
          <table class="w-full">
            <thead>
              <tr class="text-xs uppercase font-medium text-secondary border-b border-divider">
                <th class="text-left py-3 pl-4 pr-2 w-8">
                  <%= check_box_tag "select_all", "1", false,
                      class: "checkbox checkbox--light",
                      data: {
                        auto_match_bulk_select_target: "selectAll",
                        action: "auto-match-bulk-select#toggleAll"
                      },
                      aria: { label: t("auto_matches.bulk_actions.select_all") } %>
                </th>
                <th class="text-left py-3 px-2"><%= t("auto_matches.table.from") %></th>
                <th class="text-left py-3 px-2"><%= t("auto_matches.table.to") %></th>
                <th class="text-left py-3 px-2"><%= t("auto_matches.table.date") %></th>
                <th class="text-right py-3 px-2"><%= t("auto_matches.table.actions") %></th>
              </tr>
            </thead>
            <tbody>
              <% @pending_transfers.each do |transfer| %>
                <%= render "pending_transfer", transfer: transfer %>
              <% end %>
            </tbody>
          </table>
        </div>

        <% if @pagy.pages > 1 %>
          <div class="px-2 py-2">
            <%= render "shared/pagination", pagy: @pagy %>
          </div>
        <% end %>
      </div>
    <% end %>
  </div>
</div>