From fd68b5bc167915d14bcd0cdcf54884d1da1af0e0 Mon Sep 17 00:00:00 2001
From: Nataliia Makarenko <73568587+NVMakarenko@users.noreply.github.com>
Date: Mon, 9 Dec 2024 11:08:19 +0200
Subject: [PATCH] fix 'Calculator' page reverting after changing locale
(#928)
* fix refreshing new calculator after changing locale
* fix request mismatching
* add js-redirection
* fix rubocop
* fix test
* use inline script
* add CSP
* fix redirection and check tests
* update csp
* fix rubocop
* fix turbo_stream create
* add partial into shared
* turbo solution
* remove redundant code
* fix tests
---
app/views/account/calculators/new.html.erb | 14 +-------------
app/views/account/calculators/new.turbo_stream.erb | 4 ++++
.../calculators/partials/new/_form.html.erb | 13 +++++++++++++
.../account/products/partials/new/_form.html.erb | 2 +-
4 files changed, 19 insertions(+), 14 deletions(-)
create mode 100644 app/views/account/calculators/new.turbo_stream.erb
create mode 100644 app/views/account/calculators/partials/new/_form.html.erb
diff --git a/app/views/account/calculators/new.html.erb b/app/views/account/calculators/new.html.erb
index ec4afee47..4c2b347d7 100644
--- a/app/views/account/calculators/new.html.erb
+++ b/app/views/account/calculators/new.html.erb
@@ -1,15 +1,3 @@
- <%= simple_form_for @calculator, url: account_calculators_path do |f| %>
-
-
- <%= f.button :submit, t('.create_calculator_button'), class: 'btn btn-green me-2 height-auto w-auto' %>
- <%= link_to account_calculators_path, class: 'btn btn-danger d-flex align-items-center justify-content-center height-auto w-auto' do %>
- <%= t('buttons.cancel') %>
- <% end %>
-
- <% end %>
+ <%= render "account/calculators/partials/new/form", calculator: @calculator %>
diff --git a/app/views/account/calculators/new.turbo_stream.erb b/app/views/account/calculators/new.turbo_stream.erb
new file mode 100644
index 000000000..58a7f7eb3
--- /dev/null
+++ b/app/views/account/calculators/new.turbo_stream.erb
@@ -0,0 +1,4 @@
+<%= turbo_stream.replace(
+ dom_id(@calculator, :form),
+ partial: "account/calculators/partials/new/form",
+ locals: {calculator: @calculator}) %>
diff --git a/app/views/account/calculators/partials/new/_form.html.erb b/app/views/account/calculators/partials/new/_form.html.erb
new file mode 100644
index 000000000..b4839a083
--- /dev/null
+++ b/app/views/account/calculators/partials/new/_form.html.erb
@@ -0,0 +1,13 @@
+<%= simple_form_for calculator, url: account_calculators_path, html: { id: dom_id(calculator, :form) } do |f| %>
+
+
+ <%= f.button :submit, t('account.calculators.new.create_calculator_button'), class: 'btn btn-green me-2 height-auto w-auto' %>
+ <%= link_to account_calculators_path, class: 'btn btn-danger d-flex align-items-center justify-content-center height-auto w-auto' do %>
+ <%= t('buttons.cancel') %>
+ <% end %>
+
+<% end %>
diff --git a/app/views/account/products/partials/new/_form.html.erb b/app/views/account/products/partials/new/_form.html.erb
index 1d00064f1..0e19e5521 100644
--- a/app/views/account/products/partials/new/_form.html.erb
+++ b/app/views/account/products/partials/new/_form.html.erb
@@ -10,7 +10,7 @@
<%= f.simple_fields_for :prices, f.object.find_or_build_price_for_category(category) do |prices_form| %>
<%= prices_form.input :sum, label: false, input_html: { placeholder: t(".form.sum"), data: { price_form_target: "priceInput" } } %>
<%= prices_form.hidden_field :category_id, value: category.id %>
- <%= t(".form.error_sum") %>
+ <%= t(".form.error_sum") %>
<% end %>