mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-05 05:25:24 +02:00
Fix transfers and form currencies (#1477)
This commit is contained in:
parent
fcb95207d7
commit
81d604f3d4
11 changed files with 41 additions and 19 deletions
|
@ -1,6 +1,7 @@
|
|||
<%# locals: (entry:) %>
|
||||
|
||||
<%= styled_form_with data: { turbo_frame: "_top", controller: "trade-form" },
|
||||
model: entry,
|
||||
scope: :account_entry,
|
||||
url: account_trades_path(entry.account) do |form| %>
|
||||
<div class="space-y-4">
|
||||
|
@ -15,7 +16,7 @@
|
|||
<%= form.date_field :date, label: true, value: Date.today %>
|
||||
|
||||
<div data-trade-form-target="amountInput" hidden>
|
||||
<%= form.money_field :amount, label: t(".amount"), disable_currency: true %>
|
||||
<%= form.money_field :amount, label: t(".amount") %>
|
||||
</div>
|
||||
|
||||
<div data-trade-form-target="transferAccountInput" hidden>
|
||||
|
@ -27,7 +28,7 @@
|
|||
</div>
|
||||
|
||||
<div data-trade-form-target="priceInput">
|
||||
<%= form.money_field :price, label: t(".price"), disable_currency: true %>
|
||||
<%= form.money_field :price, label: t(".price"), currency_value_override: "USD", disable_currency: true %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<%= styled_form_with model: transfer, class: "space-y-4", data: { turbo_frame: "_top" } do |f| %>
|
||||
<%= 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-red-600 flex items-center gap-2">
|
||||
<%= lucide_icon "circle-alert", class: "w-5 h-5" %>
|
||||
|
@ -28,8 +28,8 @@
|
|||
<section class="space-y-2">
|
||||
<%= f.collection_select :from_account_id, Current.family.accounts.manual.alphabetically, :id, :name, { prompt: t(".select_account"), label: t(".from") }, required: true %>
|
||||
<%= f.collection_select :to_account_id, Current.family.accounts.manual.alphabetically, :id, :name, { prompt: t(".select_account"), label: t(".to") }, required: true %>
|
||||
<%= f.money_field :amount, label: t(".amount"), required: true, hide_currency: true %>
|
||||
<%= f.date_field :date, value: transfer.date, label: t(".date"), required: true, max: Date.current %>
|
||||
<%= f.number_field :amount, label: t(".amount"), required: true, min: 0, placeholder: "100", step: 0.00000001 %>
|
||||
<%= f.date_field :date, value: transfer.date || Date.today, label: t(".date"), required: true, max: Date.current %>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
data: { turbo: false } do |form| %>
|
||||
<div class="space-y-3">
|
||||
<%= form.date_field :date, label: true, required: true, value: Date.today, min: Account::Entry.min_supported_date, max: Date.today %>
|
||||
<%= form.money_field :amount, label: t(".amount"), required: true, default_currency: Current.family.currency %>
|
||||
<%= form.money_field :amount, label: t(".amount"), required: true %>
|
||||
</div>
|
||||
|
||||
<%= form.submit t(".submit") %>
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
<%# locals: (form:, amount_method:, currency_method:, **options) %>
|
||||
|
||||
<% currency_value = if form.object && form.object.respond_to?(currency_method)
|
||||
<% currency_value = if options[:currency_value_override].present?
|
||||
options[:currency_value_override]
|
||||
elsif form.object && form.object.respond_to?(currency_method)
|
||||
form.object.public_send(currency_method)
|
||||
end
|
||||
currency = Money::Currency.new(currency_value || options[:default_currency] || "USD") %>
|
||||
|
@ -44,7 +46,7 @@
|
|||
<div>
|
||||
<%= form.select currency_method,
|
||||
currencies_for_select.map(&:iso_code),
|
||||
{ inline: true },
|
||||
{ inline: true, selected: currency_value },
|
||||
{
|
||||
class: "w-fit pr-5 disabled:text-gray-400 form-field__input",
|
||||
disabled: options[:disable_currency],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue