Add error handling for vehicle and property account creation #1179

Merged
tonyvince merged 3 commits from fix-1178 into main 2024-09-17 22:37:09 +08:00
4 changed files with 5 additions and 6 deletions

View File

@@ -58,8 +58,6 @@ class AccountsController < ApplicationController
start_balance: account_params[:start_balance]
@account.sync_later
redirect_back_or_to account_path(@account), notice: t(".success")
rescue ActiveRecord::RecordInvalid => e
redirect_back_or_to accounts_path, alert: e.record.errors.full_messages.to_sentence
end
def destroy

View File

@@ -34,7 +34,8 @@ module FormsHelper
default_currency: options[:default_currency] || "USD",
disable_currency: options[:disable_currency] || false,
hide_currency: options[:hide_currency] || false,
label: options[:label] || "Amount"
label: options[:label] || "Amount",
required: options[:required] || false
}
zachgoll commented 2024-09-17 00:34:37 +08:00 (Migrated from github.com)
Review

We'll need to update this improper usage for this to flow through correctly:

fd40111264/app/views/accounts/_form.html.erb (L8)

See required: "required" should be -> required: true

We'll need to update this improper usage for this to flow through correctly: https://github.com/maybe-finance/maybe/blob/fd4011126422023228a9295b2d9b30bb1b9402cb/app/views/accounts/_form.html.erb#L8 See `required: "required"` should be -> `required: true`
end

View File

@@ -5,7 +5,7 @@
<%= f.hidden_field :accountable_type %>
<%= f.text_field :name, placeholder: t(".name_placeholder"), required: "required", label: t(".name_label"), autofocus: true %>
<%= f.collection_select :institution_id, Current.family.institutions.alphabetically, :id, :name, { include_blank: t(".ungrouped"), label: t(".institution") } %>
<%= money_with_currency_field f, :balance_money, label: t(".balance"), required: "required", default_currency: Current.family.currency %>
<%= money_with_currency_field f, :balance_money, label: t(".balance"), required: true, default_currency: Current.family.currency %>
<% if account.new_record? %>
<div class="flex items-center gap-2 mt-3 mb-6">

View File

@@ -1,4 +1,4 @@
<%# locals: (form:, money_method:, default_currency:, disable_currency: false, hide_currency: false, label: nil) %>
<%# locals: (form:, money_method:, default_currency:, disable_currency: false, hide_currency: false, label: nil, required: false) %>
<% fallback_label = t(".money-label") %>
<% currency = form.object ? (form.object.send(money_method)&.currency || Money::Currency.new(default_currency)) : Money::Currency.new(default_currency) %>
@@ -9,7 +9,7 @@
<div class="flex items-center gap-1">
<div class="flex items-center grow gap-1">
<span class="text-gray-500 text-sm" data-money-field-target="symbol"><%= currency.symbol %></span>
<%= money_field form, money_method, { inline: true, "data-money-field-target" => "amount", default_currency: currency } %>
<%= money_field form, money_method, { inline: true, "data-money-field-target" => "amount", default_currency: currency, required: required } %>
</div>
<% unless hide_currency %>
<div>