Extend the prompt in case of funnel-goal deletion

pull/2859/head
Adam Rutkowski 4 years ago
parent ab4f1433da
commit f5b577574e

@ -72,6 +72,14 @@ defmodule Plausible.Goals do
)
end
def belongs_to_funnels?(%Goal{id: goal_id}) do
belongs_to_funnels?(goal_id)
end
def belongs_to_funnels?(goal_id) do
Repo.exists?(from fs in Plausible.Funnel.Step, where: fs.goal_id == ^goal_id)
end
def delete(id, site) do
case Repo.delete_all(
from(g in Goal,

@ -12,7 +12,17 @@
<%= for goal <- @goals do %>
<div class="border-b border-gray-300 dark:border-gray-500 py-3 flex justify-between">
<span class="text-sm font-medium text-gray-900 dark:text-gray-100"><%= goal_name(goal) %></span>
<%= button(to: "/#{URI.encode_www_form(@site.domain)}/goals/#{goal.id}", method: :delete, class: "text-sm text-red-600", data: [confirm: "Are you sure you want to remove goal #{goal_name(goal)}? This will just affect the UI, all of your analytics data will stay intact."]) do %>
<% prompt = if Plausible.Goals.belongs_to_funnels?(goal) do %>
The goal <%= goal_name(goal) %> is part of some funnel(s).
If you are going to delete it, the associated funnels will be either reduced or deleted completely.
Are you sure you want to remove goal <%= goal_name(goal) %>?
<% else %>
Are you sure you want to remove goal <%= goal_name(goal) %>? This will just affect the UI, all of your analytics data will stay intact.
<% end %>
<%= button(to: "/#{URI.encode_www_form(@site.domain)}/goals/#{goal.id}", method: :delete, class: "text-sm text-red-600", data: [confirm: prompt]) do %>
<svg class="feather feather-sm" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path><line x1="10" y1="11" x2="10" y2="17"></line><line x1="14" y1="11" x2="14" y2="17"></line></svg>
<% end %>
</div>

Loading…
Cancel
Save