From ccf5c81ea977b5d057e61da803449696430f5c98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 6 Mar 2024 14:09:01 +0100 Subject: [PATCH] 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. --- app/assets/stylesheets/admin.scss | 6 +++++- .../site_customization/pages/edit_component.html.erb | 8 +++++++- spec/system/admin/site_customization/pages_spec.rb | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss index ed3f0dda5..70258353f 100644 --- a/app/assets/stylesheets/admin.scss +++ b/app/assets/stylesheets/admin.scss @@ -511,9 +511,13 @@ code { flex-wrap: wrap; a, - button { + button, + form { margin-#{$global-left}: auto; + } + a, + button { &:not(.delete) { @include regular-button; margin-#{$global-left}: auto; diff --git a/app/components/admin/site_customization/pages/edit_component.html.erb b/app/components/admin/site_customization/pages/edit_component.html.erb index 327bbcbc7..6e7650ad3 100644 --- a/app/components/admin/site_customization/pages/edit_component.html.erb +++ b/app/components/admin/site_customization/pages/edit_component.html.erb @@ -2,7 +2,13 @@ <%= back_link_to admin_site_customization_pages_path %> <%= 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 %> <%= render "form" %> diff --git a/spec/system/admin/site_customization/pages_spec.rb b/spec/system/admin/site_customization/pages_spec.rb index 15c029389..6d1f5d841 100644 --- a/spec/system/admin/site_customization/pages_spec.rb +++ b/spec/system/admin/site_customization/pages_spec.rb @@ -93,7 +93,7 @@ describe "Admin custom pages", :admin do custom_page = create(:site_customization_page, title: "An example 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 "example-page"