Use a button to destroy pages from the edit page

We were already using buttons to destroy pages from the pages index.

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 14:09:01 +01:00
parent fc4940ccb6
commit ccf5c81ea9
3 changed files with 13 additions and 3 deletions

View File

@@ -511,9 +511,13 @@ code {
flex-wrap: wrap; flex-wrap: wrap;
a, a,
button { button,
form {
margin-#{$global-left}: auto; margin-#{$global-left}: auto;
}
a,
button {
&:not(.delete) { &:not(.delete) {
@include regular-button; @include regular-button;
margin-#{$global-left}: auto; margin-#{$global-left}: auto;

View File

@@ -2,7 +2,13 @@
<%= back_link_to admin_site_customization_pages_path %> <%= back_link_to admin_site_customization_pages_path %>
<%= header do %> <%= header do %>
<%= link_to t("admin.site_customization.pages.index.delete"), admin_site_customization_page_path(page), method: :delete, class: "delete" %> <%= render Admin::ActionComponent.new(
:destroy,
@page,
text: t("admin.site_customization.pages.index.delete"),
method: :delete,
class: "delete"
) %>
<% end %> <% end %>
<%= render "form" %> <%= render "form" %>

View File

@@ -93,7 +93,7 @@ describe "Admin custom pages", :admin do
custom_page = create(:site_customization_page, title: "An example custom page") custom_page = create(:site_customization_page, title: "An example custom page")
visit edit_admin_site_customization_page_path(custom_page) visit edit_admin_site_customization_page_path(custom_page)
click_link "Delete page" click_button "Delete page"
expect(page).not_to have_content "An example custom page" expect(page).not_to have_content "An example custom page"
expect(page).not_to have_content "example-page" expect(page).not_to have_content "example-page"