From f9ea4eb4002a5636356f492e763426aca22095a3 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Mon, 27 May 2024 04:20:39 +0000 Subject: [PATCH] Make confirmations work in tailwind theme. https://www.bugherd.com/t/LQbIMc1uiet5AHha3Pak0Q --- app/components/tailwind/button_component.rb | 8 ++++++-- app/views/_tailwind/alerts_new/edit.html.erb | 2 +- app/views/_tailwind/devise/registrations/edit.html.erb | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/components/tailwind/button_component.rb b/app/components/tailwind/button_component.rb index 7d437d4ad..45f9e0df7 100644 --- a/app/components/tailwind/button_component.rb +++ b/app/components/tailwind/button_component.rb @@ -8,9 +8,11 @@ class ButtonComponent < ViewComponent::Base # href is untyped to support passing objects or paths or arrays to construct urls from sig do params(tag: Symbol, size: String, type: Symbol, href: T.untyped, icon: T.nilable(Symbol), - open_in_new_tab: T::Boolean, name: T.nilable(String), disabled: T::Boolean).void + open_in_new_tab: T::Boolean, name: T.nilable(String), disabled: T::Boolean, + confirm: T.nilable(String)).void end - def initialize(tag:, size:, type:, href: nil, icon: nil, open_in_new_tab: false, name: nil, disabled: false) + def initialize(tag:, size:, type:, href: nil, icon: nil, open_in_new_tab: false, name: nil, disabled: false, + confirm: nil) super classes = %w[font-semibold] @@ -71,6 +73,8 @@ def initialize(tag:, size:, type:, href: nil, icon: nil, open_in_new_tab: false, options[:disabled] = true if disabled + options["x-on:click"] = "if (!confirm('#{confirm}')) { $event.preventDefault(); }" if confirm + @options = T.let(options, T.nilable(T::Hash[Symbol, T.nilable(String)])) @tag = tag @href = href diff --git a/app/views/_tailwind/alerts_new/edit.html.erb b/app/views/_tailwind/alerts_new/edit.html.erb index d07e64bf8..d7c019b1b 100644 --- a/app/views/_tailwind/alerts_new/edit.html.erb +++ b/app/views/_tailwind/alerts_new/edit.html.erb @@ -37,4 +37,4 @@ <%# TODO: #1768 Show an error of some sort if the last delivery was not successful %> <%= pa_button_to "Delete this alert", [:profile, @alert], method: :delete, type: :secondary, icon: :trash, form_class: "mt-8", - data: { confirm: "Are you sure you want to unsubscribe for email alerts for #{@alert.address}?" } %> + confirm: "Are you sure you want to unsubscribe for email alerts for #{@alert.address}?" %> diff --git a/app/views/_tailwind/devise/registrations/edit.html.erb b/app/views/_tailwind/devise/registrations/edit.html.erb index 5c1b47874..66a98de35 100644 --- a/app/views/_tailwind/devise/registrations/edit.html.erb +++ b/app/views/_tailwind/devise/registrations/edit.html.erb @@ -54,4 +54,4 @@ <%= pa_button_to "Close your account", registration_path(resource_name), method: :delete, type: :secondary, icon: :trash, form_class: "mt-12", - data: { confirm: "This will permanently remove your account and can not be undone. Are you sure?" } %> + confirm: "This will permanently remove your account and can not be undone. Are you sure?" %>