+ data-controller="confirm show-more"
+ data-confirm-message-value="<%= @discuss_confirm_message %>">
@@ -12,7 +13,7 @@
<% if @user_can_discuss_snippet %>
- <%= button_to discuss_snippet_path(@snippet), method: :patch, form: { target: "_blank" } do %>
+ <%= button_to discuss_snippet_path(@snippet), method: :patch, data: { action: "confirm#handleSubmit" } do %>
discuss on Slack
<% end %>
<% end %>
diff --git a/app/components/snippets/box_component.rb b/app/components/snippets/box_component.rb
index 201fd353..b2a34295 100644
--- a/app/components/snippets/box_component.rb
+++ b/app/components/snippets/box_component.rb
@@ -11,8 +11,10 @@ def initialize(snippet:, user:)
@snippet = snippet
@user_can_edit_snippet = @snippet.user == @user
- @user_can_discuss_snippet = @snippet.user != @user && @snippet.user.slack_linked?
+ @user_can_discuss_snippet = @snippet.user != @user && @snippet.user.slack_linked? && @user.slack_linked?
@user_reaction_vote_value = @snippet.reactions.find { _1.user_id == @user.id }
+
+ @discuss_confirm_message = "By clicking this button, you will create a new Slack thread on #aoc and notify the author of the solution. Do you want to proceed?" if @snippet.slack_url.nil?
end
end
end
diff --git a/app/javascript/controllers/confirm_controller.js b/app/javascript/controllers/confirm_controller.js
new file mode 100644
index 00000000..db24d09f
--- /dev/null
+++ b/app/javascript/controllers/confirm_controller.js
@@ -0,0 +1,18 @@
+import { Controller } from "@hotwired/stimulus"
+
+export default class extends Controller {
+ static values = {
+ message: String,
+ }
+
+ handleSubmit(event) {
+ event.preventDefault()
+ if (this.messageValue && !confirm(this.messageValue)) { return }
+
+ const newTab = window.open("", "_blank")
+ const form = event.currentTarget.parentElement.cloneNode(true)
+ form.style.display = "none"
+ newTab.document.body.appendChild(form)
+ form.submit()
+ }
+}