Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby
4.8 KB
Raw Blame
<%# locals: (plaid_item:, visible_accounts:) %>

<%= tag.div id: dom_id(plaid_item) do %>
  <%= render DS::Disclosure.new(variant: :card, open: true) do |disclosure| %>
    <% disclosure.with_summary_content do %>
      <div class="flex items-center justify-between gap-2">
        <div class="flex items-center gap-2">
          <%= icon "chevron-right", class: "group-open:rotate-90 motion-safe:transition-transform motion-safe:duration-150" %>

          <%= render ProviderLogo.new(provider_key: :plaid) %>

          <div class="pl-1 text-sm">
            <div class="flex items-center gap-2">
              <%= tag.p plaid_item.name, class: "font-medium text-primary" %>
              <% if plaid_item.scheduled_for_deletion? %>
                <p class="text-destructive text-sm animate-pulse"><%= t(".deletion_in_progress") %></p>
              <% end %>
            </div>
            <p class="text-xs text-secondary"><%= t(".provider_name") %></p>
            <% if plaid_item.syncing? %>
              <div class="text-secondary flex items-center gap-1">
                <%= icon "loader", size: "sm", class: "animate-pulse" %>
                <%= tag.span t(".syncing") %>
              </div>
            <% elsif plaid_item.requires_update? %>
              <div class="text-warning flex items-center gap-1">
                <%= icon "alert-triangle", size: "sm", color: "warning" %>
                <%= tag.span t(".requires_update") %>
              </div>
            <% elsif plaid_item.sync_error.present? %>
              <div class="text-secondary flex items-center gap-1">
                <%= icon "alert-circle", size: "sm", color: "destructive" %>
                <%= tag.span t(".error"), class: "text-destructive" %>
              </div>
            <% else %>
              <p class="text-secondary">
                <%= plaid_item.last_synced_at ? t(".status", timestamp: time_ago_in_words(plaid_item.last_synced_at)) : t(".status_never") %>
              </p>
            <% end %>
          </div>
        </div>

        <% if plaid_item.manageable_by?(Current.user) %>
          <div class="flex items-center gap-2">
            <% if plaid_item.requires_update? %>
              <%= render DS::Link.new(
                text: t(".update"),
                icon: "refresh-cw",
                variant: "secondary",
                href: edit_plaid_item_path(plaid_item),
                frame: "modal"
              ) %>
            <% elsif plaid_item.us? %>
              <%= render DS::Link.new(
                text: t(".add_accounts"),
                icon: "circle-plus",
                variant: "secondary",
                href: edit_plaid_item_path(plaid_item, add_accounts: true),
                frame: "modal"
              ) %>
            <% elsif Rails.env.development? %>
              <%= icon(
                "refresh-cw",
                as_button: true,
                href: sync_plaid_item_path(plaid_item)
              ) %>
            <% end %>

            <%= render DS::Menu.new do |menu| %>
              <% sync_schedule_menu_item(menu, plaid_item) %>
              <% menu.with_item(
                variant: "button",
                text: t(".delete"),
                icon: "trash-2",
                href: plaid_item_path(plaid_item),
                method: :delete,
                confirm: CustomConfirm.for_resource_deletion(plaid_item.name, high_severity: true)
              ) %>
            <% end %>
          </div>
        <% end %>
      </div>
    <% end %>

    <% unless plaid_item.scheduled_for_deletion? %>
      <div class="space-y-4 mt-4">
        <%# The accounts index passes visible_accounts filtered to the viewer
            (AccountsController#visible_card_accounts). Nothing here reads
            Current.user: the partial can be rendered outside a request, where
            it is nil. %>
        <% if visible_accounts.any? %>
          <%= render "accounts/index/account_groups", accounts: visible_accounts %>
        <% end %>

        <%# Sync summary (collapsible) - using shared ProviderSyncSummary component %>
        <% stats = if defined?(@plaid_sync_stats_map) && @plaid_sync_stats_map
             @plaid_sync_stats_map[plaid_item.id] || {}
           else
             plaid_item.syncs.ordered.first&.sync_stats || {}
           end %>
        <%= render ProviderSyncSummary.new(
          stats: stats,
          provider_item: plaid_item, show_account_details: visible_accounts.size == plaid_item.accounts.size
        ) %>

        <% if plaid_item.accounts.empty? %>
          <div class="p-4 flex flex-col gap-3 items-center justify-center">
            <p class="text-primary font-medium text-sm"><%= t(".no_accounts_title") %></p>
            <p class="text-secondary text-sm"><%= t(".no_accounts_description") %></p>
          </div>
        <% end %>
      </div>
    <% end %>
  <% end %>
<% end %>