Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Fix selected account and Transaction/Transfer Tabs changes (#1220)

Yacine Kanzarib78944ed6f17
diff --git a/app/controllers/transfers_controller.rb b/app/controllers/transfers_controller.rb
index 239f7d9f99..21d68bb781 100644
--- a/app/controllers/transfers_controller.rb
+++ b/app/controllers/transfers_controller.rb
@@ -35,6 +35,7 @@ class TransfersController < ApplicationController
format.turbo_stream { stream_redirect_back_or_to transactions_path, notice: success_message }
end
else
+ @from_account_id = transfer_params[:from_account_id]
render :new, status: :unprocessable_entity
end
end
diff --git a/app/helpers/styled_form_builder.rb b/app/helpers/styled_form_builder.rb
index ae81f20622..bb51ab2ffb 100644
--- a/app/helpers/styled_form_builder.rb
+++ b/app/helpers/styled_form_builder.rb
@@ -28,7 +28,12 @@ class StyledFormBuilder < ActionView::Helpers::FormBuilder
end
def collection_select(method, collection, value_method, text_method, options = {}, html_options = {})
- selected_value = @object.public_send(method) if @object.respond_to?(method)
+ selected_value =
+ if options.key?(:selected)
+ options[:selected]
+ elsif @object.respond_to?(method)
+ @object.public_send(method)
+ end
placeholder = options[:prompt] || options[:include_blank] || options[:placeholder] || I18n.t("helpers.select.default_label")
@template.render(
diff --git a/app/views/shared/_transaction_type_tabs.html.erb b/app/views/shared/_transaction_type_tabs.html.erb
index 820c230712..720960871b 100644
--- a/app/views/shared/_transaction_type_tabs.html.erb
+++ b/app/views/shared/_transaction_type_tabs.html.erb
@@ -19,7 +19,7 @@
<% end %>
<% end %>
- <%= link_to new_transfer_path,
+ <%= link_to new_transfer_path(from_account_id: account_id),
data: { turbo_frame: :modal },
class: "flex-1 min-w-0 flex px-4 py-1 rounded-lg items-center space-x-2 justify-center text-sm #{active_tab == 'transfer' ? 'bg-container text-primary shadow-sm' : 'hover:bg-container text-subdued hover:text-primary hover:shadow-sm'}" do %>
<%= icon "arrow-right-left" %>
diff --git a/app/views/transfers/_form.html.erb b/app/views/transfers/_form.html.erb
index 8c3bc5edba..39684a9cd5 100644
--- a/app/views/transfers/_form.html.erb
+++ b/app/views/transfers/_form.html.erb
@@ -22,7 +22,7 @@
<% if show_type_tabs %>
<section>
- <%= render "shared/transaction_type_tabs", active_tab: "transfer" %>
+ <%= render "shared/transaction_type_tabs", active_tab: "transfer", account_id: @from_account_id %>
</section>
<% end %>