From f76344c2200f6dd2d380af90cc92e36ca31ac620 Mon Sep 17 00:00:00 2001 From: cryptogopher Date: Sun, 14 May 2023 17:57:20 +0200 Subject: [PATCH] Add action confirmation dialog --- app/helpers/application_helper.rb | 3 +++ app/views/users/registrations/edit.html.erb | 2 +- test/system/users_test.rb | 4 +--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 9216a50..4d1acee 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -87,6 +87,9 @@ module ApplicationHelper name = svg_tag("pictograms/#{image}") + name if image html_options[:class] = class_names(html_options[:class], "button", active: current == :active) + if html_options[:confirm] + html_options[:onclick] = "return confirm('#{html_options.delete(:confirm)}');" + end send "#{type}_to", name, options, html_options end diff --git a/app/views/users/registrations/edit.html.erb b/app/views/users/registrations/edit.html.erb index 5e67e27..e9f9bff 100644 --- a/app/views/users/registrations/edit.html.erb +++ b/app/views/users/registrations/edit.html.erb @@ -6,7 +6,7 @@
<%# TODO: make confirm dialog work %> <%= image_button_to t(".delete"), "account-remove-outline", user_registration_path, - class: "dangerous", method: :delete, data: {confirm: t(".confirm_delete")} %> + class: "dangerous", method: :delete, confirm: t(".confirm_delete") %>
<% end %> diff --git a/test/system/users_test.rb b/test/system/users_test.rb index 515296e..40f3cac 100644 --- a/test/system/users_test.rb +++ b/test/system/users_test.rb @@ -143,9 +143,7 @@ class UsersTest < ApplicationSystemTestCase first(:link_or_button, user.email).click end assert_difference ->{ User.count }, -1 do - # TODO: accept_confirm when modal dialog is working - #accept_confirm { click_on t("users.registrations.edit.delete") } - click_on t("users.registrations.edit.delete") + accept_confirm { click_on t("users.registrations.edit.delete") } end assert_current_path new_user_session_path end