From 53d85d6431765a7d2218b9a3b30e81358ee69fb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 6 Mar 2024 05:06:24 +0100 Subject: [PATCH] Use a button to destroy officials As mentioned in commits 5311daadf and bb958daf0, using links combined with JavaScript to generate POST (or, in this case, DELETE) requests to the server has a few issues. --- app/assets/stylesheets/admin/action.scss | 4 ++++ app/views/admin/officials/edit.html.erb | 16 ++++++++++++---- spec/system/admin/officials_spec.rb | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/assets/stylesheets/admin/action.scss b/app/assets/stylesheets/admin/action.scss index cca144bbb..abdba6794 100644 --- a/app/assets/stylesheets/admin/action.scss +++ b/app/assets/stylesheets/admin/action.scss @@ -3,4 +3,8 @@ &[disabled] { @include button-disabled; } + + &.delete { + cursor: pointer; + } } diff --git a/app/views/admin/officials/edit.html.erb b/app/views/admin/officials/edit.html.erb index 40e428e49..c03c77c65 100644 --- a/app/views/admin/officials/edit.html.erb +++ b/app/views/admin/officials/edit.html.erb @@ -14,9 +14,17 @@ <%= f.text_field :official_position %> <%= f.select :official_level, official_level_options %> <%= f.submit class: "button" %> - <% if @user.official? %> -
- <%= link_to t("admin.officials.edit.destroy"), admin_official_path(@user), method: :delete, class: "delete" %> - <% end %> + <% end %> + + <% if @user.official? %> +
+ <%= render Admin::ActionComponent.new( + :destroy, + @user, + text: t("admin.officials.edit.destroy"), + path: admin_official_path(@user), + method: :delete, + class: "delete" + ) %> <% end %> diff --git a/spec/system/admin/officials_spec.rb b/spec/system/admin/officials_spec.rb index c71dfe928..cf94a541d 100644 --- a/spec/system/admin/officials_spec.rb +++ b/spec/system/admin/officials_spec.rb @@ -63,7 +63,7 @@ describe "Admin officials", :admin do scenario "Destroy" do visit edit_admin_official_path(official) - click_link 'Remove "Official" status' + click_button 'Remove "Official" status' expect(page).to have_content "Details saved: the user is no longer an official" expect(page).to have_current_path(admin_officials_path, ignore_query: true)