wip
parent
f92847e8c1
commit
e3b8067628
@ -0,0 +1,43 @@
|
||||
defmodule PlausibleWeb.Live.FunnelSettings do
|
||||
use Phoenix.LiveView
|
||||
use Phoenix.HTML
|
||||
|
||||
alias Plausible.{Sites, Goals, Funnels}
|
||||
|
||||
def mount(
|
||||
_params,
|
||||
%{"site_id" => _site_id, "domain" => domain, "current_user_id" => user_id},
|
||||
socket
|
||||
) do
|
||||
site = Sites.get_for_user!(user_id, domain, [:owner, :admin])
|
||||
|
||||
funnels = Funnels.list(site)
|
||||
goals = Goals.for_site(site)
|
||||
|
||||
{:ok, assign(socket, site: site, funnels: funnels, goals: goals, add_funnel?: false)}
|
||||
end
|
||||
|
||||
def render(assigns) do
|
||||
~H"""
|
||||
<%= if @add_funnel? do %>
|
||||
<.live_component module={PlausibleWeb.Live.FunnelSettings.Form} id="funnelForm" site={@site} form={to_form(Plausible.Funnel.changeset())} goals={@goals} />
|
||||
<% else %>
|
||||
<.live_component module={PlausibleWeb.Live.FunnelSettings.List} id="funnelsList" funnels={@funnels} site={@site} />
|
||||
<button type="button" class="button mt-6" phx-click="add_funnel">+ Add funnel</button>
|
||||
<% end %>
|
||||
"""
|
||||
end
|
||||
|
||||
def handle_event("add_funnel", _value, socket) do
|
||||
{:noreply, assign(socket, :add_funnel?, true)}
|
||||
end
|
||||
|
||||
def handle_event("cancel_add_funnel", _value, socket) do
|
||||
{:noreply, assign(socket, :add_funnel?, false)}
|
||||
end
|
||||
|
||||
def handle_event("validate", value, socket) do
|
||||
IO.inspect(value, label: :validate)
|
||||
{:noreply, socket}
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,86 @@
|
||||
defmodule PlausibleWeb.Live.FunnelSettings.Form do
|
||||
use Phoenix.LiveComponent
|
||||
use Phoenix.HTML
|
||||
|
||||
# good
|
||||
|
||||
def mount(socket) do
|
||||
{:ok, assign(socket, step_count: 2)}
|
||||
end
|
||||
|
||||
def update(assigns, socket) do
|
||||
{:ok, assign(socket, form: assigns.form, goals: assigns.goals)}
|
||||
end
|
||||
|
||||
def render(assigns) do
|
||||
~H"""
|
||||
<div class="grid grid-cols-4 gap-6 mt-6">
|
||||
<div class="col-span-4 sm:col-span-2">
|
||||
<.form :let={f} for={@form} phx-change="validate" phx-submit="save">
|
||||
<%= label f, "Funnel name", class: "block text-sm font-medium text-gray-700 dark:text-gray-300" %>
|
||||
<.input field={@form[:name]} />
|
||||
|
||||
<%= label f, "Funnel Steps", class: "mt-6 block text-sm font-medium text-gray-700 dark:text-gray-300" %>
|
||||
|
||||
<%= for _step_number <- 1..@step_count do %>
|
||||
<.select goals={@goals} myself={@myself} />
|
||||
<% end %>
|
||||
|
||||
<%= if @step_count < 5 do %>
|
||||
<a class="underline text-indigo-600 cursor-pointer" phx-click="add-step" phx-target={@myself}>Add another step</a>
|
||||
<% end %>
|
||||
|
||||
<br/><hr/>
|
||||
|
||||
<button type="button" class="button mt-6">Save</button>
|
||||
<button type="button" class="button mt-6" phx-click="cancel_add_funnel">Cancel</button>
|
||||
</.form>
|
||||
</div>
|
||||
</div>
|
||||
"""
|
||||
end
|
||||
|
||||
attr :field, Phoenix.HTML.FormField
|
||||
|
||||
def input(assigns) do
|
||||
~H"""
|
||||
<input type="text" id={@field.id} name={@field.name} value={@field.value} 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" />
|
||||
"""
|
||||
end
|
||||
|
||||
attr :goals, :map, required: true
|
||||
attr :myself, :any, required: true
|
||||
|
||||
def select(assigns) do
|
||||
~H"""
|
||||
<select phx-change="changed" phx-target={@myself} name="steps[]" class="dark:bg-gray-900 mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 dark:border-gray-500 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md dark:text-gray-100 cursor-pointer" id="site_timezone">
|
||||
<%= for goal <- @goals do %>
|
||||
<option value={goal.id}>
|
||||
<%= Plausible.Goal.display_name(goal) %>
|
||||
</option>
|
||||
<% end %>
|
||||
</select>
|
||||
"""
|
||||
end
|
||||
|
||||
def handle_event("add-step", _value, socket) do
|
||||
step_count = socket.assigns.step_count
|
||||
|
||||
if step_count < 5 do
|
||||
{:noreply, assign(socket, step_count: step_count + 1)}
|
||||
else
|
||||
{:noreply, socket}
|
||||
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)}
|
||||
end
|
||||
end
|
||||
|
||||
# goal_options = [{"N/A", ""} | Enum.map(@goals, fn goal -> {Plausible.Goal.display_name(goal), goal.id} end)] %>
|
||||
#
|
||||
# end
|
||||
@ -0,0 +1,25 @@
|
||||
defmodule PlausibleWeb.Live.FunnelSettings.List do
|
||||
use Phoenix.LiveComponent
|
||||
use Phoenix.HTML
|
||||
|
||||
def render(assigns) do
|
||||
~H"""
|
||||
<div>
|
||||
<%= if Enum.count(@funnels) > 0 do %>
|
||||
<div class="mt-4">
|
||||
<%= for funnel <- @funnels 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"><%= funnel.name %></span>
|
||||
<%= button(to: "", method: :delete, class: "text-sm text-red-600", data: [confirm: "Are you sure you want to remove funnel '#{funnel.name}'? This will just affect the UI, all of your analytics data will stay intact."]) 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>
|
||||
<% end %>
|
||||
</div>
|
||||
<% else %>
|
||||
<div class="mt-4 dark:text-gray-100">No funnels configured for this site yet</div>
|
||||
<% end %>
|
||||
</div>
|
||||
"""
|
||||
end
|
||||
end
|
||||
@ -1,41 +1,10 @@
|
||||
<header class="relative">
|
||||
<h2 class="text-lg leading-6 font-medium text-gray-900 dark:text-gray-100">Your Funnels</h2>
|
||||
</header>
|
||||
|
||||
<ul>
|
||||
<%= for funnel <- @funnels do %>
|
||||
<li>[ID: <%= funnel.id %>] <a href="#<%= funnel.id %>"><%= funnel.name %></a></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
<hr/>
|
||||
<header class="relative">
|
||||
<h2 class="text-lg leading-6 font-medium text-gray-900 dark:text-gray-100">New funnel</h2>
|
||||
</header>
|
||||
|
||||
<% goal_options = [{"N/A", ""} | Enum.map(@goals, fn goal -> {Plausible.Goal.display_name(goal), goal.id} end)] %>
|
||||
|
||||
<%= form_for @conn, "/#{@site.domain}/settings/funnels", [class: "max-w-sm"], fn f -> %>
|
||||
<%= label f, :funnel_name, class: "block text-sm font-medium text-gray-700 dark:text-gray-300" %>
|
||||
<%= text_input f, :funnel_name, class: "shadow-sm dark:bg-gray-900 dark:text-gray-300 focus:ring-indigo-500 focus:border-indigo-500 block w-full sm:text-sm border-gray-300 dark:border-gray-500 rounded-md dark:bg-gray-800" %>
|
||||
|
||||
<%= label f, :step_1, class: "block text-sm font-medium text-gray-700 dark:text-gray-300" %>
|
||||
|
||||
<%= select f, :step_1, goal_options, class: "dark:bg-gray-900 mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 dark:border-gray-500 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md dark:text-gray-100 cursor-pointer" %>
|
||||
|
||||
<%= label f, :step_2, class: "block text-sm font-medium text-gray-700 dark:text-gray-300" %>
|
||||
<%= select f, :step_2, goal_options, class: "dark:bg-gray-900 mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 dark:border-gray-500 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md dark:text-gray-100 cursor-pointer" %>
|
||||
|
||||
|
||||
<%= label f, :step_3, class: "block text-sm font-medium text-gray-700 dark:text-gray-300" %>
|
||||
<%= select f, :step_3, goal_options, class: "dark:bg-gray-900 mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 dark:border-gray-500 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md dark:text-gray-100 cursor-pointer" %>
|
||||
|
||||
<%= label f, :step_4, class: "block text-sm font-medium text-gray-700 dark:text-gray-300" %>
|
||||
<%= select f, :step_4, goal_options, class: "dark:bg-gray-900 mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 dark:border-gray-500 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md dark:text-gray-100 cursor-pointer" %>
|
||||
|
||||
<%= label f, :step_5, class: "block text-sm font-medium text-gray-700 dark:text-gray-300" %>
|
||||
<%= select f, :step_5, goal_options, class: "dark:bg-gray-900 mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 dark:border-gray-500 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md dark:text-gray-100 cursor-pointer" %>
|
||||
|
||||
<%= submit "Save funnel", class: "button mt-4" %>
|
||||
<% end %>
|
||||
|
||||
<div class="shadow bg-white dark:bg-gray-800 sm:rounded-md sm:overflow-hidden py-6 px-4 sm:p-6">
|
||||
<header class="relative">
|
||||
<h2 class="text-lg leading-6 font-medium text-gray-900 dark:text-gray-100">Funnels</h2>
|
||||
<p class="mt-1 text-sm leading-5 text-gray-500 dark:text-gray-200">Compose goals into funnels</p>
|
||||
<%= link(to: "https://plausible.io/docs/goal-conversions", target: "_blank", rel: "noreferrer") do %>
|
||||
<svg class="w-6 h-6 absolute top-0 right-0 text-gray-400" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" clip-rule="evenodd"></path></svg>
|
||||
<% end %>
|
||||
</header>
|
||||
<%= live_render(@conn, PlausibleWeb.Live.FunnelSettings, session: %{"site_id" => @site.id, "domain" => @site.domain}) %>
|
||||
</div>
|
||||
|
||||
Loading…
Reference in New Issue