Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby
4.9 KB
Raw Blame
<%# locals: (up_item:, visible_accounts:) %>

<%= tag.div id: dom_id(up_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 w-full">
        <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: :up) %>

          <div class="pl-1 text-sm">
            <div class="flex items-center gap-2">
              <%= tag.p up_item.name, class: "font-medium text-primary" %>
              <% if up_item.scheduled_for_deletion? %>
                <p class="text-destructive text-sm animate-pulse"><%= t(".deletion_in_progress") %></p>
              <% end %>
            </div>

            <%# The institution belongs to every account on the connection, so it is
                shown only to a viewer who can see them all (#3630). %>
            <% if up_item.accounts.any? && visible_accounts.size == up_item.accounts.size %>
              <p class="text-xs text-secondary"><%= up_item.institution_summary %></p>
            <% end %>

            <% if up_item.syncing? %>
              <div class="text-secondary flex items-center gap-1">
                <%= icon "loader", size: "sm", class: "animate-spin" %>
                <%= tag.span t(".syncing") %>
              </div>
            <% elsif up_item.sync_error.present? %>
              <div class="text-secondary flex items-center gap-1">
                <%= render DS::Tooltip.new(text: up_item.sync_error, icon: "alert-circle", size: "sm", color: "destructive", as: :span) %>
                <%= tag.span t(".error"), class: "text-destructive" %>
              </div>
            <% else %>
              <p class="text-secondary">
                <% if up_item.last_synced_at %>
                  <%= t(".status_with_summary", timestamp: time_ago_in_words(up_item.last_synced_at), summary: up_item.sync_status_summary) %>
                <% else %>
                  <%= t(".status_never") %>
                <% end %>
              </p>
            <% end %>
          </div>
        </div>

        <% if Current.user&.admin? %>
          <div class="flex items-center gap-2">
            <%= render DS::Menu.new do |menu| %>
              <% sync_schedule_menu_item(menu, up_item) %>
              <% menu.with_item(
                variant: "button",
                text: t(".delete"),
                icon: "trash-2",
                href: up_item_path(up_item),
                method: :delete,
                confirm: CustomConfirm.for_resource_deletion(up_item.name, high_severity: true)
              ) %>
            <% end %>
          </div>
        <% end %>
      </div>
    <% end %>

    <% unless up_item.scheduled_for_deletion? %>
      <div class="space-y-4 mt-4">
        <% if visible_accounts.any? %>
          <%= render "accounts/index/account_groups", accounts: visible_accounts %>
        <% end %>

        <% stats = if defined?(@up_sync_stats_map) && @up_sync_stats_map
             @up_sync_stats_map[up_item.id] || {}
           else
             up_item.syncs.ordered.first&.sync_stats || {}
           end %>
        <%= render ProviderSyncSummary.new(
          stats: stats,
          provider_item: up_item, show_account_details: visible_accounts.size == up_item.accounts.size,
          institutions_count: up_item.connected_institutions.size
        ) %>

        <% unlinked_count = up_item.unlinked_accounts_count %>
        <% linked_count = up_item.linked_accounts_count %>
        <% total_count = up_item.total_accounts_count %>

        <% if unlinked_count > 0 %>
          <div class="p-4 flex flex-col gap-3 items-center justify-center">
            <p class="text-primary font-medium text-sm"><%= t(".setup_needed") %></p>
            <p class="text-secondary text-sm"><%= t(".setup_description", linked: linked_count, total: total_count) %></p>
            <%= render DS::Link.new(
              text: t(".setup_action"),
              icon: "settings",
              variant: "primary",
              href: setup_accounts_up_item_path(up_item),
              frame: :modal
            ) %>
          </div>
        <% elsif up_item.accounts.empty? && total_count == 0 %>
          <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>
            <%= render DS::Link.new(
              text: t(".setup_action"),
              icon: "settings",
              variant: "primary",
              href: setup_accounts_up_item_path(up_item),
              frame: :modal
            ) %>
          </div>
        <% end %>
      </div>
    <% end %>
  <% end %>
<% end %>