Skip to content

Commit

Permalink
fix 'Calculator' page reverting after changing locale (#928)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
NVMakarenko authored Dec 9, 2024
1 parent bbb06b3 commit fd68b5b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
14 changes: 1 addition & 13 deletions app/views/account/calculators/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
<div class="container">
<%= simple_form_for @calculator, url: account_calculators_path do |f| %>
<div class="form-group row">
<div class="my-auto col-12 has-float-label">
<%= f.input :name, class: 'form-control' %>
</div>
</div>
<div class="button-group d-flex">
<%= 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 %>
<span><%= t('buttons.cancel') %></span>
<% end %>
</div>
<% end %>
<%= render "account/calculators/partials/new/form", calculator: @calculator %>
</div>
4 changes: 4 additions & 0 deletions app/views/account/calculators/new.turbo_stream.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<%= turbo_stream.replace(
dom_id(@calculator, :form),
partial: "account/calculators/partials/new/form",
locals: {calculator: @calculator}) %>
13 changes: 13 additions & 0 deletions app/views/account/calculators/partials/new/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<%= simple_form_for calculator, url: account_calculators_path, html: { id: dom_id(calculator, :form) } do |f| %>
<div class="form-group row">
<div class="my-auto col-12 has-float-label">
<%= f.input :name, class: 'form-control' %>
</div>
</div>
<div class="button-group d-flex">
<%= 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 %>
<span><%= t('buttons.cancel') %></span>
<% end %>
</div>
<% end %>
2 changes: 1 addition & 1 deletion app/views/account/products/partials/new/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
<div class="error-message hidden text-error" data-price-form-target="errorMessage"><%= t(".form.error_sum") %></div>
<div class="hidden error-message text-error" data-price-form-target="errorMessage"><%= t(".form.error_sum") %></div>
<% end %>
</div>
</div>
Expand Down

0 comments on commit fd68b5b

Please sign in to comment.