|
|
|
|
@ -7,7 +7,12 @@ defmodule PlausibleWeb.Live.FunnelSettings.Form do
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def update(assigns, socket) do
|
|
|
|
|
{:ok, assign(socket, form: assigns.form, goals: assigns.goals)}
|
|
|
|
|
{:ok,
|
|
|
|
|
assign(socket,
|
|
|
|
|
form: assigns.form,
|
|
|
|
|
goals: assigns.goals,
|
|
|
|
|
site: assigns.site
|
|
|
|
|
)}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def render(assigns) do
|
|
|
|
|
@ -18,6 +23,7 @@ defmodule PlausibleWeb.Live.FunnelSettings.Form do
|
|
|
|
|
:let={f}
|
|
|
|
|
for={@form}
|
|
|
|
|
phx-change="validate"
|
|
|
|
|
phx-target={@myself}
|
|
|
|
|
phx-submit="save"
|
|
|
|
|
onkeydown="return event.key != 'Enter';"
|
|
|
|
|
>
|
|
|
|
|
@ -26,35 +32,38 @@ defmodule PlausibleWeb.Live.FunnelSettings.Form do
|
|
|
|
|
) %>
|
|
|
|
|
<.input field={@form[:name]} />
|
|
|
|
|
|
|
|
|
|
<%= label(f, "Funnel Steps",
|
|
|
|
|
class: "mt-6 block text-sm font-medium text-gray-700 dark:text-gray-300"
|
|
|
|
|
) %>
|
|
|
|
|
<div :if={String.trim(@form[:name].value) != ""} id="steps-builder">
|
|
|
|
|
<%= label(f, "Funnel Steps",
|
|
|
|
|
class: "mt-6 block text-sm font-medium text-gray-700 dark:text-gray-300"
|
|
|
|
|
) %>
|
|
|
|
|
|
|
|
|
|
<.live_component
|
|
|
|
|
:for={step_number <- 1..@step_count}
|
|
|
|
|
submit_name="funnel[steps][][goal_id]"
|
|
|
|
|
module={PlausibleWeb.Live.FunnelSettings.InputPicker}
|
|
|
|
|
id={"step-#{step_number}"}
|
|
|
|
|
options={Enum.map(@goals, fn goal -> {goal.id, Plausible.Goal.display_name(goal)} end)}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<.live_component
|
|
|
|
|
:for={step_number <- 1..@step_count}
|
|
|
|
|
module={PlausibleWeb.Live.FunnelSettings.InputPicker}
|
|
|
|
|
id={"step-#{step_number}"}
|
|
|
|
|
options={Enum.map(@goals, fn goal -> {goal.id, Plausible.Goal.display_name(goal)} end)}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<a
|
|
|
|
|
:if={@step_count < 5}
|
|
|
|
|
class="underline text-indigo-600 text-sm cursor-pointer mt-6"
|
|
|
|
|
phx-click="add-step"
|
|
|
|
|
phx-target={@myself}
|
|
|
|
|
>
|
|
|
|
|
+ Add another step
|
|
|
|
|
</a>
|
|
|
|
|
|
|
|
|
|
<div class="mt-6">
|
|
|
|
|
<button type="submit" class="button mt-6">Save</button>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
class="inline-block mt-4 ml-2 px-4 py-2 border border-gray-300 dark:border-gray-500 text-sm leading-5 font-medium rounded-md text-red-700 bg-white dark:bg-gray-800 hover:text-red-500 dark:hover:text-red-400 focus:outline-none focus:border-blue-300 focus:ring active:text-red-800 active:bg-gray-50 transition ease-in-out duration-150 "
|
|
|
|
|
phx-click="cancel_add_funnel"
|
|
|
|
|
<a
|
|
|
|
|
:if={@step_count < 5}
|
|
|
|
|
class="underline text-indigo-600 text-sm cursor-pointer mt-6"
|
|
|
|
|
phx-click="add-step"
|
|
|
|
|
phx-target={@myself}
|
|
|
|
|
>
|
|
|
|
|
Cancel
|
|
|
|
|
</button>
|
|
|
|
|
+ Add another step
|
|
|
|
|
</a>
|
|
|
|
|
|
|
|
|
|
<div class="mt-6">
|
|
|
|
|
<button type="submit" class="button mt-6">Save</button>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
class="inline-block mt-4 ml-2 px-4 py-2 border border-gray-300 dark:border-gray-500 text-sm leading-5 font-medium rounded-md text-red-700 bg-white dark:bg-gray-800 hover:text-red-500 dark:hover:text-red-400 focus:outline-none focus:border-blue-300 focus:ring active:text-red-800 active:bg-gray-50 transition ease-in-out duration-150 "
|
|
|
|
|
phx-click="cancel_add_funnel"
|
|
|
|
|
>
|
|
|
|
|
Cancel
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</.form>
|
|
|
|
|
</div>
|
|
|
|
|
@ -66,15 +75,28 @@ defmodule PlausibleWeb.Live.FunnelSettings.Form do
|
|
|
|
|
|
|
|
|
|
def input(assigns) do
|
|
|
|
|
~H"""
|
|
|
|
|
<input
|
|
|
|
|
autofocus
|
|
|
|
|
type="text"
|
|
|
|
|
id={@field.id}
|
|
|
|
|
name={@field.name}
|
|
|
|
|
value={@field.value}
|
|
|
|
|
phx-debounce="300"
|
|
|
|
|
class="focus:ring-indigo-500 focus:border-indigo-500 dark:bg-gray-900 dark:text-gray-300 block w-full rounded-md sm:text-sm border-gray-300 dark:border-gray-500"
|
|
|
|
|
/>
|
|
|
|
|
<div phx-feedback-for={@field.name}>
|
|
|
|
|
<input
|
|
|
|
|
autocomplete="off"
|
|
|
|
|
autofocus
|
|
|
|
|
type="text"
|
|
|
|
|
id={@field.id}
|
|
|
|
|
name={@field.name}
|
|
|
|
|
value={@field.value}
|
|
|
|
|
phx-debounce="300"
|
|
|
|
|
class="focus:ring-indigo-500 focus:border-indigo-500 dark:bg-gray-900 dark:text-gray-300 block w-full rounded-md sm:text-sm border-gray-300 dark:border-gray-500"
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<.error :for={{msg, _} <- @field.errors}>Funnel name <%= msg %></.error>
|
|
|
|
|
</div>
|
|
|
|
|
"""
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def error(assigns) do
|
|
|
|
|
~H"""
|
|
|
|
|
<div class="mt-2 text-sm text-red-600">
|
|
|
|
|
<%= render_slot(@inner_block) %>
|
|
|
|
|
</div>
|
|
|
|
|
"""
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@ -88,10 +110,36 @@ defmodule PlausibleWeb.Live.FunnelSettings.Form do
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def handle_event(event, value, socket) do
|
|
|
|
|
IO.inspect(event, label: :event)
|
|
|
|
|
IO.inspect(value, label: :value)
|
|
|
|
|
[_ | except_first] = socket.assigns.goals
|
|
|
|
|
{:noreply, assign(socket, goals: except_first)}
|
|
|
|
|
def handle_event("validate", %{"funnel" => params}, socket) do
|
|
|
|
|
changeset =
|
|
|
|
|
Plausible.Funnels.create_changeset(
|
|
|
|
|
socket.assigns.site,
|
|
|
|
|
params["name"],
|
|
|
|
|
params["steps"] || []
|
|
|
|
|
)
|
|
|
|
|
|> Map.put(:action, :insert)
|
|
|
|
|
|
|
|
|
|
{:noreply, assign(socket, form: to_form(changeset))}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def handle_event("save", %{"funnel" => params}, %{assigns: %{site: site}} = socket) do
|
|
|
|
|
IO.inspect(:saving)
|
|
|
|
|
|
|
|
|
|
case Plausible.Funnels.create(site, params["name"], params["steps"]) do
|
|
|
|
|
{:ok, funnel} ->
|
|
|
|
|
send(self(), {:funnel_saved, funnel})
|
|
|
|
|
{:noreply, socket}
|
|
|
|
|
|
|
|
|
|
{:error, changeset} ->
|
|
|
|
|
IO.inspect(changeset)
|
|
|
|
|
|
|
|
|
|
IO.inspect(to_form(changeset))
|
|
|
|
|
|
|
|
|
|
Ecto.Changeset.traverse_errors(changeset, fn thing ->
|
|
|
|
|
IO.inspect(thing)
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
{:noreply, assign(socket, form: to_form(changeset))}
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|