Add confirmations to warn about destructive consequences

This commit is contained in:
Jason Zimdars
2025-09-05 10:49:14 -05:00
parent c9bd38560e
commit 3a28bc3300
2 changed files with 15 additions and 1 deletions
+10
View File
@@ -22,4 +22,14 @@ module WorkflowsHelper
"It's not being used in any collections."
end
end
def workflow_switch_confirmation_message(workflow, collection)
if workflow == collection.workflow
"Stop using #{workflow.name}? Cards you're working on will lose their current stage."
elsif collection.workflow.present?
"Switch to #{workflow.name}? This will return all cards you're working on to the first stage."
else
nil
end
end
end
@@ -7,7 +7,10 @@
<div class="flex flex-wrap gap justify-center">
<% Workflow.all.each do |workflow| %>
<div class="workflow-preview txt-align-start border-radius <%= 'workflow-preview--selected' if workflow == collection.workflow %>">
<%= button_to collection_workflow_path(collection), method: :patch, aria: { label: workflow == collection.workflow ? "Stop using this workflow" : "Use this workflow" } do %>
<% confirmation_message = workflow_switch_confirmation_message(workflow, collection) %>
<%= button_to collection_workflow_path(collection), method: :patch,
aria: { label: workflow == collection.workflow ? "Stop using this workflow" : "Use this workflow" },
data: confirmation_message ? { turbo_confirm: confirmation_message } : {} do %>
<%= hidden_field_tag "collection[workflow_id]", workflow == collection.workflow ? "" : workflow.id %>
<strong class="txt-small overflow-ellipsis flex-item-no-shrink"><%= workflow.name %></strong>
<ul class="list-style-none txt-xx-small margin-none flex flex-column gap-half">
@@ -22,5 +25,6 @@
</div>
<% end %>
</div>
<%= link_to "Manage workflows", workflows_path, class: "btn btn--plain txt-link", data: { turbo_frame: "_top" } %>
<% end %>