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.
This commit is contained in:
Javi Martín
2024-03-06 05:06:24 +01:00
parent 5876738369
commit 53d85d6431
3 changed files with 17 additions and 5 deletions

View File

@@ -3,4 +3,8 @@
&[disabled] {
@include button-disabled;
}
&.delete {
cursor: pointer;
}
}

View File

@@ -14,9 +14,17 @@
<%= f.text_field :official_position %>
<%= f.select :official_level, official_level_options %>
<%= f.submit class: "button" %>
<% end %>
<% if @user.official? %>
<br>
<%= link_to t("admin.officials.edit.destroy"), admin_official_path(@user), method: :delete, class: "delete" %>
<% end %>
<%= render Admin::ActionComponent.new(
:destroy,
@user,
text: t("admin.officials.edit.destroy"),
path: admin_official_path(@user),
method: :delete,
class: "delete"
) %>
<% end %>
</div>

View File

@@ -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)