Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby
5.4 KB
Raw Blame
<%# locals: (brex_item:, visible_accounts:) %>
<% render_locals = brex_item_render_locals(
     brex_item,
     sync_stats_map: @brex_sync_stats_map,
     account_counts_map: @brex_account_counts_map,
     institutions_count_map: @brex_institutions_count_map
   ) %>
<% stats = render_locals[:stats] %>
<% unlinked_count = render_locals[:unlinked_count] %>
<% linked_count = render_locals[:linked_count] %>
<% total_count = render_locals[:total_count] %>
<% institutions_count = render_locals[:institutions_count] %>

<%= tag.div id: dom_id(brex_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: :brex) %>

          <div class="pl-1 text-sm">
            <div class="flex items-center gap-2">
              <%= tag.p brex_item.name, class: "font-medium text-primary" %>
              <% if brex_item.scheduled_for_deletion? %>
                <%= tag.p t(".deletion_in_progress"), class: "text-destructive text-sm animate-pulse" %>
              <% 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 brex_item.accounts.any? && visible_accounts.size == brex_item.accounts.size %>
              <p class="text-xs text-secondary">
                <%= brex_item.institution_summary %>
              </p>
            <% end %>
            <% if brex_item.syncing? %>
              <div class="text-secondary flex items-center gap-1">
                <%= icon "loader", size: "sm", class: "animate-spin" %>
                <%= tag.span t(".syncing") %>
              </div>
            <% elsif brex_item.sync_error.present? %>
              <div class="text-secondary flex items-center gap-1">
                <%= render DS::Tooltip.new(text: brex_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 brex_item.last_synced_at %>
                  <% if brex_item.sync_status_summary %>
                    <%= t(".status_with_summary", timestamp: time_ago_in_words(brex_item.last_synced_at), summary: brex_item.sync_status_summary) %>
                  <% else %>
                    <%= t(".status", timestamp: time_ago_in_words(brex_item.last_synced_at)) %>
                  <% end %>
                <% else %>
                  <%= t(".status_never") %>
                <% end %>
              </p>
            <% end %>
          </div>
        </div>

        <% if Current.user&.admin? %>
          <div class="flex items-center gap-2">
            <% if Rails.env.development? %>
              <%= icon(
                "refresh-cw",
                as_button: true,
                href: sync_brex_item_path(brex_item)
              ) %>
            <% end %>

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

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

        <%= render ProviderSyncSummary.new(
          stats: stats,
          provider_item: brex_item, show_account_details: visible_accounts.size == brex_item.accounts.size,
          institutions_count: institutions_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_brex_item_path(brex_item),
              frame: :modal
            ) %>
          </div>
        <% elsif brex_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_brex_item_path(brex_item),
              frame: :modal
            ) %>
          </div>
        <% end %>
      </div>
    <% end %>
  <% end %>
<% end %>