The personal finance app for everyone (by everyone)
Ruby
<%# locals: (form:, entry:, candidates:, accounts:) %>
<% account_items = accounts.map { |account| { value: account.id, label: account.name, object: account } } %>
<% if candidates.any? %>
<div data-controller="transfer-match" class="space-y-2">
<p class="text-sm text-secondary">
<%= t(".select_method") %>
</p>
<%= form.select :method,
[
[t(".match_existing_recommended"), "existing"],
[t(".create_new_transaction"), "new"]
],
{ selected: "existing", label: t(".matching_method") },
data: { action: "change->transfer-match#update" } %>
<div data-transfer-match-target="existingSelect">
<%= render DS::Select.new(
form: form,
method: :matched_entry_id,
items: candidates.map { |candidate| { value: candidate.id, label: entry_name_detailed(candidate), object: candidate.account } },
selected: candidates.first.id,
variant: :logo,
label: t(".matching_transaction")
) %>
</div>
<div data-transfer-match-target="newSelect" class="hidden">
<%= render DS::Select.new(
form: form,
method: :target_account_id,
items: account_items,
selected: account_items.first&.dig(:value),
variant: :logo,
searchable: true,
label: t(".target_account")
) %>
</div>
</div>
<% else %>
<p class="text-sm text-secondary">
<%= t(".no_matching_transactions") %>
</p>
<%= form.hidden_field :method, value: "new" %>
<%= render DS::Select.new(
form: form,
method: :target_account_id,
items: account_items,
selected: account_items.first&.dig(:value),
variant: :logo,
searchable: true,
label: t(".target_account")
) %>
<% end %>