mirror of
https://github.com/we-promise/sure.git
synced 2026-04-22 21:44:11 +00:00
* feat: Add :logo variant in account dropdown on transfer form * fix test * fix test * fix: avoid multiple queries on accounts
40 lines
2.0 KiB
Plaintext
40 lines
2.0 KiB
Plaintext
<%= styled_form_with model: transfer, class: "space-y-4", data: { turbo_frame: "_top", controller: "transfer-form" } do |f| %>
|
|
<% if transfer.errors.present? %>
|
|
<div class="text-destructive flex items-center gap-2">
|
|
<%= icon "circle-alert", size: "sm" %>
|
|
<p class="text-sm"><%= @transfer.errors.full_messages.to_sentence %></p>
|
|
</div>
|
|
<% end %>
|
|
|
|
<%# Hide expense/income tabs when creating a transfer involving an investment or crypto account. %>
|
|
<% show_type_tabs = true %>
|
|
<% account_ids = [] %>
|
|
<% account_ids << @from_account_id if defined?(@from_account_id) && @from_account_id.present? %>
|
|
<% account_ids << params[:from_account_id] if params[:from_account_id].present? %>
|
|
<% account_ids << params[:to_account_id] if params[:to_account_id].present? %>
|
|
<% account_ids << transfer.from_account_id if transfer.respond_to?(:from_account_id) && transfer.from_account_id.present? %>
|
|
<% account_ids << transfer.to_account_id if transfer.respond_to?(:to_account_id) && transfer.to_account_id.present? %>
|
|
<% selected_accounts = @accounts.select { |a| account_ids.include?(a.id) } %>
|
|
|
|
<% if selected_accounts.any? { |a| a.investment? || a.crypto? } %>
|
|
<% show_type_tabs = false %>
|
|
<% end %>
|
|
|
|
<% if show_type_tabs %>
|
|
<section>
|
|
<%= render "shared/transaction_type_tabs", active_tab: "transfer" %>
|
|
</section>
|
|
<% end %>
|
|
|
|
<section class="space-y-2">
|
|
<%= f.collection_select :from_account_id, @accounts, :id, :name, { prompt: t(".select_account"), label: t(".from"), selected: @from_account_id, variant: :logo }, required: true %>
|
|
<%= f.collection_select :to_account_id, @accounts, :id, :name, { prompt: t(".select_account"), label: t(".to"), variant: :logo }, required: true %>
|
|
<%= f.number_field :amount, label: t(".amount"), required: true, min: 0, placeholder: "100", step: 0.00000001 %>
|
|
<%= f.date_field :date, value: transfer.inflow_transaction&.entry&.date || Date.current, label: t(".date"), required: true, max: Date.current %>
|
|
</section>
|
|
|
|
<section>
|
|
<%= f.submit t(".submit") %>
|
|
</section>
|
|
<% end %>
|