The personal finance app for everyone (by everyone)
Ruby
<%= render DS::Dialog.new do |dialog| %>
<% dialog.with_header(title: @recurring_transaction.is_income ? t(".income_title") : t(".title")) %>
<% dialog.with_body do %>
<% if @candidates.present? %>
<div class="space-y-2 mb-5">
<p class="text-sm font-medium text-primary">
<%= @recurring_transaction.is_income ? t(".start_from_income_title") : t(".start_from_title") %>
</p>
<div class="max-h-44 overflow-y-auto rounded-lg shadow-border-xs divide-y divide-subdued">
<% @candidates.each do |candidate| %>
<%= link_to new_recurring_transaction_path(entry_id: candidate[:entry_id], income: params[:income].presence),
class: "flex items-center justify-between gap-3 px-3 py-2 hover:bg-surface-inset" do %>
<div class="min-w-0">
<p class="text-sm text-primary truncate"><%= candidate[:name] %></p>
<p class="text-xs text-secondary">
<%= t(".candidate_meta", count: candidate[:count], date: l(candidate[:last_date], format: :short_with_year)) %>
</p>
</div>
<p class="text-sm text-primary privacy-sensitive shrink-0">
<%= format_money(Money.new(candidate[:amount], candidate[:currency])) %>
</p>
<% end %>
<% end %>
</div>
<p class="text-xs text-secondary"><%= t(".start_from_hint") %></p>
</div>
<% end %>
<%# Reachable whether or not detection found anything, and before the form
so a search does not throw away typed fields. %>
<div class="mb-5 text-sm flex flex-wrap items-center gap-x-3 gap-y-1">
<% if params[:entry_id].present? %>
<%= render DS::Link.new(
text: t(".pick_different"),
variant: :default,
href: new_recurring_transaction_path(picker: 1, income: params[:income].presence)
) %>
<%# Smart-fill needs the picked transaction as its evidence anchor, so
it only exists on this variant: with no anchor it would guess.
DS::Link translates method: into data-turbo-method, so this is a
real POST; the anchor rides the query string. %>
<% if ai_feature_available?(:bill_setup) %>
<%= render DS::Link.new(
text: t(".smart_fill"),
icon: "sparkles",
variant: :default,
href: smart_fill_recurring_transactions_path(entry_id: params[:entry_id], income: params[:income].presence),
method: :post,
frame: :modal
) %>
<% end %>
<% else %>
<span class="text-secondary"><%= t(".search_all_prompt") %></span>
<%= render DS::Link.new(
text: t(".search_all_cta"),
variant: :default,
href: new_recurring_transaction_path(picker: 1, income: params[:income].presence)
) %>
<% end %>
</div>
<% if @smart_fill %>
<div class="mb-5 rounded-lg bg-container-inset px-3 py-2 text-sm">
<p class="text-primary"><%= t(".smart_fill_applied") %></p>
<% if @smart_fill.rationale.present? %>
<p class="text-xs text-secondary"><%= @smart_fill.rationale %></p>
<% end %>
</div>
<% elsif @smart_fill_error %>
<div class="mb-5 rounded-lg bg-container-inset px-3 py-2 text-sm text-secondary">
<%= @smart_fill_error %>
</div>
<% end %>
<% if @covering_series %>
<%# The transaction this dialog was opened from is already paying a bill.
Saving would count it twice, so the bill comes first and the form
waits behind a deliberate choice: a second price tier is the one
legitimate reason to want another. %>
<%# A suggestion is that bill, found by detection and not yet confirmed.
Confirming it links this payment; a separate bill would become the
duplicate the moment the suggestion was confirmed. %>
<%# Income is stored negative, so an inflow's covering series is income
and the warning names it as such. %>
<% suggested = @covering_series.suggested? %>
<% covered = @covering_series.amount.negative? ? ".covered_income" : ".covered" %>
<div class="mb-5">
<%= render DS::Alert.new(title: t(suggested ? "#{covered}_suggested_title" : "#{covered}_title"), variant: :warning, live: :polite) do %>
<p><%= t(suggested ? "#{covered}_suggested_body" : "#{covered}_body", name: @covering_series.display_name) %></p>
<div class="flex flex-wrap items-center gap-3">
<% if suggested && series_writable?(@covering_series) %>
<%= render DS::Link.new(
text: t("#{covered}_confirm"),
variant: "primary",
href: confirm_recurring_transaction_path(@covering_series),
method: :post,
frame: "_top"
) %>
<% end %>
<%= render DS::Link.new(
text: t("#{covered}_open"),
variant: :default,
href: bill_path(@covering_series),
frame: "_top"
) %>
</div>
<% end %>
</div>
<%= render DS::Disclosure.new(title: t("#{covered}_create_anyway"), align: "left") do %>
<div class="pt-2">
<%= render "form", recurring_transaction: @recurring_transaction, sibling_count: 0,
source_entry_id: @source_entry&.id, allow_duplicate: true %>
</div>
<% end %>
<% else %>
<%# A failed save after "anyway" keeps that choice for the resubmit. %>
<%= render "form", recurring_transaction: @recurring_transaction, sibling_count: 0,
source_entry_id: @source_entry&.id,
allow_duplicate: separate_bill_chosen? %>
<% end %>
<% end %>
<% end %>