Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby
3.2 KB
Raw Blame
<%# Everything about one bill, in the drawer, the way a transaction or a
    budget category opens. Opened from a row, the list stays where it was, so
    closing this lands back on the same row. There is no separate bill page:
    a direct visit renders the overview with this drawer already open. %>
<%= render DS::Dialog.new(variant: :drawer) do |dialog| %>
  <% dialog.with_header(custom_header: true) do %>
    <div class="flex items-start justify-between gap-2">
      <div class="min-w-0 space-y-1.5">
        <% if @series.category %>
          <%= render "categories/badge", category: @series.category %>
        <% end %>
        <h2 id="<%= dialog.title_id %>" class="text-lg font-medium text-primary"><%= @series.display_name %></h2>
      </div>

      <div class="flex items-center gap-1 shrink-0">
        <%# Pause and remove answer with the whole page, so they leave the
            drawer's frame. Edit and AI open as modals over the drawer. %>
        <%= render DS::Menu.new do |menu| %>
          <% menu.with_item(
               variant: "link",
               text: t("bills.show.edit"),
               icon: "pencil",
               href: edit_recurring_transaction_path(@series),
               data: { turbo_frame: :modal }) %>
          <% if ai_feature_available?(:bill_setup) %>
            <% menu.with_item(
                 variant: "link",
                 text: t("bills.smart_configurations.show.trigger"),
                 icon: "sparkles",
                 href: smart_configuration_bill_path(@series),
                 data: { turbo_frame: :modal }) %>
          <% end %>
          <% menu.with_item(
               variant: "button",
               text: @series.active? ? t("recurring_transactions.actions.pause") : t("recurring_transactions.actions.resume"),
               icon: @series.active? ? "pause" : "play",
               href: toggle_status_recurring_transaction_path(@series),
               method: :post,
               frame: "_top") %>
          <% menu.with_item(
               variant: "button",
               text: t("recurring_transactions.actions.delete"),
               icon: "trash-2",
               href: recurring_transaction_path(@series),
               method: :delete,
               destructive: true,
               frame: "_top",
               confirm: t(@series.typed_income? ? "recurring_transactions.confirm_delete_income" : "recurring_transactions.confirm_delete", name: @series.display_name)) %>
        <% end %>
        <%= dialog.close_button %>
      </div>
    </div>
  <% end %>

  <% dialog.with_body do %>
    <div class="space-y-4">
      <%= render "bills/summary",
            series: @series,
            current_occurrence: @current_occurrence,
            suggestion: @drawer_suggestion,
            settled_occurrence: @latest_paid_occurrence %>

      <%# The collapsible sections: Overview, Coming up, History and Notes.
          Lazy, so opening a bill costs no more than its summary;
          refresh: :morph, or a morph refresh would empty it. %>
      <%= turbo_frame_tag dom_id(@series, :history),
            src: bill_path(@series, display: "history"),
            loading: :lazy,
            refresh: :morph,
            class: "block" %>
    </div>
  <% end %>
<% end %>