Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

CRM: split into dedicated live views with per-tab components (#5611)

Adam Rutkowskice428cda088a
diff --git a/extra/lib/plausible/customer_support/resource.ex b/extra/lib/plausible/customer_support/resource.ex
index 3c2d0c6800..e50925eabe 100644
--- a/extra/lib/plausible/customer_support/resource.ex
+++ b/extra/lib/plausible/customer_support/resource.ex
@@ -1,8 +1,8 @@
defmodule Plausible.CustomerSupport.Resource do
@moduledoc """
- Generic behaviour for CS resources and their components
+ Generic behaviour for CS resources
"""
- defstruct [:id, :type, :module, :object]
+ defstruct [:id, :type, :module, :object, :path]
@type schema() :: map()
@@ -15,75 +15,34 @@ defmodule Plausible.CustomerSupport.Resource do
@callback search(String.t(), Keyword.t()) :: list(schema())
@callback get(pos_integer()) :: schema()
- @callback component() :: module()
- @callback type() :: String.t()
+ @callback path(any()) :: String.t()
@callback dump(schema()) :: t()
- defmodule Component do
- @moduledoc false
- @callback render_result(assigns :: Phoenix.LiveView.Socket.assigns()) ::
- Phoenix.LiveView.Rendered.t()
- end
-
- defmacro __using__(:component) do
- quote do
- use PlausibleWeb, :live_component
- alias Plausible.CustomerSupport.Resource
- import PlausibleWeb.CustomerSupport.Live.Shared
-
- @behaviour Plausible.CustomerSupport.Resource.Component
-
- def success(socket, msg) do
- send(socket.root_pid, {:success, msg})
- socket
- end
-
- def failure(socket, msg) do
- send(socket.root_pid, {:failure, msg})
- socket
- end
- end
- end
-
- defmacro __using__(component: component) do
+ defmacro __using__(type: type) do
quote do
@behaviour Plausible.CustomerSupport.Resource
alias Plausible.CustomerSupport.Resource
+ alias PlausibleWeb.Router.Helpers, as: Routes
import Ecto.Query
alias Plausible.Repo
@impl true
def dump(schema) do
- Resource.new(__MODULE__, schema)
+ new(__MODULE__, schema)
end
defoverridable dump: 1
- @impl true
- def type do
- __MODULE__
- |> Module.split()
- |> Enum.reverse()
- |> hd()
- |> String.downcase()
+ def new(module, schema) do
+ %Resource{
+ id: schema.id,
+ type: unquote(type),
+ path: module.path(schema.id),
+ module: module,
+ object: schema
+ }
end
-
- defoverridable type: 0
-
- @impl true
- def component, do: unquote(component)
-
- defoverridable component: 0
end
end
-
- def new(module, schema) do
- %__MODULE__{
- id: schema.id,
- type: module.type(),
- module: module,
- object: schema
- }
- end
end
diff --git a/extra/lib/plausible/customer_support/resource/site.ex b/extra/lib/plausible/customer_support/resource/site.ex
index df09883d08..561ddea0ef 100644
--- a/extra/lib/plausible/customer_support/resource/site.ex
+++ b/extra/lib/plausible/customer_support/resource/site.ex
@@ -1,6 +1,12 @@
defmodule Plausible.CustomerSupport.Resource.Site do
@moduledoc false
- use Plausible.CustomerSupport.Resource, component: PlausibleWeb.CustomerSupport.Live.Site
+ use Plausible.CustomerSupport.Resource, type: "site"
+ alias Plausible.Repo
+
+ @impl true
+ def path(id) do
+ Routes.customer_support_site_path(PlausibleWeb.Endpoint, :show, id)
+ end
@impl true
def search(input, opts \\ [])
@@ -18,7 +24,7 @@ defmodule Plausible.CustomerSupport.Resource.Site do
limit: ^limit,
preload: [team: {t, owners: o}]
- Plausible.Repo.all(q)
+ Repo.all(q)
end
def search(input, opts) do
@@ -41,13 +47,13 @@ defmodule Plausible.CustomerSupport.Resource.Site do
limit: ^limit,
preload: [team: {t, owners: o}]
- Plausible.Repo.all(q)
+ Repo.all(q)
end
@impl true
def get(id) do
Plausible.Site
- |> Plausible.Repo.get!(id)
- |> Plausible.Repo.preload(:team)
+ |> Repo.get!(id)
+ |> Repo.preload(:team)
end
end
diff --git a/extra/lib/plausible/customer_support/resource/team.ex b/extra/lib/plausible/customer_support/resource/team.ex
index bc910cec09..250501019a 100644
--- a/extra/lib/plausible/customer_support/resource/team.ex
+++ b/extra/lib/plausible/customer_support/resource/team.ex
@@ -1,7 +1,13 @@
defmodule Plausible.CustomerSupport.Resource.Team do
@moduledoc false
- use Plausible.CustomerSupport.Resource, component: PlausibleWeb.CustomerSupport.Live.Team
+ use Plausible.CustomerSupport.Resource, type: "team"
alias Plausible.Teams
+ alias Plausible.Repo
+
+ @impl true
+ def path(id) do
+ Routes.customer_support_team_path(PlausibleWeb.Endpoint, :show, id)
+ end
@impl true
def search(input, opts \\ [])
diff --git a/extra/lib/plausible/customer_support/resource/user.ex b/extra/lib/plausible/customer_support/resource/user.ex
index 6d52cbd2e1..758fa6c784 100644
--- a/extra/lib/plausible/customer_support/resource/user.ex
+++ b/extra/lib/plausible/customer_support/resource/user.ex
@@ -1,11 +1,17 @@
defmodule Plausible.CustomerSupport.Resource.User do
@moduledoc false
- use Plausible.CustomerSupport.Resource, component: PlausibleWeb.CustomerSupport.Live.User
+ use Plausible.CustomerSupport.Resource, type: "user"
+ alias Plausible.Repo
+
+ @impl true
+ def path(id) do
+ Routes.customer_support_user_path(PlausibleWeb.Endpoint, :show, id)
+ end
@impl true
def get(id) do
- Plausible.Repo.get!(Plausible.Auth.User, id)
- |> Plausible.Repo.preload(team_memberships: :team)
+ Repo.get!(Plausible.Auth.User, id)
+ |> Repo.preload(team_memberships: :team)
end
@impl true
@@ -22,7 +28,7 @@ defmodule Plausible.CustomerSupport.Resource.User do
preload: [:owned_teams],
limit: ^limit
- Plausible.Repo.all(q)
+ Repo.all(q)
end
def search(input, opts) do
@@ -39,6 +45,6 @@ defmodule Plausible.CustomerSupport.Resource.User do
preload: [:owned_teams],
limit: ^limit
- Plausible.Repo.all(q)
+ Repo.all(q)
end
end
diff --git a/extra/lib/plausible/help_scout.ex b/extra/lib/plausible/help_scout.ex
index a061c39664..dfe1d2079e 100644
--- a/extra/lib/plausible/help_scout.ex
+++ b/extra/lib/plausible/help_scout.ex
@@ -106,11 +106,9 @@ defmodule Plausible.HelpScout do
end)
user_link =
- Routes.customer_support_resource_url(
+ Routes.customer_support_user_url(
PlausibleWeb.Endpoint,
- :details,
- :users,
- :user,
+ :show,
user.id
)
@@ -136,19 +134,15 @@ defmodule Plausible.HelpScout do
status_link =
if team do
- Routes.customer_support_resource_url(
+ Routes.customer_support_team_url(
PlausibleWeb.Endpoint,
- :details,
- :teams,
- :team,
+ :show,
team.id
)
else
- Routes.customer_support_resource_url(
+ Routes.customer_support_user_url(
PlausibleWeb.Endpoint,
- :details,
- :users,
- :user,
+ :show,
user.id
)
end
diff --git a/extra/lib/plausible_web/live/customer_support.ex b/extra/lib/plausible_web/live/customer_support.ex
index 50622f25c4..d5de1e0ae7 100644
--- a/extra/lib/plausible_web/live/customer_support.ex
+++ b/extra/lib/plausible_web/live/customer_support.ex
@@ -1,162 +1,47 @@
defmodule PlausibleWeb.Live.CustomerSupport do
@moduledoc """
- Customer Support UI
+ Customer Support home page (search)
"""
use PlausibleWeb, :live_view
- alias Plausible.CustomerSupport.Resource
- @resources [Resource.Team, Resource.User, Resource.Site]
- @resources_by_type @resources |> Enum.into(%{}, fn mod -> {mod.type(), mod} end)
+ alias PlausibleWeb.CustomerSupport.Components.{Layout, Search}
@impl true
def mount(params, _session, socket) do
uri =
- ("/cs?" <> URI.encode_query(Map.take(params, ["filter_text"])))
+ Routes.customer_support_path(
+ PlausibleWeb.Endpoint,
+ :index,
+ Map.take(params, ["filter_text"])
+ )
|> URI.new!()
{:ok,
assign(socket,
- resources_by_type: @resources_by_type,
- results: [],
- current: nil,
uri: uri,
filter_text: params["filter_text"] || ""
)}
end
@impl true
- def render(assigns) do
- ~H"""
- <.flash_messages flash={@flash} />
-
- <div x-data="{ openHelp: false }">
- <div
- id="help"
- x-show="openHelp"
- x-cloak
- class="p-16 fixed top-0 left-0 w-full h-full bg-gray-800 text-gray-300 bg-opacity-95 z-50 flex items-center justify-center"
- >
- <div @click.away="openHelp = false" @click="openHelp = false">
- Prefix your searches with: <br /><br />
- <div class="font-mono">
- <strong>site:</strong>input<br />
- <p class="font-sans pl-2 mb-1">
- Search for sites exclusively. Input will be checked against site's domain, team's name, owners' names and e-mails.
- </p>
- <strong>user:</strong>input<br />
- <p class="font-sans pl-2 mb-1">
- Search for users exclusively. Input will be checked against user's name and e-mail.
- </p>
- <strong>team:</strong>input<br />
- <p class="font-sans pl-2 mb-1">
- Search for teams exclusively. Input will be checked against user's name and e-mail.
- </p>
-
- <strong>team:</strong>input <strong>+sub</strong>
- <br />
- <p class="font-sans pl-2 mb-1">
- Like above, but only finds team(s) with subscription (in any status).
- </p>
-
- <strong>team:</strong>input <strong>+sso</strong>
- <br />
- <p class="font-sans pl-2 mb-1">
- Like above, but only finds team(s) with SSO integrations (in any status).
- </p>
- </div>
- </div>
- </div>
-
- <div class="container pt-6">
- <div class="group mt-6 pb-5 border-b border-gray-200 dark:border-gray-500 flex items-center justify-between">
- <h2 class="text-2xl font-bold leading-7 text-gray-900 dark:text-gray-100 sm:text-3xl sm:leading-9 sm:truncate flex-shrink-0">
- <.link replace patch="/cs?filter_text=">
- 💬 Customer Support
- </.link>
- </h2>
- </div>
+ def handle_params(params, _uri, socket) do
+ filter_text = params["filter_text"] || ""
+ socket = assign(socket, filter_text: filter_text)
- <div class="mb-4 mt-4">
- <.filter_bar filter_text={@filter_text} placeholder="Search everything">
- <a class="cursor-pointer" @click="openHelp = !openHelp">
- <Heroicons.question_mark_circle class="text-indigo-700 dark:text-gray-500 w-5 h-5 hover:stroke-2" />
- </a>
- </.filter_bar>
- </div>
-
- <ul :if={!@current} class="my-6 grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3">
- <li :for={r <- @results} class="group relative">
- <.link
- patch={"/cs/#{r.type}s/#{r.type}/#{r.id}"}
- data-test-type={r.type}
- data-test-id={r.id}
- >
- <div class="col-span-1 bg-white dark:bg-gray-800 rounded-lg shadow p-4 group-hover:shadow-lg cursor-pointer">
- <div class="text-gray-800 dark:text-gray-500 w-full flex items-center justify-between space-x-4">
- <.render_result resource={r} />
- </div>
- </div>
- </.link>
- </li>
- </ul>
-
- <div class={[
- if(is_nil(@current), do: "hidden")
- ]}>
- <div class="overflow-auto bg-white dark:bg-gray-800 text-gray-800 dark:text-gray-300 w-full h-3/4 max-w-7xl max-h-full p-4 rounded-lg shadow-lg">
- <div class="flex justify-between text-xs">
- <.styled_link onclick="window.history.go(-1); return false;">
- &larr; Previous
- </.styled_link>
- </div>
- <.live_component
- :if={@current}
- module={@current.component()}
- resource_id={@id}
- id={"#{@current.type()}-#{@id}"}
- />
- </div>
- </div>
- </div>
- </div>
- """
- end
-
- def render_result(assigns) do
- apply(assigns.resource.module.component(), :render_result, [assigns])
- end
-
- @impl true
- def handle_params(%{"id" => id, "resource" => type} = p, _uri, socket) do
- mod = Map.fetch!(@resources_by_type, type)
-
- id = String.to_integer(id)
-
- tab_params = Map.drop(p, ["id", "resource", "tab"])
-
- send_update(self(), mod.component(),
- id: "#{mod.type()}-#{id}",
- tab: p["tab"],
- tab_params: tab_params
- )
-
- {:noreply, assign(socket, type: type, current: mod, id: id)}
- end
-
- def handle_params(%{"filter_text" => _}, _uri, socket) do
- socket =
- search(assign(socket, current: nil))
+ send_update(Search, id: "search-component", filter_text: filter_text)
{:noreply, socket}
end
- def handle_params(_, _uri, socket) do
- {:noreply, search(socket)}
- end
+ @impl true
+ def render(assigns) do
+ ~H"""
+ <.flash_messages flash={@flash} />
- def search(%{assigns: assigns} = socket) do
- results = spawn_searches(assigns.filter_text)
- assign(socket, results: results)
+ <Layout.layout filter_text={@filter_text}>
+ <.live_component module={Search} filter_text={@filter_text} id="search-component" />
+ </Layout.layout>
+ """
end
@impl true
@@ -170,77 +55,11 @@ defmodule PlausibleWeb.Live.CustomerSupport do
{:noreply, socket}
end
- def handle_event("close", _, socket) do
- {:noreply, assign(socket, current: nil)}
- end
-
- def handle_info({:success, msg}, socket) do
- {:noreply, put_live_flash(socket, :success, msg)}
- end
-
- def handle_info({:failure, msg}, socket) do
- {:noreply, put_live_flash(socket, :error, msg)}
- end
-
- defp spawn_searches(input) do
- input = String.trim(input)
-
- {resources, input, opts} =
- maybe_focus_search(input)
-
- resources
- |> Task.async_stream(fn resource ->
- input
- |> resource.search(opts)
- |> Enum.map(&resource.dump/1)
- end)
- |> Enum.reduce([], fn {:ok, results}, acc ->
- acc ++ results
- end)
- end
-
- defp maybe_focus_search(lone_modifier) when lone_modifier in ["site:", "team:", "user:"] do
- {[], "", limit: 0}
- end
-
- defp maybe_focus_search("site:" <> rest) do
- {[Resource.Site], rest, limit: 90}
- end
-
- defp maybe_focus_search("team:" <> rest) do
- [input | mods] = String.split(rest, "+", trim: true)
- input = String.trim(input)
-
- opts =
- if "sub" in mods do
- [limit: 90, with_subscription_only?: true]
- else
- [limit: 90]
- end
-
- opts =
- if "sso" in mods do
- Keyword.merge(opts, with_sso_only?: true)
- else
- opts
- end
-
- {[Resource.Team], input, opts}
- end
-
- defp maybe_focus_search("user:" <> rest) do
- {[Resource.User], rest, limit: 90}
- end
-
- defp maybe_focus_search(input) do
- {@resources, input, limit: 30}
- end
-
defp set_filter_text(socket, filter_text) do
uri = socket.assigns.uri
uri_params =
- uri.query
+ (uri.query || "")
|> URI.decode_query()
|> Map.put("filter_text", filter_text)
|> URI.encode_query()
diff --git a/extra/lib/plausible_web/live/customer_support/components/layout.ex b/extra/lib/plausible_web/live/customer_support/components/layout.ex
new file mode 100644
index 0000000000..47ca132bc8
--- /dev/null
+++ b/extra/lib/plausible_web/live/customer_support/components/layout.ex
@@ -0,0 +1,124 @@
+defmodule PlausibleWeb.CustomerSupport.Components.Layout do
+ @moduledoc """
+ Base layout component for Customer Support UI
+ Provides common header, filter bar, and content area structure
+ """
+ use PlausibleWeb, :component
+ import PlausibleWeb.Live.Flash
+
+ attr :filter_text, :string, default: ""
+ attr :show_search, :boolean, default: true
+ attr :flash, :map, default: %{}
+ slot :inner_block, required: true
+ slot :filter_actions, required: false
+
+ def layout(assigns) do
+ ~H"""
+ <div x-data="{ openHelp: false }" class="dark:text-gray-400">
+ <.help_overlay />
+
+ <div class="container pt-6">
+ <.header filter_text={@filter_text} />
+
+ <div class="py-4">
+ <.styled_link class="text-sm" onclick="window.history.go(-1); return false;">
+ &larr; Go back
+ </.styled_link>
+ </div>
+
+ <.search_bar :if={@show_search} filter_text={@filter_text}>
+ {render_slot(@filter_actions)}
+ </.search_bar>
+
+ <.flash_messages flash={@flash} />
+
+ <div class="mt-4">
+ {render_slot(@inner_block)}
+ </div>
+
+ <div class="py-4">
+ <.styled_link class="text-sm" onclick="window.history.go(-1); return false;">
+ &larr; Go back
+ </.styled_link>
+ </div>
+ </div>
+ </div>
+ """
+ end
+
+ defp help_overlay(assigns) do
+ ~H"""
+ <div
+ id="help"
+ x-show="openHelp"
+ x-cloak
+ class="p-16 fixed top-0 left-0 w-full h-full bg-gray-800 text-gray-300 bg-opacity-95 z-50 flex items-center justify-center"
+ >
+ <div @click.away="openHelp = false" @click="openHelp = false">
+ Prefix your searches with: <br /><br />
+ <div class="font-mono">
+ <strong>site:</strong>input<br />
+ <p class="font-sans pl-2 mb-1">
+ Search for sites exclusively. Input will be checked against site's domain, team's name, owners' names and e-mails.
+ </p>
+ <strong>user:</strong>input<br />
+ <p class="font-sans pl-2 mb-1">
+ Search for users exclusively. Input will be checked against user's name and e-mail.
+ </p>
+ <strong>team:</strong>input<br />
+ <p class="font-sans pl-2 mb-1">
+ Search for teams exclusively. Input will be checked against user's name and e-mail.
+ </p>
+
+ <strong>team:</strong>input <strong>+sub</strong>
+ <br />
+ <p class="font-sans pl-2 mb-1">
+ Like above, but only finds team(s) with subscription (in any status).
+ </p>
+
+ <strong>team:</strong>input <strong>+sso</strong>
+ <br />
+ <p class="font-sans pl-2 mb-1">
+ Like above, but only finds team(s) with SSO integrations (in any status).
+ </p>
+ </div>
+ </div>
+ </div>
+ """
+ end
+
+ attr :filter_text, :string, required: true
+
+ defp header(assigns) do
+ ~H"""
+ <div class="group mt-6 pb-5 border-b border-gray-200 dark:border-gray-500 flex items-center justify-between">
+ <h2 class="text-2xl font-bold leading-7 text-gray-900 dark:text-gray-100 sm:text-3xl sm:leading-9 sm:truncate flex-shrink-0">
+ <.link
+ replace
+ patch={
+ Routes.customer_support_path(PlausibleWeb.Endpoint, :index, %{filter_text: @filter_text})
+ }
+ >
+ 💬 Customer Support
+ </.link>
+ </h2>
+ </div>
+ """
+ end
+
+ attr :filter_text, :string, required: true
+ slot :inner_block, required: false
+
+ defp search_bar(assigns) do
+ ~H"""
+ <div class="mb-4 mt-4">
+ <.filter_bar filter_text={@filter_text} placeholder="Search everything">
+ <a class="cursor-pointer" @click="openHelp = !openHelp">
+ <Heroicons.question_mark_circle class="text-indigo-700 dark:text-gray-500 w-5 h-5 hover:stroke-2" />
+ </a>
+ {render_slot(@inner_block)}
+ </.filter_bar>
+ </div>
+ """
+ end
+end
diff --git a/extra/lib/plausible_web/live/customer_support/components/search.ex b/extra/lib/plausible_web/live/customer_support/components/search.ex
new file mode 100644
index 0000000000..f45ca34218
--- /dev/null
+++ b/extra/lib/plausible_web/live/customer_support/components/search.ex
@@ -0,0 +1,116 @@
+defmodule PlausibleWeb.CustomerSupport.Components.Search do
+ @moduledoc """
+ Dedicated search component for Customer Support
+ Handles search logic independently from other components
+ """
+ use PlausibleWeb, :live_component
+
+ alias Plausible.CustomerSupport.Resource
+ alias PlausibleWeb.CustomerSupport.Components.SearchResult
+
+ @resources [Resource.Team, Resource.User, Resource.Site]
+
+ def update(%{filter_text: filter_text} = assigns, socket) do
+ socket = assign(socket, assigns)
+ {:ok, perform_search(socket, filter_text)}
+ end
+
+ def handle_event("search-updated", %{"filter_text" => filter_text}, socket) do
+ {:noreply, perform_search(socket, filter_text)}
+ end
+
+ def render(assigns) do
+ ~H"""
+ <div>
+ <ul :if={@results != []} class="my-6 grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3">
+ <li :for={r <- @results} class="group relative">
+ <.link patch={r.path} data-test-type={r.type} data-test-id={r.id}>
+ <div class="col-span-1 bg-white dark:bg-gray-800 rounded-lg shadow p-4 group-hover:shadow-lg cursor-pointer">
+ <div class="text-gray-800 dark:text-gray-500 w-full flex items-center justify-between space-x-4">
+ <.render_result resource={r} />
+ </div>
+ </div>
+ </.link>
+ </li>
+ </ul>
+
+ <div
+ :if={@results == [] && String.trim(@filter_text) != ""}
+ class="text-center py-8 text-gray-500"
+ >
+ No results found for "{@filter_text}"
+ </div>
+
+ <div
+ :if={@results == [] && String.trim(@filter_text) == ""}
+ class="text-center py-8 text-gray-500"
+ >
+ Enter a search term to find teams, users, or sites
+ </div>
+ </div>
+ """
+ end
+
+ def render_result(assigns) do
+ SearchResult.render_result(assigns)
+ end
+
+ defp perform_search(socket, filter_text) do
+ results = spawn_searches(filter_text)
+ assign(socket, :results, results)
+ end
+
+ defp spawn_searches(input) do
+ input = String.trim(input)
+
+ {resources, input, opts} =
+ maybe_focus_search(input)
+
+ resources
+ |> Task.async_stream(fn resource ->
+ input
+ |> resource.search(opts)
+ |> Enum.map(&resource.dump/1)
+ end)
+ |> Enum.reduce([], fn {:ok, results}, acc ->
+ acc ++ results
+ end)
+ end
+
+ defp maybe_focus_search(lone_modifier) when lone_modifier in ["site:", "team:", "user:"] do
+ {[], "", limit: 0}
+ end
+
+ defp maybe_focus_search("site:" <> rest) do
+ {[Resource.Site], rest, limit: 90}
+ end
+
+ defp maybe_focus_search("team:" <> rest) do
+ [input | mods] = String.split(rest, "+", trim: true)
+ input = String.trim(input)
+
+ opts =
+ if "sub" in mods do
+ [limit: 90, with_subscription_only?: true]
+ else
+ [limit: 90]
+ end
+
+ opts =
+ if "sso" in mods do
+ Keyword.merge(opts, with_sso_only?: true)
+ else
+ opts
+ end
+
+ {[Resource.Team], input, opts}
+ end
+
+ defp maybe_focus_search("user:" <> rest) do
+ {[Resource.User], rest, limit: 90}
+ end
+
+ defp maybe_focus_search(input) do
+ {@resources, input, limit: 30}
+ end
+end
diff --git a/extra/lib/plausible_web/live/customer_support/components/search_result.ex b/extra/lib/plausible_web/live/customer_support/components/search_result.ex
new file mode 100644
index 0000000000..31d53f0b89
--- /dev/null
+++ b/extra/lib/plausible_web/live/customer_support/components/search_result.ex
@@ -0,0 +1,109 @@
+defmodule PlausibleWeb.CustomerSupport.Components.SearchResult do
+ @moduledoc """
+ Component responsible for rendering search result cards for customer support resources
+ """
+ use PlausibleWeb, :live_component
+
+ def favicon(assigns) do
+ ~H"""
+ <img src={"/favicon/sources/#{@domain}"} class={@class} />
+ """
+ end
+
+ def render_result(%{resource: %{type: "team"}} = assigns) do
+ ~H"""
+ <div class="flex-1 -mt-px w-full">
+ <div class="w-full flex items-center justify-between space-x-4">
+ <div class="w-5 h-5 rounded-full bg-blue-500 flex items-center justify-center">
+ <span class="text-white text-xs font-bold">T</span>
+ </div>
+ <h3
+ class="text-gray-900 font-medium text-lg truncate dark:text-gray-100"
+ style="width: calc(100% - 4rem)"
+ >
+ {@resource.object.name}
+ </h3>
+
+ <span class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-blue-100 text-blue-800">
+ Team
+ </span>
+ </div>
+
+ <hr class="mt-4 mb-4 flex-grow border-t border-gray-200 dark:border-gray-600" />
+ <div class="text-sm truncate">
+ <div :if={@resource.object.owners}>
+ Owner(s): {Enum.map_join(@resource.object.owners, ", ", & &1.name)}
+ </div>
+ <div :if={@resource.object.subscription}>
+ Plan: {@resource.object.subscription.paddle_plan_id || "Free"}
+ </div>
+ <div :if={is_nil(@resource.object.subscription)}>
+ Plan: Free
+ </div>
+ <div :if={@resource.object.sites && is_list(@resource.object.sites)}>
+ {length(@resource.object.sites)} site(s)
+ </div>
+ <div :if={[email protected] || !is_list(@resource.object.sites)}>
+ Sites: Not loaded
+ </div>
+ </div>
+ </div>
+ """
+ end
+
+ def render_result(%{resource: %{type: "user"}} = assigns) do
+ ~H"""
+ <div class="flex-1 -mt-px w-full">
+ <div class="w-full flex items-center justify-between space-x-4">
+ <img src={Plausible.Auth.User.profile_img_url(@resource.object)} class="h-5 w-5 rounded-full" />
+ <h3
+ class="text-gray-900 font-medium text-lg truncate dark:text-gray-100"
+ style="width: calc(100% - 4rem)"
+ >
+ {@resource.object.name}
+ </h3>
+
+ <span class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-red-100 text-red-800">
+ User
+ </span>
+ </div>
+
+ <hr class="mt-4 mb-4 flex-grow border-t border-gray-200 dark:border-gray-600" />
+ <div class="text-sm truncate">
+ {@resource.object.name} &lt;{@resource.object.email}&gt; <br />
+ <br /> Owns {length(@resource.object.owned_teams)} team(s)
+ </div>
+ </div>
+ """
+ end
+
+ def render_result(%{resource: %{type: "site"}} = assigns) do
+ ~H"""
+ <div class="flex-1 -mt-px w-full">
+ <div class="w-full flex items-center justify-between space-x-4">
+ <.favicon class="w-5" domain={@resource.object.domain} />
+ <h3
+ class="text-gray-900 font-medium text-lg truncate dark:text-gray-100"
+ style="width: calc(100% - 4rem)"
+ >
+ {@resource.object.domain}
+ </h3>
+
+ <span class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-green-100 text-green-800">
+ Site
+ </span>
+ </div>
+
+ <hr class="mt-4 mb-4 flex-grow border-t border-gray-200 dark:border-gray-600" />
+ <div class="text-sm truncate">
+ Part of <strong>{@resource.object.team.name}</strong>
+ <br />
+ <br />
+ <div :if={@resource.object.team && @resource.object.team.locked}>
+ <span class="text-red-600 font-bold">🔒 TEAM LOCKED</span>
+ </div>
+ </div>
+ </div>
+ """
+ end
+end
diff --git a/extra/lib/plausible_web/live/customer_support/live.ex b/extra/lib/plausible_web/live/customer_support/live.ex
new file mode 100644
index 0000000000..fecf2f8b77
--- /dev/null
+++ b/extra/lib/plausible_web/live/customer_support/live.ex
@@ -0,0 +1,133 @@
+defmodule PlausibleWeb.CustomerSupport.Live do
+ @moduledoc """
+ Shared module providing common LiveView functionality for Customer Support.
+
+ Provides:
+ - Standard mount/3 and handle_info/2 implementations
+ - Tab navigation components and routing utilities
+ - Common aliases and imports for Customer Support LiveViews
+ - Convenience API for flashes and redirects
+ """
+
+ defmacro __using__(_opts) do
+ quote do
+ use PlausibleWeb, :live_view
+
+ alias Plausible.CustomerSupport.Resource
+ alias PlausibleWeb.CustomerSupport.Components.Layout
+ import PlausibleWeb.CustomerSupport.Live
+ import PlausibleWeb.Components.Generic
+ alias PlausibleWeb.Router.Helpers, as: Routes
+
+ def mount(_params, _session, socket) do
+ {:ok, socket}
+ end
+
+ def handle_info({:success, msg}, socket) do
+ {:noreply, put_flash(socket, :success, msg)}
+ end
+
+ def handle_info({:error, msg}, socket) do
+ {:noreply, put_flash(socket, :error, msg)}
+ end
+
+ def handle_info({:navigate, path, success_msg}, socket) do
+ socket = if success_msg, do: put_flash(socket, :success, success_msg), else: socket
+ {:noreply, push_navigate(socket, to: path)}
+ end
+
+ def handle_params(%{"id" => _id} = params, _uri, socket) do
+ handle_params(Map.put(params, "tab", "overview"), nil, socket)
+ end
+
+ defoverridable mount: 3, handle_info: 2, handle_params: 3
+ end
+ end
+
+ @spec success(String.t()) :: :ok
+ def success(msg) do
+ send(self(), {:success, msg})
+ end
+
+ @spec failure(String.t()) :: :ok
+ def failure(msg) do
+ send(self(), {:error, msg})
+ end
+
+ @spec navigate_with_success(String.t(), String.t()) :: :ok
+ def navigate_with_success(path, msg) do
+ send(self(), {:navigate, path, msg})
+ end
+
+ use Phoenix.Component
+ import Phoenix.LiveView
+
+ attr :to, :string, required: true
+ attr :tab, :string, required: true
+ slot :inner_block, required: true
+
+ def tab(assigns) do
+ current_class = "text-gray-900 dark:text-gray-100"
+
+ inactive_class =
+ "text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200"
+
+ assigns =
+ assign(
+ assigns,
+ :link_class,
+ if(assigns.to == assigns.tab, do: current_class, else: inactive_class)
+ )
+
+ ~H"""
+ <.link
+ patch={"?tab=#{@to}"}
+ class={[
+ @link_class,
+ "group relative min-w-0 flex-1 overflow-hidden bg-white dark:bg-gray-800 py-4 px-6 text-center text-sm font-medium hover:bg-gray-50 dark:hover:bg-gray-750 focus:z-10 first:rounded-l-lg last:rounded-r-lg"
+ ]}
+ >
+ {render_slot(@inner_block)}
+ </.link>
+ """
+ end
+
+ attr :tab, :string, required: true
+ attr :extra_classes, :string, default: ""
+ slot :tabs, required: true
+
+ def tab_navigation(assigns) do
+ ~H"""
+ <div class="mt-4">
+ <div class="hidden sm:block">
+ <nav
+ class={[
+ "isolate flex divide-x dark:divide-gray-900 divide-gray-200 rounded-lg shadow dark:shadow-1",
+ @extra_classes
+ ]}
+ aria-label="Tabs"
+ >
+ {render_slot(@tabs)}
+ </nav>
+ </div>
+ </div>
+ """
+ end
+
+ def go_to_tab(socket, tab, params, resource_key, component) do
+ tab_params = Map.drop(params, ["id", "tab"])
+ resource = Map.get(socket.assigns, resource_key)
+
+ update_params = [
+ id: "#{resource_key}-#{resource.id}-#{tab}",
+ tab: tab,
+ tab_params: tab_params
+ ]
+
+ update_params = Keyword.put(update_params, resource_key, resource)
+
+ send_update(component, update_params)
+
+ socket
+ end
+end
diff --git a/extra/lib/plausible_web/live/customer_support/live/shared.ex b/extra/lib/plausible_web/live/customer_support/live/shared.ex
deleted file mode 100644
index 8eaf148252..0000000000
--- a/extra/lib/plausible_web/live/customer_support/live/shared.ex
+++ /dev/null
@@ -1,30 +0,0 @@
-defmodule PlausibleWeb.CustomerSupport.Live.Shared do
- @moduledoc false
- use Phoenix.Component
-
- attr :to, :string, required: true
- attr :tab, :string, required: true
- slot :inner_block, required: true
-
- def tab(assigns) do
- ~H"""
- <.link
- replace
- patch={"?tab=#{@to}"}
- class="group relative min-w-0 flex-1 overflow-hidden rounded-l-lg px-4 py-4 text-center text-sm font-medium focus:z-10 cursor-pointer text-gray-800 dark:text-gray-200"
- >
- <span class={if(@tab == @to, do: "font-bold")}>
- {render_slot(@inner_block)}
- </span>
- <span
- aria-hidden="true"
- class={[
- "absolute inset-x-0 bottom-0 h-0.5",
- if(@tab == @to, do: "dark:bg-indigo-300 bg-indigo-500", else: "bg-transparent")
- ]}
- >
- </span>
- </.link>
- """
- end
-end
diff --git a/extra/lib/plausible_web/live/customer_support/live/site.ex b/extra/lib/plausible_web/live/customer_support/live/site.ex
deleted file mode 100644
index 37ab13a027..0000000000
--- a/extra/lib/plausible_web/live/customer_support/live/site.ex
+++ /dev/null
@@ -1,343 +0,0 @@
-defmodule PlausibleWeb.CustomerSupport.Live.Site do
- @moduledoc false
- use Plausible.CustomerSupport.Resource, :component
-
- alias PlausibleWeb.Live.Components.ComboBox
- alias Plausible.Repo
- import Ecto.Query
-
- def update(%{resource_id: resource_id}, socket) do
- site = Resource.Site.get(resource_id)
- changeset = Plausible.Site.crm_changeset(site, %{})
- form = to_form(changeset)
- {:ok, assign(socket, site: site, form: form)}
- end
-
- def update(%{tab: "people"}, %{assigns: %{site: site}} = socket) do
- people = Plausible.Sites.list_people(site)
-
- people =
- (people.invitations ++ people.memberships)
- |> Enum.map(fn p ->
- if Map.has_key?(p, :invitation_id) do
- {:invitation, p.email, p.role}
- else
- {:membership, p.user, p.role}
- end
- end)
-
- {:ok, assign(socket, people: people, tab: "people")}
- end
-
- def update(%{tab: "rescue-zone"}, %{assigns: %{site: site}} = socket) do
- first_owner =
- hd(Repo.preload(site, :owners).owners)
-
- {:ok, assign(socket, tab: "rescue-zone", first_owner: first_owner)}
- end
-
- def update(_, socket) do
- {:ok, assign(socket, tab: "overview")}
- end
-
- attr :tab, :string, default: "overview"
-
- def render(assigns) do
- ~H"""
- <div class="p-6">
- <div class="flex items-center">
- <div class="rounded-full p-1 mr-4">
- <.favicon class="w-8" domain={@site.domain} />
- </div>
-
- <div>
- <p class="text-xl font-bold sm:text-2xl flex items-center gap-x-2">
- {@site.domain}
-
- <span
- :if={
- @site.team.accept_traffic_until &&
- Date.after?(Date.utc_today(), @site.team.accept_traffic_until)
- }
- class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-red-100 text-red-800"
- >
- Rejecting traffic
- </span>
-
- <span
- :if={@site.ingest_rate_limit_threshold == 0}
- class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-red-100 text-red-800"
- >
- Traffic blocked
- </span>
- </p>
- <p class="text-sm font-medium">
- Timezone: {@site.timezone}
- </p>
- <p class="text-sm font-medium">
- Team:
- <.styled_link patch={"/cs/teams/team/#{@site.team.id}"}>
- {@site.team.name}
- </.styled_link>
- </p>
- <p class="text-sm font-medium">
- <span :if={@site.domain_changed_from}>(previously: {@site.domain_changed_from})</span>
- </p>
- </div>
- </div>
-
- <div>
- <div class="hidden sm:block">
- <nav
- class="isolate flex divide-x dark:divide-gray-900 divide-gray-200 rounded-lg shadow dark:shadow-1"
- aria-label="Tabs"
- >
- <.tab to="overview" tab={@tab}>Overview</.tab>
- <.tab to="people" tab={@tab}>
- People
- </.tab>
- <.tab to="rescue-zone" tab={@tab}>
- Rescue Zone
- </.tab>
- </nav>
- </div>
- </div>
-
- <.form
- :let={f}
- :if={@tab == "overview"}
- for={@form}
- phx-target={@myself}
- phx-submit="save-site"
- class="mt-8"
- >
- <div class="flex justify-center items-center gap-x-8 pb-8 mb-8 border-b border-gray-200 dark:border-gray-700 w-full text-sm text-center">
- <span>Quick links:</span>
-
- <.styled_link
- new_tab={true}
- href={Routes.stats_path(PlausibleWeb.Endpoint, :stats, @site.domain, [])}
- >
- Dashboard
- </.styled_link>
-
- <.styled_link
- new_tab={true}
- href={Routes.site_path(PlausibleWeb.Endpoint, :settings_general, @site.domain, [])}
- >
- Settings
- </.styled_link>
-
- <.styled_link
- new_tab={true}
- href={"https://plausible.grafana.net/d/BClBG5b4k/ingest-counters-per-domain?orgId=1&from=now-24h&to=now&timezone=browser&var-domain=#{@site.domain}&refresh=10s"}
- >
- Ingest Overview
- </.styled_link>
- </div>
-
- <.input
- type="select"
- field={f[:timezone]}
- label="Timezone"
- options={Plausible.Timezones.options()}
- />
- <.input type="checkbox" field={f[:public]} label="Public?" />
- <.input type="datetime-local" field={f[:native_stats_start_at]} label="Native Stats Start At" />
- <.input
- type="text"
- field={f[:ingest_rate_limit_threshold]}
- label="Ingest Rate Limit Threshold"
- />
- <.input
- type="text"
- field={f[:ingest_rate_limit_scale_seconds]}
- label="Ingest Rate Limit Scale Seconds"
- />
-
- <div class="flex justify-between">
- <.button phx-target={@myself} type="submit">
- Save
- </.button>
-
- <.button
- phx-target={@myself}
- phx-click="delete-site"
- data-confirm="Are you sure you want to delete this site?"
- theme="danger"
- >
- Delete Site
- </.button>
- </div>
- </.form>
-
- <div :if={@tab == "people"} class="mt-8">
- <.table rows={@people}>
- <:thead>
- <.th>User</.th>
- <.th>Kind</.th>
- <.th>Role</.th>
- </:thead>
- <:tbody :let={{kind, person, role}}>
- <.td :if={kind == :membership}>
- <.styled_link class="flex items-center" patch={"/cs/users/user/#{person.id}"}>
- <img
- src={Plausible.Auth.User.profile_img_url(person)}
- class="w-4 rounded-full bg-gray-300 mr-2"
- />
- {person.name}
- </.styled_link>
- </.td>
-
- <.td :if={kind == :invitation}>
- <div class="flex items-center">
- <img
- src={Plausible.Auth.User.profile_img_url(person)}
- class="w-4 rounded-full bg-gray-300 mr-2"
- />
- {person}
- </div>
- </.td>
-
- <.td :if={kind == :membership}>
- Membership
- </.td>
-
- <.td :if={kind == :invitation}>
- Invitation
- </.td>
- <.td>{role}</.td>
- </:tbody>
- </.table>
- </div>
-
- <div :if={@tab == "rescue-zone"} class="mt-8">
- <h1 class="text-xs font-semibold">Transfer Site</h1>
- <form class="mt-4 mb-8" phx-target={@myself} phx-submit="init-transfer">
- <.label for="inviter_email">
- Initiate transfer as
- </.label>
- <.live_component
- id="inviter_email"
- submit_name="inviter_email"
- class={[
- "mb-4"
- ]}
- module={ComboBox}
- suggest_fun={fn input, _ -> search_email(input) end}
- selected={{@first_owner.email, "#{@first_owner.name} <#{@first_owner.email}>"}}
- />
-
- <.label for="invitee_email">
- Send transfer invitation to
- </.label>
- <.live_component
- id="invitee_email"
- submit_name="invitee_email"
- module={ComboBox}
- suggest_fun={fn input, _ -> search_email(input) end}
- creatable
- />
- <.button phx-target={@myself} type="submit">
- Initiate Site Transfer
- </.button>
- </form>
- </div>
- </div>
- """
- end
-
- def render_result(assigns) do
- ~H"""
- <div class="flex-1 -mt-px w-full">
- <div class="w-full flex items-center justify-between space-x-4">
- <.favicon class="w-5" domain={@resource.object.domain} />
- <h3
- class="text-gray-900 font-medium text-lg truncate dark:text-gray-100"
- style="width: calc(100% - 4rem)"
- >
- {@resource.object.domain}
- </h3>
-
- <span class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-green-100 text-green-800">
- Site
- </span>
- </div>
-
- <hr class="mt-4 mb-4 flex-grow border-t border-gray-200 dark:border-gray-600" />
- <div class="text-sm truncate">
- Part of <strong>{@resource.object.team.name}</strong>
- <br />
- owned by {@resource.object.team.owners
- |> Enum.map(& &1.name)
- |> Enum.join(", ")}
- </div>
- </div>
- """
- end
-
- attr :domain, :string, required: true
- attr :class, :string, required: true
-
- def favicon(assigns) do
- ~H"""
- <img src={"/favicon/sources/#{@domain}"} class={@class} />
- """
- end
-
- def handle_event("save-site", %{"site" => params}, socket) do
- changeset = Plausible.Site.crm_changeset(socket.assigns.site, params)
-
- case Plausible.Repo.update(changeset) do
- {:ok, site} ->
- success(socket, "Site saved")
- {:noreply, assign(socket, site: site, form: to_form(changeset))}
-
- {:error, changeset} ->
- failure(socket, "Error saving site: #{inspect(changeset.errors)}")
- {:noreply, assign(socket, form: to_form(changeset))}
- end
- end
-
- def handle_event("delete-site", _, socket) do
- Plausible.Site.Removal.run(socket.assigns.site)
-
- {:noreply, push_navigate(put_flash(socket, :success, "Site deleted"), to: "/cs")}
- end
-
- def handle_event("init-transfer", params, socket) do
- inviter = Plausible.Repo.get_by!(Plausible.Auth.User, email: params["inviter_email"])
-
- case Plausible.Teams.Invitations.InviteToSite.invite(
- socket.assigns.site,
- inviter,
- params["invitee_email"],
- :owner
- ) do
- {:ok, _transfer} ->
- success(socket, "Transfer e-mail sent!")
-
- error ->
- failure(socket, inspect(error))
- end
-
- {:noreply, socket}
- end
-
- defp search_email(input) do
- Repo.all(
- from u in Plausible.Auth.User,
- where: ilike(u.name, ^"%#{input}%") or ilike(u.email, ^"%#{input}%"),
- limit: 20,
- order_by: [
- desc: fragment("?.name = ?", u, ^input),
- desc: fragment("?.email = ?", u, ^input),
- asc: u.name
- ],
- select: {u.email, u.name}
- )
- |> Enum.map(fn {email, name} ->
- {email, "#{name} <#{email}>"}
- end)
- end
-end
diff --git a/extra/lib/plausible_web/live/customer_support/live/team.ex b/extra/lib/plausible_web/live/customer_support/live/team.ex
deleted file mode 100644
index adb8be690a..0000000000
--- a/extra/lib/plausible_web/live/customer_support/live/team.ex
+++ /dev/null
@@ -1,1322 +0,0 @@
-defmodule PlausibleWeb.CustomerSupport.Live.Team do
- @moduledoc false
- use Plausible.CustomerSupport.Resource, :component
-
- alias Plausible.Auth.SSO
- alias Plausible.Billing.EnterprisePlan
- alias Plausible.Billing.{Plans, Subscription}
- alias Plausible.Repo
- alias Plausible.Teams
- alias Plausible.Teams.Management.Layout
- alias PlausibleWeb.Router.Helpers, as: Routes
-
- require Plausible.Billing.Subscription.Status
-
- import Ecto.Query, only: [from: 2]
-
- def update(%{resource_id: resource_id}, socket) do
- team = Resource.Team.get(resource_id)
- changeset = Plausible.Teams.Team.crm_changeset(team, %{})
- form = to_form(changeset)
-
- usage = Teams.Billing.quota_usage(team, with_features: true)
-
- sso_integration = get_sso_integration(team)
-
- limits = %{
- monthly_pageviews: Teams.Billing.monthly_pageview_limit(team),
- sites: Teams.Billing.site_limit(team),
- team_members: Teams.Billing.team_member_limit(team)
- }
-
- {:ok,
- assign(socket,
- team: team,
- form: form,
- usage: usage,
- limits: limits,
- sso_integration: sso_integration
- )}
- end
-
- def update(%{tab: "sso"}, %{assigns: %{team: _team}} = socket) do
- {:ok, assign(socket, tab: "sso")}
- end
-
- def update(%{tab: "audit", tab_params: tab_params}, %{assigns: %{team: team}} = socket) do
- pagination_params = get_pagination_params(tab_params)
-
- audit_page = Plausible.Audit.list_entries_paginated([team_id: team.id], pagination_params)
-
- entries =
- Enum.map(audit_page.entries, fn entry ->
- meta = entry.meta
-
- meta =
- if entry.user_id && entry.user_id > 0 do
- user = Plausible.Repo.get(Plausible.Auth.User, entry.user_id)
- Map.put(meta, :user, user)
- else
- meta
- end
-
- meta =
- if entry.entity == "Plausible.Auth.User" do
- user = Plausible.Repo.get(Plausible.Auth.User, String.to_integer(entry.entity_id))
- Map.put(meta, :entity, user)
- else
- meta
- end
-
- Map.put(entry, :meta, meta)
- end)
-
- audit_page = %{audit_page | entries: entries}
- current_limit = pagination_params["limit"]
-
- {:ok,
- assign(socket,
- tab: "audit",
- audit_page: audit_page,
- revealed_audit_entry_id: nil,
- current_limit: current_limit
- )}
- end
-
- def update(%{tab: "sites"}, %{assigns: %{team: team}} = socket) do
- sites = Teams.owned_sites(team, 100)
- sites_count = Teams.owned_sites_count(team)
-
- {:ok, assign(socket, sites: sites, sites_count: sites_count, tab: "sites")}
- end
-
- def update(%{tab: "billing"}, %{assigns: %{team: team}} = socket) do
- plans = get_plans(team.id)
-
- plan =
- Plans.get_subscription_plan(team.subscription)
-
- attrs =
- if is_map(plan) do
- Map.take(plan, [
- :billing_interval,
- :monthly_pageview_limit,
- :site_limit,
- :team_member_limit,
- :hourly_api_request_limit,
- :features
- ])
- |> Map.update(:features, [], fn features ->
- Enum.map(features, &to_string(&1.name()))
- end)
- else
- %{
- monthly_pageview_limit: 10_000,
- hourly_api_request_limit: 600,
- site_limit: 10,
- team_member_limit: 10,
- features: Plausible.Billing.Feature.list() -- [Plausible.Billing.Feature.SSO]
- }
- end
-
- plan_form =
- to_form(
- EnterprisePlan.changeset(
- %EnterprisePlan{},
- attrs
- )
- )
-
- {:ok,
- assign(socket,
- plan: plan,
- plans: plans,
- plan_form: plan_form,
- show_plan_form?: false,
- editing_plan: nil,
- tab: "billing",
- cost_estimate: 0
- )}
- end
-
- def update(%{tab: "members"}, socket) do
- {:ok, refresh_members(socket)}
- end
-
- def update(_, socket) do
- {:ok, assign(socket, tab: "overview")}
- end
-
- attr :tab, :string, default: "overview"
-
- def render(assigns) do
- ~H"""
- <div>
- <script type="text/javascript">
- const featureChangeCallback = function(e) {
- const value = e.target.value
- const checked = e.target.checked
- const form = e.target.closest('form')
-
- if (value === 'sites_api' && checked) {
- form.querySelector('input[value=stats_api]').checked = true
- } else if (value === 'stats_api' && !checked) {
- form.querySelector('input[value=sites_api]').checked = false
- }
- }
- </script>
- <div class="overflow-hidden rounded-lg">
- <div class="p-6">
- <div class="sm:flex sm:items-center sm:justify-between">
- <div class="sm:flex sm:space-x-5">
- <div class="shrink-0">
- <div class={[
- team_bg(@team.identifier),
- "rounded-full p-1 flex items-center justify-center"
- ]}>
- <Heroicons.user_group class="h-14 w-14 text-white dark:text-gray-300" />
- </div>
- </div>
- <div class="mt-4 text-center sm:mt-0 sm:pt-1 sm:text-left">
- <p class="text-xl font-bold dark:text-gray-300 text-gray-900 sm:text-2xl">
- {@team.name}
- </p>
- <p class="text-sm font-medium">
- <span :if={@team.setup_complete}>Set up at {@team.setup_at}</span>
- <span :if={[email protected]_complete}>Not set up yet</span>
- </p>
- </div>
- </div>
-
- <div class="mt-5 flex justify-center sm:mt-0">
- <.input_with_clipboard
- id="team-identifier"
- name="team-identifier"
- label="Team Identifier"
- value={@team.identifier}
- onfocus="this.value = this.value;"
- />
- </div>
- </div>
- </div>
-
- <div>
- <div class="hidden sm:block">
- <nav
- class="isolate flex divide-x dark:divide-gray-900 divide-gray-200 rounded-lg shadow dark:shadow-none"
- aria-label="Tabs"
- >
- <.tab to="overview" tab={@tab}>Overview</.tab>
- <.tab to="members" tab={@tab}>
- Members ({number_format(@usage.team_members)}/{number_format(@limits.team_members)})
- </.tab>
- <.tab to="sites" tab={@tab}>
- Sites ({number_format(@usage.sites)}/{number_format(@limits.sites)})
- </.tab>
- <.tab :if={@sso_integration} to="sso" tab={@tab}>
- SSO
- </.tab>
- <.tab to="billing" tab={@tab}>
- Billing
- </.tab>
- <.tab to="audit" tab={@tab}>
- Audit
- </.tab>
- </nav>
- </div>
- </div>
-
- <div class="grid grid-cols-1 divide-y border-t sm:grid-cols-3 sm:divide-x sm:divide-y-0 dark:bg-gray-850 text-gray-900 dark:text-gray-400 dark:divide-gray-800 dark:border-gray-600">
- <div class="px-6 py-5 text-center text-sm font-medium">
- <span>
- <strong>Subscription status</strong> <br />{subscription_status(@team)}
- <div :if={
- @team.subscription && @team.subscription.status == Subscription.Status.deleted() &&
- }>
- <span class="flex items-center gap-x-8 justify-center mt-1">
- <div :if={not Teams.locked?(@team)}>
- <Heroicons.lock_open solid class="inline stroke-2 w-4 h-4 text-red-400 mr-1" />
- <.styled_link
- phx-click="refund-lock"
- phx-target={@myself}
- data-confirm="Are you sure you want to lock? The only way to unlock, is for the user to resubscribe."
- >
- Refund Lock
- </.styled_link>
- </div>
-
- <div :if={Teams.locked?(@team)}>
- <Heroicons.lock_closed solid class="inline stroke-2 w-4 h-4 text-red-400 mr-1" />
- Locked
- </div>
- </span>
- </div>
- </span>
- </div>
- <div class="px-6 py-5 text-center text-sm font-medium">
- <span>
- <strong>Subscription plan</strong> <br />{subscription_plan(@team)}
- </span>
- </div>
- <div class="px-6 py-5 text-center text-sm font-medium">
- <span>
- <strong>Grace Period</strong> <br />{grace_period_status(@team)}
-
- <div :if={@team.grace_period}>
- <span class="flex items-center gap-x-8 justify-center mt-1">
- <div>
- <Heroicons.lock_open solid class="inline stroke-2 w-4 h-4 text-red-400 mr-1" />
- <.styled_link phx-click="unlock" phx-target={@myself}>Unlock</.styled_link>
- </div>
-
- <div>
- <Heroicons.lock_closed solid class="inline stroke-2 w-4 h-4 text-red-400 mr-1" />
- <.styled_link phx-click="lock" phx-target={@myself}>Lock</.styled_link>
- </div>
- </span>
- </div>
- </span>
- </div>
- </div>
-
- <div :if={@tab == "sso"} class="mt-4 mb-4 text-gray-900 dark:text-gray-400">
- <div :if={@sso_integration} class="flex gap-x-8 mb-4 justify-between items-start">
- <p>
- Configured?: <code>{SSO.Integration.configured?(@sso_integration)}</code>
- <br /> IDP Signin URL:
- <code>
- {@sso_integration.config.idp_signin_url}
- </code>
- <br />IDP Entity ID: <code>{@sso_integration.config.idp_entity_id}</code>
- </p>
- <div class="ml-auto">
- <.button
- data-confirm="Are you sure you want to remove this SSO team integration, including all its domains and users?"
- id="remove-sso-integration"
- phx-click="remove-sso-integration"
- phx-target={@myself}
- theme="danger"
- >
- Remove Integration
- </.button>
- </div>
- </div>
- <.table rows={@sso_integration.sso_domains}>
- <:thead>
- <.th>Domain</.th>
- <.th>Status</.th>
- <.th></.th>
- </:thead>
- <:tbody :let={sso_domain}>
- <.td>
- {sso_domain.domain}
- </.td>
- <.td>
- {sso_domain.status}
- <span :if={sso_domain.verified_via}>
- (via {sso_domain.verified_via} at {Calendar.strftime(
- sso_domain.last_verified_at,
- "%b %-d, %Y"
- )})
- </span>
- </.td>
- <.td actions>
- <.delete_button
- id={"remove-sso-domain-#{sso_domain.identifier}"}
- phx-click="remove-sso-domain"
- phx-value-identifier={sso_domain.identifier}
- phx-target={@myself}
- class="text-sm text-red-600"
- data-confirm={"Are you sure you want to remove domain '#{sso_domain.domain}'? All SSO users will be deprovisioned and logged out."}
- />
- </.td>
- </:tbody>
- </.table>
- </div>
-
- <div :if={@tab == "audit"} class="mt-4 mb-4 text-gray-900 dark:text-gray-400 relative">
- <div :if={Enum.empty?(@audit_page.entries)} class="flex justify-center items-center">
- No audit logs yet
- </div>
- <div
- :if={@revealed_audit_entry_id}
- phx-target={@myself}
- phx-window-keydown="reveal-audit-entry"
- phx-key="escape"
- >
- <.input_with_clipboard
- id="audit-entry-identifier"
- name="audit-entry-identifier"
- label="Audit Entry Identifier"
- value={@revealed_audit_entry_id}
- />
- <div class="relative">
- <.input
- rows="16"
- type="textarea"
- id="audit-entry-change"
- name="audit-entry-change"
- value={
- Jason.encode!(
- Enum.find(@audit_page.entries, &(&1.id == @revealed_audit_entry_id)).change,
- pretty: true
- )
- }
- >
- </.input>
- <.styled_link
- class="text-sm float-right"
- onclick="var textarea = document.getElementById('audit-entry-change'); textarea.focus(); textarea.select(); document.execCommand('copy');"
- href="#"
- >
- <div class="flex items-center absolute top-4 right-4 text-xs gap-x-1">
- <Heroicons.document_duplicate class="h-4 w-4 text-indigo-700" /> COPY
- </div>
- </.styled_link>
-
- <.styled_link
- phx-click="reveal-audit-entry"
- phx-target={@myself}
- class="float-right pt-4 text-sm"
- >
- &larr; Return
- <kbd class="rounded border border-gray-200 dark:border-gray-600 px-2 font-mono font-normal text-xs text-gray-400">
- ESC
- </kbd>
- </.styled_link>
- </div>
- </div>
- <.table :if={is_nil(@revealed_audit_entry_id)} rows={@audit_page.entries}>
- <:thead>
- <.th invisible></.th>
- <.th invisible></.th>
- <.th>Name</.th>
- <.th>Entity</.th>
- <.th>Actor</.th>
- <.th invisible>Actions</.th>
- </:thead>
- <:tbody :let={entry}>
- <.td>{Calendar.strftime(entry.datetime, "%Y-%m-%d")}</.td>
- <.td>{Calendar.strftime(entry.datetime, "%H:%M:%S")}</.td>
- <.td class="font-mono">{entry.name}</.td>
- <.td truncate>
- <.audit_entity entry={entry} />
- </.td>
- <.td :if={entry.actor_type == :system}>
- <div class="flex items-center gap-x-1">
- <Heroicons.cog_6_tooth class="size-4" /> SYSTEM
- </div>
- </.td>
- <.td :if={entry.actor_type == :user} truncate>
- <.audit_user user={entry.meta.user} />
- </.td>
-
- <.td actions>
- <.edit_button
- phx-click="reveal-audit-entry"
- icon={:magnifying_glass_plus}
- phx-value-id={entry.id}
- phx-target={@myself}
- />
- </.td>
- </:tbody>
- </.table>
- <div
- :if={
- is_nil(@revealed_audit_entry_id) &&
- (@audit_page.metadata.before || @audit_page.metadata.after)
- }
- class="flex justify-between items-center mt-4"
- >
- <.button
- :if={@audit_page.metadata.before}
- id="prev-page"
- phx-click="paginate-audit"
- phx-value-before={@audit_page.metadata.before}
- phx-value-limit={@current_limit}
- phx-target={@myself}
- theme="bright"
- >
- &larr; Prev
- </.button>
- <div></div>
- <.button
- :if={@audit_page.metadata.after}
- id="next-page"
- phx-click="paginate-audit"
- phx-value-after={@audit_page.metadata.after}
- phx-value-limit={@current_limit}
- phx-target={@myself}
- theme="bright"
- >
- Next &rarr;
- </.button>
- </div>
- </div>
- <div :if={@tab == "billing"} class="mt-4 mb-4 text-gray-900 dark:text-gray-400">
- <h1 class="text-xs font-semibold">Usage</h1>
- <.table rows={monthly_pageviews_usage(@usage.monthly_pageviews, @limits.monthly_pageviews)}>
- <:thead>
- <.th invisible>Cycle</.th>
- <.th invisible>Dates</.th>
- <.th>Total</.th>
- <.th>Limit</.th>
- </:thead>
- <:tbody :let={{cycle, date, total, limit}}>
- <.td>{cycle}</.td>
- <.td>{date}</.td>
- <.td>
- <span class={if total > limit, do: "text-red-600"}>{number_format(total)}</span>
- </.td>
- <.td>{number_format(limit)}</.td>
- </:tbody>
- </.table>
-
- <p :if={@usage.features != []} class="mt-6 mb-4">
- <h1 class="text-xs font-semibold">Features Used</h1>
- <span class="text-sm">
- {@usage.features |> Enum.map(& &1.display_name()) |> Enum.join(", ")}
- </span>
- </p>
-
- <h1 :if={!@show_plan_form? and @plans != []} class="mt-8 text-xs font-semibold">
- Custom Plans
- </h1>
- <.table :if={!@show_plan_form?} rows={@plans}>
- <:thead>
- <.th invisible>Interval</.th>
- <.th>Paddle Plan ID</.th>
- <.th>Limits</.th>
- <.th>Features</.th>
- <.th invisible>Actions</.th>
- </:thead>
- <:tbody :let={plan}>
- <.td class="align-top">
- {plan.billing_interval}
- </.td>
- <.td class="align-top">
- {plan.paddle_plan_id}
-
- <span
- :if={
- (@team.subscription && @team.subscription.paddle_plan_id) == plan.paddle_plan_id
- }
- class="inline-flex items-center px-2 py-0.5 rounded text-xs font-xs bg-red-100 text-red-800"
- >
- CURRENT
- </span>
- </.td>
- <.td max_width="max-w-40">
- <.table rows={[
- {"Pageviews", number_format(plan.monthly_pageview_limit)},
- {"Sites", number_format(plan.site_limit)},
- {"Members", number_format(plan.team_member_limit)},
- {"API Requests", number_format(plan.hourly_api_request_limit)}
- ]}>
- <:tbody :let={{label, value}}>
- <.td>{label}</.td>
- <.td>{value}</.td>
- </:tbody>
- </.table>
- </.td>
- <.td class="align-top">
- <span :for={feat <- plan.features}>{feat.display_name()}<br /></span>
- </.td>
- <.td class="align-top">
- <.edit_button phx-click="edit-plan" phx-value-id={plan.id} phx-target={@myself} />
- </.td>
- </:tbody>
- </.table>
-
- <.form
- :let={f}
- :if={@show_plan_form?}
- for={@plan_form}
- id="save-plan"
- phx-submit={if @editing_plan, do: "update-plan", else: "save-plan"}
- phx-target={@myself}
- phx-change="estimate-cost"
- >
- <.input field={f[:paddle_plan_id]} label="Paddle Plan ID" autocomplete="off" />
- <.input
- type="select"
- options={["monthly", "yearly"]}
- field={f[:billing_interval]}
- label="Billing Interval"
- autocomplete="off"
- />
-
- <div class="flex items-center gap-x-4">
- <.input
- field={f[:monthly_pageview_limit]}
- label="Monthly Pageview Limit"
- autocomplete="off"
- width="w-[500]"
- />
-
- <.preview for={f[:monthly_pageview_limit]} />
- </div>
- <div class="flex items-center gap-x-4">
- <.input width="w-[500]" field={f[:site_limit]} label="Site Limit" autocomplete="off" />
-
- <.preview for={f[:site_limit]} />
- </div>
-
- <div class="flex items-center gap-x-4">
- <.input
- field={f[:team_member_limit]}
- label="Team Member Limit"
- autocomplete="off"
- width="w-[500]"
- />
-
- <.preview for={f[:team_member_limit]} />
- </div>
-
- <div class="flex items-center gap-x-4">
- <.input
- field={f[:hourly_api_request_limit]}
- label="Hourly API Request Limit"
- autocomplete="off"
- width="w-[500]"
- />
-
- <.preview for={f[:hourly_api_request_limit]} />
- </div>
-
- <.input
- :for={
- mod <-
- Plausible.Billing.Feature.list()
- |> Enum.sort_by(fn item -> if item.name() == :stats_api, do: 0, else: 1 end)
- }
- :if={not mod.free?()}
- x-on:change="featureChangeCallback(event)"
- type="checkbox"
- value={mod in (f.source.changes[:features] || f.source.data.features || [])}
- name={"#{f.name}[features[]][#{mod.name()}]"}
- label={mod.display_name()}
- />
-
- <div class="mt-8 flex align-center gap-x-4">
- <.input_with_clipboard
- id="cost-estimate"
- name="cost-estimate"
- label={"#{(f[:billing_interval].value || "monthly")} cost estimate"}
- value={@cost_estimate}
- />
-
- <.button theme="bright" phx-click="hide-plan-form" phx-target={@myself}>
- Cancel
- </.button>
-
- <.button type="submit">
- {if @editing_plan, do: "Update Plan", else: "Save Custom Plan"}
- </.button>
- </div>
- </.form>
-
- <.button
- :if={!@show_plan_form?}
- id="new-custom-plan"
- phx-click="show-plan-form"
- phx-target={@myself}
- >
- New Custom Plan
- </.button>
- </div>
-
- <div :if={@tab == "overview"} class="mt-8">
- <.form :let={f} for={@form} phx-submit="save-team" phx-target={@myself}>
- <.input field={f[:trial_expiry_date]} type="date" label="Trial Expiry Date" />
- <.input field={f[:accept_traffic_until]} type="date" label="Accept traffic Until" />
- <.input
- type="checkbox"
- field={f[:allow_next_upgrade_override]}
- label="Allow Next Upgrade Override"
- />
-
- <.input type="textarea" field={f[:notes]} label="Notes" />
-
- <div class="flex justify-between">
- <.button type="submit">
- Save
- </.button>
-
- <.button
- phx-target={@myself}
- phx-click="delete-team"
- data-confirm="Are you sure you want to delete this team?"
- theme="danger"
- >
- Delete Team
- </.button>
- </div>
- </.form>
- </div>
-
- <div :if={@tab == "sites"} class="mt-2">
- <.notice :if={@sites_count > 100} class="mt-4 mb-4">
- This team owns more than 100 sites. Displaying first 100 below.
- </.notice>
- <.table rows={@sites}>
- <:thead>
- <.th>Domain</.th>
- <.th>Previous Domain</.th>
- <.th>Timezone</.th>
- <.th invisible>Settings</.th>
- <.th invisible>Dashboard</.th>
- </:thead>
- <:tbody :let={site}>
- <.td>
- <div class="flex items-center">
- <img
- src="/favicon/sources/{site.domain}"
- onerror="this.onerror=null; this.src='/favicon/sources/placeholder';"
- class="w-4 h-4 flex-shrink-0 mt-px mr-2"
- />
- <.styled_link
- patch={"/cs/sites/site/#{site.id}"}
- class="cursor-pointer flex block items-center"
- >
- {site.domain}
- </.styled_link>
- </div>
- </.td>
- <.td>{site.domain_changed_from || "--"}</.td>
- <.td>{site.timezone}</.td>
- <.td>
- <.styled_link
- new_tab={true}
- href={Routes.stats_path(PlausibleWeb.Endpoint, :stats, site.domain, [])}
- >
- Dashboard
- </.styled_link>
- </.td>
- <.td>
- <.styled_link
- new_tab={true}
- href={Routes.site_path(PlausibleWeb.Endpoint, :settings_general, site.domain, [])}
- >
- Settings
- </.styled_link>
- </.td>
- </:tbody>
- </.table>
- </div>
-
- <div :if={@tab == "members"} class="mt-2">
- <.table rows={Layout.sorted_for_display(@team_layout)}>
- <:thead>
- <.th>User</.th>
- <.th>Sessions</.th>
- <.th>Type</.th>
- <.th>Role</.th>
- </:thead>
- <:tbody :let={{_, member}}>
- <.td truncate>
- <div :if={member.id != 0}>
- <.styled_link
- patch={"/cs/users/user/#{member.id}"}
- class="cursor-pointer flex block items-center"
- >
- <img
- src={
- Plausible.Auth.User.profile_img_url(%Plausible.Auth.User{email: member.email})
- }
- class="mr-4 w-6 rounded-full bg-gray-300"
- />
- {member.name} &lt;{member.email}&gt;
- </.styled_link>
- </div>
- <div :if={member.id == 0} class="flex items-center">
- <img
- src={
- Plausible.Auth.User.profile_img_url(%Plausible.Auth.User{email: member.email})
- }
- class="mr-4 w-6 rounded-full bg-gray-300"
- />
- {member.name} &lt;{member.email}&gt;
- </div>
- </.td>
- <.td>
- {@session_counts[member.meta.user.id] || 0}
- </.td>
- <.td>
- <div class="flex items-center gap-x-1">
- <span :if={member.meta.user.type == :sso}>SSO </span>{member.type}
-
- <.delete_button
- :if={member.meta.user.type == :sso}
- id={"deprovision-sso-user-#{member.id}"}
- phx-click="deprovision-sso-user"
- phx-value-identifier={member.id}
- phx-target={@myself}
- class="text-sm"
- icon={:user_minus}
- data-confirm="Are you sure you want to deprovision SSO user and convert them to a standard user? This will sign them out and force to use regular e-mail/password combination to log in again."
- />
- </div>
- </.td>
- <.td>
- {member.role}
- </.td>
- </:tbody>
- </.table>
- </div>
- </div>
- </div>
- """
- end
-
- def render_result(assigns) do
- ~H"""
- <div class="flex-1 -mt-px w-full">
- <div class="w-full flex items-center justify-between space-x-4">
- <div class={[
- team_bg(@resource.object.identifier),
- "rounded-full p-1 flex items-center justify-center"
- ]}>
- <Heroicons.user_group class="h-4 w-4 text-white" />
- </div>
- <h3
- class="text-gray-900 font-medium text-lg truncate dark:text-gray-100"
- style="width: calc(100% - 4rem)"
- >
- {@resource.object.name}
- </h3>
-
- <span class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-blue-100 text-blue-800">
- Team
- </span>
-
- <span
- :if={@resource.object.subscription}
- class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-green-100 text-green-800"
- >
- $
- </span>
- </div>
-
- <hr class="mt-4 mb-4 flex-grow border-t border-gray-200 dark:border-gray-600" />
- <div class="text-sm truncate">
- Team identifier:
- <code class="font-mono">{@resource.object.identifier |> String.slice(0, 8)}</code>
- <br />
- Owned by: {@resource.object.owners
- |> Enum.map(& &1.name)
- |> Enum.join(", ")}
- </div>
- </div>
- """
- end
-
- def handle_event("reveal-audit-entry", %{"id" => id}, socket) do
- {:noreply, assign(socket, revealed_audit_entry_id: id)}
- end
-
- def handle_event("reveal-audit-entry", _, socket) do
- {:noreply, assign(socket, revealed_audit_entry_id: nil)}
- end
-
- def handle_event("paginate-audit", params, socket) do
- pagination_params = get_pagination_params(params)
- team = socket.assigns.team
-
- query_params = %{"tab" => "audit"} |> Map.merge(pagination_params)
-
- {:noreply,
- push_patch(socket,
- to: "/cs/teams/team/#{team.id}?" <> URI.encode_query(query_params)
- )}
- end
-
- def handle_event("show-plan-form", _, socket) do
- {:noreply, assign(socket, show_plan_form?: true, editing_plan: nil)}
- end
-
- def handle_event("edit-plan", %{"id" => plan_id}, socket) do
- {plan_id, _} = Integer.parse(plan_id)
- plan = Enum.find(socket.assigns.plans, &(&1.id == plan_id))
-
- if plan do
- plan_form = to_form(EnterprisePlan.changeset(plan, %{}))
-
- {:noreply, assign(socket, show_plan_form?: true, editing_plan: plan, plan_form: plan_form)}
- else
- {:noreply, socket}
- end
- end
-
- def handle_event("remove-sso-integration", _, socket) do
- :ok = SSO.remove_integration(socket.assigns.sso_integration, force_deprovision?: true)
-
- socket =
- socket
- |> assign(sso_integration: nil)
- |> put_flash(:success, "SSO integration removed")
- |> refresh_members()
- |> push_navigate(
- to:
- Routes.customer_support_resource_path(
- socket,
- :details,
- :teams,
- :team,
- socket.assigns.team.id
- )
- )
-
- {:noreply, socket}
- end
-
- def handle_event("remove-sso-domain", %{"identifier" => i}, socket) do
- domain = Enum.find(socket.assigns.sso_integration.sso_domains, &(&1.identifier == i))
- :ok = SSO.Domains.remove(domain, force_deprovision?: true)
- socket = socket |> success("SSO domain removed") |> refresh_members()
- {:noreply, assign(socket, sso_integration: get_sso_integration(socket.assigns.team))}
- end
-
- def handle_event("hide-plan-form", _, socket) do
- {:noreply, assign(socket, show_plan_form?: false, editing_plan: nil)}
- end
-
- def handle_event("save-team", %{"team" => params}, socket) do
- changeset = Plausible.Teams.Team.crm_changeset(socket.assigns.team, params)
-
- case Plausible.Repo.update(changeset) do
- {:ok, team} ->
- success(socket, "Team saved")
- {:noreply, assign(socket, team: team, form: to_form(changeset))}
-
- {:error, changeset} ->
- failure(socket, "Error saving team: #{inspect(changeset.errors)}")
- {:noreply, assign(socket, form: to_form(changeset))}
- end
- end
-
- def handle_event("delete-team", _params, socket) do
- case Teams.delete(socket.assigns.team) do
- {:ok, :deleted} ->
- {:noreply, push_navigate(put_flash(socket, :success, "Team deleted"), to: "/cs")}
-
- {:error, :active_subscription} ->
- failure(
- socket,
- "The team has an active subscription which must be canceled first."
- )
-
- {:noreply, socket}
- end
- end
-
- def handle_event("deprovision-sso-user", %{"identifier" => user_id}, socket) do
- [id: String.to_integer(user_id)]
- |> Plausible.Auth.find_user_by()
- |> SSO.deprovision_user!()
-
- socket = socket |> success("SSO user deprovisioned") |> refresh_members()
- {:noreply, socket}
- end
-
- def handle_event("estimate-cost", %{"enterprise_plan" => params}, socket) do
- params = update_features_to_list(params)
-
- form =
- to_form(
- EnterprisePlan.changeset(
- %EnterprisePlan{},
- params
- )
- )
-
- params = sanitize_params(params)
-
- cost_estimate =
- Plausible.CustomerSupport.EnterprisePlan.estimate(
- params["billing_interval"],
- get_int_param(params, "monthly_pageview_limit"),
- get_int_param(params, "site_limit"),
- get_int_param(params, "team_member_limit"),
- get_int_param(params, "hourly_api_request_limit"),
- params["features"]
- )
-
- socket =
- assign(socket,
- cost_estimate: cost_estimate,
- plan_form: form
- )
-
- {:noreply, socket}
- end
-
- def handle_event("save-plan", %{"enterprise_plan" => params}, socket) do
- params =
- params
- |> update_features_to_list()
- |> sanitize_params()
-
- changeset = EnterprisePlan.changeset(%EnterprisePlan{team_id: socket.assigns.team.id}, params)
-
- case Plausible.Repo.insert(changeset) do
- {:ok, _plan} ->
- success(socket, "Plan saved")
- plans = get_plans(socket.assigns.team.id)
-
- {:noreply,
- assign(socket,
- plans: plans,
- plan_form: to_form(changeset),
- show_plan_form?: false,
- editing_plan: nil
- )}
-
- {:error, changeset} ->
- failure(socket, "Error saving plan: #{inspect(changeset.errors)}")
- {:noreply, assign(socket, plan_form: to_form(changeset))}
- end
- end
-
- def handle_event("update-plan", %{"enterprise_plan" => params}, socket) do
- params =
- params
- |> update_features_to_list()
- |> sanitize_params()
-
- changeset = EnterprisePlan.changeset(socket.assigns.editing_plan, params)
-
- case Plausible.Repo.update(changeset) do
- {:ok, _plan} ->
- success(socket, "Plan updated")
- plans = get_plans(socket.assigns.team.id)
-
- {:noreply,
- assign(socket,
- plans: plans,
- plan_form: to_form(changeset),
- show_plan_form?: false,
- editing_plan: nil
- )}
-
- {:error, changeset} ->
- failure(socket, "Error updating plan: #{inspect(changeset.errors)}")
- {:noreply, assign(socket, plan_form: to_form(changeset))}
- end
- end
-
- def handle_event("unlock", _, socket) do
- {:noreply, unlock_team(socket)}
- end
-
- def handle_event("lock", _, socket) do
- {:noreply, lock_team(socket)}
- end
-
- def handle_event("refund-lock", _, socket) do
- team = socket.assigns.team
-
- {:ok, team} =
- Repo.transaction(fn ->
- yesterday = Date.shift(Date.utc_today(), day: -1)
- Plausible.Billing.SiteLocker.set_lock_status_for(team, true)
- Repo.update!(Subscription.changeset(team.subscription, %{next_bill_date: yesterday}))
- Resource.Team.get(team.id)
- end)
-
- {:noreply, assign(socket, team: team)}
- end
-
- def team_bg(term) do
- list = [
- "bg-blue-500",
- "bg-blue-600",
- "bg-blue-700",
- "bg-blue-800",
- "bg-cyan-500",
- "bg-cyan-600",
- "bg-cyan-700",
- "bg-cyan-800",
- "bg-red-500",
- "bg-red-600",
- "bg-red-700",
- "bg-red-800",
- "bg-green-500",
- "bg-green-600",
- "bg-green-700",
- "bg-green-800",
- "bg-yellow-500",
- "bg-yellow-600",
- "bg-yellow-700",
- "bg-yellow-800",
- "bg-orange-500",
- "bg-orange-600",
- "bg-orange-700",
- "bg-orange-800",
- "bg-purple-500",
- "bg-purple-600",
- "bg-purple-700",
- "bg-purple-800",
- "bg-gray-500",
- "bg-gray-600",
- "bg-gray-700",
- "bg-gray-800",
- "bg-emerald-500",
- "bg-emerald-600",
- "bg-emerald-700",
- "bg-emerald-800"
- ]
-
- idx = :erlang.phash2(term, length(list))
- Enum.at(list, idx)
- end
-
- def subscription_status(team) do
- cond do
- team && team.subscription ->
- status_str =
- PlausibleWeb.SettingsView.present_subscription_status(team.subscription.status)
-
- if team.subscription.paddle_subscription_id do
- assigns = %{status_str: status_str, subscription: team.subscription}
-
- ~H"""
- <.styled_link new_tab={true} href={manage_url(@subscription)}>{@status_str}</.styled_link>
- """
- else
- status_str
- end
-
- Plausible.Teams.on_trial?(team) ->
- "On trial"
-
- true ->
- "Trial expired"
- end
- end
-
- defp manage_url(%{paddle_subscription_id: paddle_id} = _subscription) do
- Plausible.Billing.PaddleApi.vendors_domain() <>
- "/subscriptions/customers/manage/" <> paddle_id
- end
-
- def subscription_plan(team) do
- subscription = team.subscription
-
- if Subscription.Status.active?(subscription) && subscription.paddle_subscription_id do
- quota = PlausibleWeb.AuthView.subscription_quota(subscription)
- interval = PlausibleWeb.AuthView.subscription_interval(subscription)
-
- assigns = %{quota: quota, interval: interval, subscription: subscription}
-
- ~H"""
- <.styled_link new_tab={true} href={manage_url(@subscription)}>
- {@quota} ({@interval})
- </.styled_link>
- """
- else
- "--"
- end
- end
-
- def grace_period_status(team) do
- grace_period = team.grace_period
-
- case grace_period do
- nil ->
- "--"
-
- %{manual_lock: true, is_over: true} ->
- "Manually locked"
-
- %{manual_lock: true, is_over: false} ->
- "Waiting for manual lock"
-
- %{is_over: true} ->
- "ended"
-
- %{end_date: %Date{} = end_date} ->
- days_left = Date.diff(end_date, Date.utc_today())
- "#{days_left} days left"
- end
- end
-
- defp lock_team(socket) do
- if socket.assigns.team.grace_period do
- team = Plausible.Teams.end_grace_period(socket.assigns.team)
- Plausible.Billing.SiteLocker.set_lock_status_for(team, true)
-
- success(socket, "Team locked. Grace period ended.")
- assign(socket, team: team)
- else
- failure(socket, "No grace period")
- socket
- end
- end
-
- defp unlock_team(socket) do
- if socket.assigns.team.grace_period do
- team = Plausible.Teams.remove_grace_period(socket.assigns.team)
- Plausible.Billing.SiteLocker.set_lock_status_for(team, false)
-
- success(socket, "Team unlocked. Grace period removed.")
- assign(socket, team: team)
- else
- socket
- end
- end
-
- defp monthly_pageviews_usage(usage, limit) do
- usage
- |> Enum.sort_by(fn {_cycle, usage} -> usage.date_range.first end, :desc)
- |> Enum.map(fn {cycle, usage} ->
- {cycle, PlausibleWeb.TextHelpers.format_date_range(usage.date_range), usage.total, limit}
- end)
- end
-
- defp get_plans(team_id) do
- Repo.all(
- from ep in EnterprisePlan,
- where: ep.team_id == ^team_id,
- order_by: [desc: :id]
- )
- end
-
- defp number_format(unlimited) when unlimited in [-1, "unlimited", :unlimited] do
- "unlimited"
- end
-
- defp number_format(number) when is_integer(number) do
- Cldr.Number.to_string!(number)
- end
-
- defp number_format(other), do: other
-
- defp sanitize_params(params) do
- params
- |> Enum.map(&clear_param/1)
- |> Enum.reject(&(&1 == ""))
- |> Map.new()
- end
-
- defp clear_param({key, value}) when is_binary(value) do
- {key, String.trim(value)}
- end
-
- defp clear_param(other) do
- other
- end
-
- defp get_int_param(params, key) do
- param = Map.get(params, key)
- param = if param in ["", nil], do: "0", else: param
-
- case Integer.parse(param) do
- {integer, ""} -> integer
- _ -> 0
- end
- end
-
- defp update_features_to_list(params) do
- features =
- params["features[]"]
- |> Enum.reject(fn {_key, value} -> value == "false" or value == "" end)
- |> Enum.map(fn {key, _value} -> key end)
-
- Map.put(params, "features", features)
- end
-
- defp preview_number(n) do
- case Integer.parse("#{n}") do
- {n, ""} ->
- number_format(n) <> " (#{PlausibleWeb.StatsView.large_number_format(n)})"
-
- _ ->
- "0"
- end
- end
-
- attr :for, :any, required: true
-
- defp preview(assigns) do
- ~H"""
- <.input
- name={"#{@for.name}-preview"}
- label="Preview"
- autocomplete="off"
- width="w-[500]"
- readonly
- value={preview_number(@for.value)}
- class="bg-transparent border-0 p-0 m-0 text-sm w-full"
- />
- """
- end
-
- defp get_sso_integration(team) do
- case SSO.get_integration_for(team) do
- {:error, :not_found} -> nil
- {:ok, integration} -> integration
- end
- end
-
- defp refresh_members(socket) do
- team_layout = Layout.init(socket.assigns.team)
-
- session_counts =
- team_layout
- |> Enum.map(fn {_, entry} -> entry.meta.user end)
- |> Plausible.Auth.UserSessions.count_for_users()
- |> Enum.into(%{})
-
- assign(socket, team_layout: team_layout, session_counts: session_counts, tab: "members")
- end
-
- attr :entry, Plausible.Audit.Entry
-
- defp audit_entity(assigns) do
- ~H"""
- <%= if @entry.entity == "Plausible.Auth.User" do %>
- <.audit_user user={@entry.meta.entity} />
- <% else %>
- {@entry.entity |> String.split(".") |> List.last()} #{String.slice(@entry.entity_id, 0, 8)}
- <% end %>
- """
- end
-
- attr :user, Plausible.Auth.User
-
- defp audit_user(%{user: nil} = assigns) do
- ~H"""
- (N/A)
- """
- end
-
- defp audit_user(assigns) do
- ~H"""
- <div class="flex items-center gap-x-1">
- <img
- class="w-4"
- src={
- Plausible.Auth.User.profile_img_url(%Plausible.Auth.User{
- email: @user.email
- })
- }
- />
-
- <.styled_link
- patch={"/cs/users/user/#{@user.id}"}
- class="cursor-pointer flex block items-center"
- >
- {@user.name}
- </.styled_link>
- </div>
- """
- end
-
- defp get_pagination_params(params) do
- params
- |> Map.take(["after", "before", "limit"])
- |> Map.put_new("limit", 15)
- end
-end
diff --git a/extra/lib/plausible_web/live/customer_support/live/user.ex b/extra/lib/plausible_web/live/customer_support/live/user.ex
deleted file mode 100644
index a70480110e..0000000000
--- a/extra/lib/plausible_web/live/customer_support/live/user.ex
+++ /dev/null
@@ -1,224 +0,0 @@
-defmodule PlausibleWeb.CustomerSupport.Live.User do
- @moduledoc false
- use Plausible.CustomerSupport.Resource, :component
- use PlausibleWeb.Live.Flash
-
- import Ecto.Query
- alias Plausible.Repo
-
- def update(%{resource_id: resource_id}, socket) do
- user = socket.assigns[:user] || Resource.User.get(resource_id)
-
- if is_nil(user) do
- redirect(
- socket,
- to: Routes.customer_support_path(socket, :index)
- )
- else
- form = user |> Plausible.Auth.User.changeset() |> to_form()
- {:ok, assign(socket, user: user, form: form, tab: "overview", keys_count: keys_count(user))}
- end
- end
-
- def update(%{tab: "keys"}, socket) do
- keys = keys(socket.assigns.user)
- {:ok, assign(socket, tab: "keys", keys: keys)}
- end
-
- def update(_, socket) do
- {:ok, assign(socket, tab: "overview", keys_count: keys_count(socket.assigns.user))}
- end
-
- def render(assigns) do
- ~H"""
- <div class="p-6">
- <div class="sm:flex sm:items-center sm:justify-between">
- <div class="sm:flex sm:space-x-5">
- <div class="shrink-0">
- <div class="rounded-full p-1 flex items-center justify-center">
- <img
- src={Plausible.Auth.User.profile_img_url(@user)}
- class="w-14 rounded-full bg-gray-300"
- />
- </div>
- </div>
- <div class="mt-4 text-center sm:mt-0 sm:pt-1 sm:text-left">
- <p class="text-xl font-bold sm:text-2xl">
- <div class="flex items-center gap-x-2">
- {@user.name}
- <span :if={@user.type == :sso} class="bg-green-700 text-gray-100 text-xs p-1 rounded">
- SSO
- </span>
- </div>
- </p>
- <p class="text-sm font-medium">
- <span>{@user.email}</span>
-
- <span :if={@user.previous_email}>(previously: {@user.previous_email})</span>
- </p>
- </div>
- </div>
-
- <div class="mt-5 flex justify-center sm:mt-0">
- <.input_with_clipboard
- id="user-identifier"
- name="user-identifier"
- label="User Identifier"
- value={@user.id}
- />
- </div>
- </div>
-
- <div class="mt-4">
- <div class="hidden sm:block">
- <nav
- class="isolate flex divide-x dark:divide-gray-900 divide-gray-200 rounded-lg shadow dark:shadow-1"
- aria-label="Tabs"
- >
- <.tab to="overview" tab={@tab}>Overview</.tab>
- <.tab to="keys" tab={@tab}>
- API Keys ({@keys_count})
- </.tab>
- </nav>
- </div>
- </div>
-
- <div :if={@tab == "overview"} class="mt-8">
- <.table rows={@user.team_memberships}>
- <:thead>
- <.th>Team</.th>
- <.th>Role</.th>
- </:thead>
- <:tbody :let={membership}>
- <.td>
- <.styled_link patch={"/cs/teams/team/#{membership.team.id}"}>
- {membership.team.name}
- </.styled_link>
- </.td>
- <.td>{membership.role}</.td>
- </:tbody>
- </.table>
-
- <.form :let={f} for={@form} phx-target={@myself} phx-submit="save-user" class="mt-8">
- <.input type="textarea" field={f[:notes]} label="Notes" />
- <div class="flex justify-between">
- <.button phx-target={@myself} type="submit">
- Save
- </.button>
- <.button
- phx-target={@myself}
- phx-click="delete-user"
- data-confirm="Are you sure you want to delete this user?"
- theme="danger"
- >
- Delete User
- </.button>
- </div>
- </.form>
- </div>
-
- <div :if={@tab == "keys"} class="mt-8">
- <.table rows={@keys}>
- <:thead>
- <.th>Team</.th>
- <.th>Name</.th>
- <.th>Scopes</.th>
- <.th>Prefix</.th>
- </:thead>
- <:tbody :let={api_key}>
- <.td :if={is_nil(api_key.team)}>N/A</.td>
- <.td :if={api_key.team}>
- <.styled_link patch={"/cs/teams/team/#{api_key.team.id}"}>
- {api_key.team.name}
- </.styled_link>
- </.td>
- <.td>{api_key.name}</.td>
- <.td>
- {api_key.scopes}
- </.td>
- <.td>{api_key.key_prefix}</.td>
- </:tbody>
- </.table>
- </div>
- </div>
- """
- end
-
- def render_result(assigns) do
- ~H"""
- <div class="flex-1 -mt-px w-full">
- <div class="w-full flex items-center justify-between space-x-4">
- <img src={Plausible.Auth.User.profile_img_url(@resource.object)} class="h-5 w-5 rounded-full" />
- <h3
- class="text-gray-900 font-medium text-lg truncate dark:text-gray-100"
- style="width: calc(100% - 4rem)"
- >
- {@resource.object.name}
- </h3>
-
- <span class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-red-100 text-red-800">
- User
- </span>
- </div>
-
- <hr class="mt-4 mb-4 flex-grow border-t border-gray-200 dark:border-gray-600" />
- <div class="text-sm truncate">
- {@resource.object.name} &lt;{@resource.object.email}&gt; <br />
- <br /> Owns {length(@resource.object.owned_teams)} team(s)
- </div>
- </div>
- """
- end
-
- def handle_event("delete-user", _params, socket) do
- case Plausible.Auth.delete_user(socket.assigns.user) do
- {:ok, :deleted} ->
- {:noreply, push_navigate(put_flash(socket, :success, "User deleted"), to: "/cs")}
-
- {:error, :active_subscription} ->
- failure(
- socket,
- "User's personal team has an active subscription which must be canceled first."
- )
-
- {:noreply, socket}
-
- {:error, :is_only_team_owner} ->
- failure(socket, "The user is the only public team owner on one or more teams.")
- {:noreply, socket}
- end
- end
-
- def handle_event("save-user", %{"user" => params}, socket) do
- changeset = Plausible.Auth.User.changeset(socket.assigns.user, params)
-
- case Plausible.Repo.update(changeset) do
- {:ok, user} ->
- success(socket, "User updated")
- {:noreply, assign(socket, user: user, form: to_form(changeset))}
-
- {:error, changeset} ->
- failure(socket, inspect(changeset.errors))
- send(socket.root_pid, {:failure, inspect(changeset.errors)})
- {:noreply, assign(socket, form: to_form(changeset))}
- end
- end
-
- defp keys_query(user) do
- from api_key in Plausible.Auth.ApiKey,
- where: api_key.user_id == ^user.id,
- left_join: t in Plausible.Teams.Team,
- on: t.id == api_key.team_id,
- distinct: true,
- order_by: [desc: api_key.id],
- preload: [team: t]
- end
-
- def keys(user) do
- Repo.all(keys_query(user))
- end
-
- def keys_count(user) do
- Repo.aggregate(keys_query(user), :count)
- end
-end
diff --git a/extra/lib/plausible_web/live/customer_support/site.ex b/extra/lib/plausible_web/live/customer_support/site.ex
new file mode 100644
index 0000000000..88d450e2bd
--- /dev/null
+++ b/extra/lib/plausible_web/live/customer_support/site.ex
@@ -0,0 +1,115 @@
+defmodule PlausibleWeb.Live.CustomerSupport.Site do
+ @moduledoc """
+ Site coordinator LiveView for Customer Support interface.
+
+ Manages tab-based navigation and delegates rendering to specialized
+ components: Overview, People, and Rescue Zone.
+ """
+ use PlausibleWeb.CustomerSupport.Live
+
+ alias PlausibleWeb.CustomerSupport.Site.Components.{
+ Overview,
+ People,
+ RescueZone
+ }
+
+ def favicon(assigns) do
+ ~H"""
+ <img src={"/favicon/sources/#{@domain}"} class={@class} />
+ """
+ end
+
+ def handle_params(%{"id" => site_id} = params, _uri, socket) do
+ tab = params["tab"] || "overview"
+ site = Resource.Site.get(site_id)
+
+ if site do
+ socket =
+ socket
+ |> assign(:site, site)
+ |> assign(:tab, tab)
+
+ {:noreply, go_to_tab(socket, tab, params, :site, tab_component(tab))}
+ else
+ {:noreply, redirect(socket, to: Routes.customer_support_path(socket, :index))}
+ end
+ end
+
+ def render(assigns) do
+ ~H"""
+ <Layout.layout show_search={false} flash={@flash}>
+ <.site_header site={@site} />
+ <.site_tab_navigation site={@site} tab={@tab} />
+
+ <.live_component
+ module={tab_component(@tab)}
+ site={@site}
+ tab={@tab}
+ id={"site-#{@site.id}-#{@tab}"}
+ />
+ </Layout.layout>
+ """
+ end
+
+ defp site_header(assigns) do
+ ~H"""
+ <div class="flex items-center">
+ <div class="rounded-full p-1 mr-4">
+ <.favicon class="w-8" domain={@site.domain} />
+ </div>
+ <div>
+ <p class="text-xl font-bold sm:text-2xl">
+ {@site.domain}
+ <span
+ :if={
+ @site.ingest_rate_limit_threshold &&
+ @site.ingest_rate_limit_threshold < @site.ingest_rate_limit_scale_seconds
+ }
+ class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-red-100 text-red-800"
+ >
+ Rejecting traffic
+ </span>
+
+ <span
+ :if={@site.ingest_rate_limit_threshold == 0}
+ class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-red-100 text-red-800"
+ >
+ Traffic blocked
+ </span>
+ </p>
+ <p class="text-sm font-medium">
+ Timezone: {@site.timezone}
+ </p>
+ <p class="text-sm font-medium">
+ Team:
+ <.styled_link patch={
+ Routes.customer_support_team_path(PlausibleWeb.Endpoint, :show, @site.team.id)
+ }>
+ {@site.team.name}
+ </.styled_link>
+ </p>
+ <p class="text-sm font-medium">
+ <span :if={@site.domain_changed_from}>(previously: {@site.domain_changed_from})</span>
+ </p>
+ </div>
+ </div>
+ """
+ end
+
+ defp site_tab_navigation(assigns) do
+ ~H"""
+ <.tab_navigation tab={@tab}>
+ <:tabs>
+ <.tab to="overview" tab={@tab}>Overview</.tab>
+ <.tab to="people" tab={@tab}>People</.tab>
+ <.tab to="rescue-zone" tab={@tab}>Rescue Zone</.tab>
+ </:tabs>
+ </.tab_navigation>
+ """
+ end
+
+ defp tab_component("overview"), do: Overview
+ defp tab_component("people"), do: People
+ defp tab_component("rescue-zone"), do: RescueZone
+ defp tab_component(_), do: Overview
+end
diff --git a/extra/lib/plausible_web/live/customer_support/site/components/overview.ex b/extra/lib/plausible_web/live/customer_support/site/components/overview.ex
new file mode 100644
index 0000000000..31ee65ff81
--- /dev/null
+++ b/extra/lib/plausible_web/live/customer_support/site/components/overview.ex
@@ -0,0 +1,98 @@
+defmodule PlausibleWeb.CustomerSupport.Site.Components.Overview do
+ @moduledoc """
+ Site overview component - handles site settings and management
+ """
+ use PlausibleWeb, :live_component
+ import PlausibleWeb.CustomerSupport.Live
+
+ def update(%{site: site}, socket) do
+ changeset = Plausible.Site.crm_changeset(site, %{})
+ form = to_form(changeset)
+ {:ok, assign(socket, site: site, form: form)}
+ end
+
+ def render(assigns) do
+ ~H"""
+ <div class="mt-8">
+ <.form :let={f} for={@form} phx-target={@myself} phx-submit="save-site">
+ <div class="flex justify-center items-center gap-x-8 pb-8 mb-8 border-b border-gray-200 dark:border-gray-700 w-full text-sm text-center">
+ <span>Quick links:</span>
+
+ <.styled_link new_tab={true} href={"/#{@site.domain}"}>
+ Dashboard
+ </.styled_link>
+
+ <.styled_link new_tab={true} href={"/#{@site.domain}/settings/general"}>
+ Settings
+ </.styled_link>
+
+ <.styled_link
+ new_tab={true}
+ href={"https://plausible.grafana.net/d/BClBG5b4k/ingest-counters-per-domain?orgId=1&from=now-24h&to=now&timezone=browser&var-domain=#{@site.domain}&refresh=10s"}
+ >
+ Ingest Overview
+ </.styled_link>
+ </div>
+
+ <.input
+ type="select"
+ field={f[:timezone]}
+ label="Timezone"
+ options={Plausible.Timezones.options()}
+ />
+ <.input type="checkbox" field={f[:public]} label="Public?" />
+ <.input type="datetime-local" field={f[:native_stats_start_at]} label="Native Stats Start At" />
+ <.input
+ type="text"
+ field={f[:ingest_rate_limit_threshold]}
+ label="Ingest Rate Limit Threshold"
+ />
+ <.input
+ type="text"
+ field={f[:ingest_rate_limit_scale_seconds]}
+ label="Ingest Rate Limit Scale Seconds"
+ />
+
+ <div class="flex justify-between">
+ <.button phx-target={@myself} type="submit">
+ Save
+ </.button>
+
+ <.button
+ phx-target={@myself}
+ phx-click="delete-site"
+ data-confirm="Are you sure you want to delete this site?"
+ theme="danger"
+ >
+ Delete Site
+ </.button>
+ </div>
+ </.form>
+ </div>
+ """
+ end
+
+ def handle_event("save-site", %{"site" => params}, socket) do
+ site = socket.assigns.site
+
+ case Plausible.Site.crm_changeset(site, params) |> Plausible.Repo.update() do
+ {:ok, updated_site} ->
+ form = Plausible.Site.crm_changeset(updated_site, %{}) |> to_form()
+ success("Site updated successfully")
+ {:noreply, assign(socket, site: updated_site, form: form)}
+
+ {:error, changeset} ->
+ form = changeset |> to_form()
+ failure("Failed to update site")
+ {:noreply, assign(socket, form: form)}
+ end
+ end
+
+ def handle_event("delete-site", _, socket) do
+ site = socket.assigns.site
+
+ {:ok, _} = Plausible.Site.Removal.run(site)
+ navigate_with_success(Routes.customer_support_path(socket, :index), "Site deleted")
+ {:noreply, socket}
+ end
+end
diff --git a/extra/lib/plausible_web/live/customer_support/site/components/people.ex b/extra/lib/plausible_web/live/customer_support/site/components/people.ex
new file mode 100644
index 0000000000..f3d284ede6
--- /dev/null
+++ b/extra/lib/plausible_web/live/customer_support/site/components/people.ex
@@ -0,0 +1,70 @@
+defmodule PlausibleWeb.CustomerSupport.Site.Components.People do
+ @moduledoc """
+ Site people component - handles site memberships and invitations
+ """
+ use PlausibleWeb, :live_component
+
+ def update(%{site: site}, socket) do
+ people = Plausible.Sites.list_people(site)
+
+ people =
+ (people.invitations ++ people.memberships)
+ |> Enum.map(fn p ->
+ if Map.has_key?(p, :invitation_id) do
+ {:invitation, p.email, p.role}
+ else
+ {:membership, p.user, p.role}
+ end
+ end)
+
+ {:ok, assign(socket, site: site, people: people)}
+ end
+
+ def render(assigns) do
+ ~H"""
+ <div class="mt-8">
+ <.table rows={@people}>
+ <:thead>
+ <.th>User</.th>
+ <.th>Kind</.th>
+ <.th>Role</.th>
+ </:thead>
+ <:tbody :let={{kind, person, role}}>
+ <.td :if={kind == :membership}>
+ <.styled_link
+ class="flex items-center"
+ patch={Routes.customer_support_user_path(PlausibleWeb.Endpoint, :show, person.id)}
+ >
+ <img
+ src={Plausible.Auth.User.profile_img_url(person)}
+ class="w-4 rounded-full bg-gray-300 mr-2"
+ />
+ {person.name}
+ </.styled_link>
+ </.td>
+
+ <.td :if={kind == :invitation}>
+ <div class="flex items-center">
+ <img
+ src={Plausible.Auth.User.profile_img_url(person)}
+ class="w-4 rounded-full bg-gray-300 mr-2"
+ />
+ {person}
+ </div>
+ </.td>
+
+ <.td :if={kind == :membership}>
+ Membership
+ </.td>
+
+ <.td :if={kind == :invitation}>
+ Invitation
+ </.td>
+
+ <.td>{role}</.td>
+ </:tbody>
+ </.table>
+ </div>
+ """
+ end
+end
diff --git a/extra/lib/plausible_web/live/customer_support/site/components/rescue_zone.ex b/extra/lib/plausible_web/live/customer_support/site/components/rescue_zone.ex
new file mode 100644
index 0000000000..31e7dcc4ea
--- /dev/null
+++ b/extra/lib/plausible_web/live/customer_support/site/components/rescue_zone.ex
@@ -0,0 +1,89 @@
+defmodule PlausibleWeb.CustomerSupport.Site.Components.RescueZone do
+ @moduledoc """
+ Site rescue zone component - handles site transfer functionality
+ """
+ use PlausibleWeb, :live_component
+ import PlausibleWeb.CustomerSupport.Live
+ import PlausibleWeb.Components.Generic
+ import Ecto.Query
+ alias Plausible.Repo
+ alias PlausibleWeb.Live.Components.ComboBox
+
+ def update(%{site: site}, socket) do
+ first_owner =
+ hd(Repo.preload(site, :owners).owners)
+
+ {:ok, assign(socket, site: site, first_owner: first_owner)}
+ end
+
+ def render(assigns) do
+ ~H"""
+ <div class="mt-8">
+ <h1 class="text-xs font-semibold">Transfer Site</h1>
+ <form class="mt-4 mb-8" phx-target={@myself} phx-submit="init-transfer">
+ <.label for="inviter_email">
+ Initiate transfer as
+ </.label>
+ <.live_component
+ id="inviter_email"
+ submit_name="inviter_email"
+ class={[
+ "mb-4"
+ ]}
+ module={ComboBox}
+ suggest_fun={fn input, _ -> search_email(input) end}
+ selected={{@first_owner.email, "#{@first_owner.name} <#{@first_owner.email}>"}}
+ />
+
+ <.label for="invitee_email">
+ Send transfer invitation to
+ </.label>
+ <.live_component
+ id="invitee_email"
+ submit_name="invitee_email"
+ module={ComboBox}
+ suggest_fun={fn input, _ -> search_email(input) end}
+ creatable
+ />
+ <.button phx-target={@myself} type="submit">
+ Initiate Site Transfer
+ </.button>
+ </form>
+ </div>
+ """
+ end
+
+ def handle_event("init-transfer", params, socket) do
+ inviter = Plausible.Repo.get_by!(Plausible.Auth.User, email: params["inviter_email"])
+
+ case Plausible.Teams.Invitations.InviteToSite.invite(
+ socket.assigns.site,
+ inviter,
+ params["invitee_email"],
+ :owner
+ ) do
+ {:ok, _transfer} ->
+ success("Transfer e-mail sent!")
+ {:noreply, socket}
+
+ error ->
+ failure("Transfer failed: #{inspect(error)}")
+ {:noreply, socket}
+ end
+ end
+
+ defp search_email(input) do
+ Repo.all(
+ from u in Plausible.Auth.User,
+ where: ilike(u.name, ^"%#{input}%") or ilike(u.email, ^"%#{input}%"),
+ limit: 20,
+ order_by: [
+ desc: fragment("?.name = ?", u, ^input),
+ desc: fragment("?.email = ?", u, ^input),
+ asc: u.name
+ ],
+ select: {u.email, u.name}
+ )
+ |> Enum.map(fn {email, name} -> {email, "#{name} <#{email}>"} end)
+ end
+end
diff --git a/extra/lib/plausible_web/live/customer_support/team.ex b/extra/lib/plausible_web/live/customer_support/team.ex
new file mode 100644
index 0000000000..6932811e1a
--- /dev/null
+++ b/extra/lib/plausible_web/live/customer_support/team.ex
@@ -0,0 +1,357 @@
+defmodule PlausibleWeb.Live.CustomerSupport.Team do
+ @moduledoc """
+ Team coordinator LiveView for Customer Support interface.
+
+ Manages tab-based navigation and delegates rendering to specialized
+ components: Overview, Members, Sites, Billing, SSO, and Audit.
+ """
+ use PlausibleWeb.CustomerSupport.Live
+
+ alias PlausibleWeb.CustomerSupport.Team.Components.{
+ Overview,
+ Members,
+ Sites,
+ Billing,
+ SSO,
+ Audit
+ }
+
+ require Plausible.Billing.Subscription.Status
+
+ def handle_params(%{"id" => id} = params, _uri, socket) do
+ tab = params["tab"] || "overview"
+ team_id = String.to_integer(id)
+ team = Resource.Team.get(team_id)
+
+ if team do
+ socket =
+ socket
+ |> assign(:team, team)
+ |> assign(:tab, tab)
+
+ {:noreply, go_to_tab(socket, tab, params, :team, tab_component(tab))}
+ else
+ {:noreply, redirect(socket, to: Routes.customer_support_path(socket, :index))}
+ end
+ end
+
+ def handle_event("unlock", _, socket) do
+ {:noreply, unlock_team(socket)}
+ end
+
+ def handle_event("lock", _, socket) do
+ {:noreply, lock_team(socket)}
+ end
+
+ def handle_event("refund-lock", _, socket) do
+ team = socket.assigns.team
+
+ {:ok, team} =
+ Plausible.Repo.transaction(fn ->
+ yesterday = Date.shift(Date.utc_today(), day: -1)
+ Plausible.Billing.SiteLocker.set_lock_status_for(team, true)
+
+ Plausible.Repo.update!(
+ Plausible.Billing.Subscription.changeset(team.subscription, %{next_bill_date: yesterday})
+ )
+
+ Resource.Team.get(team.id)
+ end)
+
+ {:noreply, assign(socket, team: team)}
+ end
+
+ def render(assigns) do
+ ~H"""
+ <Layout.layout show_search={false} flash={@flash}>
+ <.team_header team={@team} />
+ <.team_tab_navigation team={@team} tab={@tab} />
+ <.team_stats team={@team} />
+
+ <.live_component
+ module={tab_component(@tab)}
+ team={@team}
+ tab={@tab}
+ id={"team-#{@team.id}-#{@tab}"}
+ />
+ </Layout.layout>
+ """
+ end
+
+ defp team_header(assigns) do
+ ~H"""
+ <div>
+ <div class="sm:flex sm:items-center sm:justify-between">
+ <div class="sm:flex sm:space-x-5">
+ <div class="shrink-0">
+ <div class={[
+ team_bg(@team.identifier),
+ "rounded-full p-1 flex items-center justify-center"
+ ]}>
+ <Heroicons.user_group class="h-14 w-14 text-white dark:text-gray-300" />
+ </div>
+ </div>
+ <div class="mt-4 text-center sm:mt-0 sm:pt-1 sm:text-left">
+ <p class="text-xl font-bold dark:text-gray-300 text-gray-900 sm:text-2xl">
+ {@team.name}
+ </p>
+ <p class="text-sm font-medium dark:text-gray-500">
+ <span :if={@team.setup_complete}>Set up at {@team.setup_at}</span>
+ <span :if={[email protected]_complete}>Not set up yet</span>
+ </p>
+ </div>
+ </div>
+
+ <div class="mt-5 flex justify-center sm:mt-0">
+ <.input_with_clipboard
+ id="team-identifier"
+ name="team-identifier"
+ label="Team Identifier"
+ value={@team.identifier}
+ onfocus="this.value = this.value;"
+ />
+ </div>
+ </div>
+ </div>
+ """
+ end
+
+ defp team_tab_navigation(assigns) do
+ ~H"""
+ <.tab_navigation tab={@tab}>
+ <:tabs>
+ <.tab to="overview" tab={@tab}>Overview</.tab>
+ <.tab to="members" tab={@tab}>Members</.tab>
+ <.tab to="sites" tab={@tab}>Sites</.tab>
+ <.tab :if={has_sso_integration?(@team)} to="sso" tab={@tab}>SSO</.tab>
+ <.tab to="billing" tab={@tab}>Billing</.tab>
+ <.tab to="audit" tab={@tab}>Audit</.tab>
+ </:tabs>
+ </.tab_navigation>
+ """
+ end
+
+ defp team_stats(assigns) do
+ team = assigns.team
+ usage = Plausible.Teams.Billing.quota_usage(team, with_features: true)
+
+ limits = %{
+ monthly_pageviews: Plausible.Teams.Billing.monthly_pageview_limit(team),
+ sites: Plausible.Teams.Billing.site_limit(team),
+ team_members: Plausible.Teams.Billing.team_member_limit(team)
+ }
+
+ assigns = assign(assigns, usage: usage, limits: limits)
+
+ ~H"""
+ <div class="grid grid-cols-1 divide-y border-t sm:grid-cols-3 sm:divide-x sm:divide-y-0 dark:bg-gray-850 text-gray-900 dark:text-gray-400 dark:divide-gray-800 dark:border-gray-600">
+ <div class="px-6 py-5 text-center text-sm font-medium">
+ <span>
+ <strong>Subscription status</strong> <br />{subscription_status(@team)}
+ <div :if={
+ @team.subscription &&
+ @team.subscription.status == Plausible.Billing.Subscription.Status.deleted() &&
+ }>
+ <span class="flex items-center gap-x-8 justify-center mt-1">
+ <div :if={not Plausible.Teams.locked?(@team)}>
+ <Heroicons.lock_open solid class="inline stroke-2 w-4 h-4 text-red-400 mr-1" />
+ <.styled_link
+ phx-click="refund-lock"
+ data-confirm="Are you sure you want to lock? The only way to unlock, is for the user to resubscribe."
+ >
+ Refund Lock
+ </.styled_link>
+ </div>
+
+ <div :if={Plausible.Teams.locked?(@team)}>
+ <Heroicons.lock_closed solid class="inline stroke-2 w-4 h-4 text-red-400 mr-1" />
+ Locked
+ </div>
+ </span>
+ </div>
+ </span>
+ </div>
+ <div class="px-6 py-5 text-center text-sm font-medium">
+ <span>
+ <strong>Subscription plan</strong> <br />{subscription_plan(@team)}
+ </span>
+ </div>
+ <div class="px-6 py-5 text-center text-sm font-medium">
+ <span>
+ <strong>Grace Period</strong> <br />{grace_period_status(@team)}
+
+ <div :if={@team.grace_period}>
+ <span class="flex items-center gap-x-8 justify-center mt-1">
+ <div>
+ <Heroicons.lock_open solid class="inline stroke-2 w-4 h-4 text-red-400 mr-1" />
+ <.styled_link phx-click="unlock">Unlock</.styled_link>
+ </div>
+
+ <div>
+ <Heroicons.lock_closed solid class="inline stroke-2 w-4 h-4 text-red-400 mr-1" />
+ <.styled_link phx-click="lock">Lock</.styled_link>
+ </div>
+ </span>
+ </div>
+ </span>
+ </div>
+ </div>
+ """
+ end
+
+ defp tab_component("overview"), do: Overview
+ defp tab_component("members"), do: Members
+ defp tab_component("sites"), do: Sites
+ defp tab_component("billing"), do: Billing
+ defp tab_component("sso"), do: SSO
+ defp tab_component("audit"), do: Audit
+ defp tab_component(_), do: Overview
+
+ defp has_sso_integration?(team) do
+ case Plausible.Auth.SSO.get_integration_for(team) do
+ {:ok, _} -> true
+ {:error, :not_found} -> false
+ end
+ end
+
+ defp team_bg(term) do
+ list = [
+ "bg-blue-500",
+ "bg-blue-600",
+ "bg-blue-700",
+ "bg-blue-800",
+ "bg-cyan-500",
+ "bg-cyan-600",
+ "bg-cyan-700",
+ "bg-cyan-800",
+ "bg-red-500",
+ "bg-red-600",
+ "bg-red-700",
+ "bg-red-800",
+ "bg-green-500",
+ "bg-green-600",
+ "bg-green-700",
+ "bg-green-800",
+ "bg-yellow-500",
+ "bg-yellow-600",
+ "bg-yellow-700",
+ "bg-yellow-800",
+ "bg-orange-500",
+ "bg-orange-600",
+ "bg-orange-700",
+ "bg-orange-800",
+ "bg-purple-500",
+ "bg-purple-600",
+ "bg-purple-700",
+ "bg-purple-800",
+ "bg-gray-500",
+ "bg-gray-600",
+ "bg-gray-700",
+ "bg-gray-800",
+ "bg-emerald-500",
+ "bg-emerald-600",
+ "bg-emerald-700",
+ "bg-emerald-800"
+ ]
+
+ idx = :erlang.phash2(term, length(list))
+ Enum.at(list, idx)
+ end
+
+ defp subscription_status(team) do
+ cond do
+ team && team.subscription ->
+ status_str =
+ PlausibleWeb.SettingsView.present_subscription_status(team.subscription.status)
+
+ if team.subscription.paddle_subscription_id do
+ assigns = %{status_str: status_str, subscription: team.subscription}
+
+ ~H"""
+ <.styled_link new_tab={true} href={manage_url(@subscription)}>{@status_str}</.styled_link>
+ """
+ else
+ status_str
+ end
+
+ Plausible.Teams.on_trial?(team) ->
+ "On trial"
+
+ true ->
+ "Trial expired"
+ end
+ end
+
+ defp manage_url(%{paddle_subscription_id: paddle_id} = _subscription) do
+ Plausible.Billing.PaddleApi.vendors_domain() <>
+ "/subscriptions/customers/manage/" <> paddle_id
+ end
+
+ defp subscription_plan(team) do
+ subscription = team.subscription
+
+ if Plausible.Billing.Subscription.Status.active?(subscription) &&
+ subscription.paddle_subscription_id do
+ quota = PlausibleWeb.AuthView.subscription_quota(subscription)
+ interval = PlausibleWeb.AuthView.subscription_interval(subscription)
+
+ assigns = %{quota: quota, interval: interval, subscription: subscription}
+
+ ~H"""
+ <.styled_link new_tab={true} href={manage_url(@subscription)}>
+ {@quota} ({@interval})
+ </.styled_link>
+ """
+ else
+ "--"
+ end
+ end
+
+ defp grace_period_status(team) do
+ grace_period = team.grace_period
+
+ case grace_period do
+ nil ->
+ "--"
+
+ %{manual_lock: true, is_over: true} ->
+ "Manually locked"
+
+ %{manual_lock: true, is_over: false} ->
+ "Waiting for manual lock"
+
+ %{is_over: true} ->
+ "ended"
+
+ %{end_date: %Date{} = end_date} ->
+ days_left = Date.diff(end_date, Date.utc_today())
+ "#{days_left} days left"
+ end
+ end
+
+ defp lock_team(socket) do
+ if socket.assigns.team.grace_period do
+ team = Plausible.Teams.end_grace_period(socket.assigns.team)
+ Plausible.Billing.SiteLocker.set_lock_status_for(team, true)
+
+ put_live_flash(socket, :success, "Team locked. Grace period ended.")
+ assign(socket, team: team)
+ else
+ put_live_flash(socket, :error, "No grace period")
+ socket
+ end
+ end
+
+ defp unlock_team(socket) do
+ if socket.assigns.team.grace_period do
+ team = Plausible.Teams.remove_grace_period(socket.assigns.team)
+ Plausible.Billing.SiteLocker.set_lock_status_for(team, false)
+
+ put_live_flash(socket, :success, "Team unlocked. Grace period removed.")
+ assign(socket, team: team)
+ else
+ socket
+ end
+ end
+end
diff --git a/extra/lib/plausible_web/live/customer_support/team/components/audit.ex b/extra/lib/plausible_web/live/customer_support/team/components/audit.ex
new file mode 100644
index 0000000000..a2cf198255
--- /dev/null
+++ b/extra/lib/plausible_web/live/customer_support/team/components/audit.ex
@@ -0,0 +1,246 @@
+defmodule PlausibleWeb.CustomerSupport.Team.Components.Audit do
+ @moduledoc """
+ Team audit component - handles audit log viewing
+ """
+ use PlausibleWeb, :live_component
+
+ def update(%{team: team, tab_params: tab_params}, socket) do
+ pagination_params = get_pagination_params(tab_params)
+ audit_page = Plausible.Audit.list_entries_paginated([team_id: team.id], pagination_params)
+
+ entries = process_audit_entries(audit_page.entries)
+ audit_page = %{audit_page | entries: entries}
+ current_limit = pagination_params["limit"]
+
+ {:ok,
+ assign(socket,
+ team: team,
+ audit_page: audit_page,
+ revealed_audit_entry_id: nil,
+ current_limit: current_limit
+ )}
+ end
+
+ def update(%{team: team}, socket) do
+ update(%{team: team, tab_params: %{}}, socket)
+ end
+
+ def render(assigns) do
+ ~H"""
+ <div class="mt-4 mb-4 text-gray-900 dark:text-gray-400 relative">
+ <div :if={Enum.empty?(@audit_page.entries)} class="flex justify-center items-center">
+ No audit logs yet
+ </div>
+
+ <div
+ :if={@revealed_audit_entry_id}
+ phx-target={@myself}
+ phx-window-keydown="reveal-audit-entry"
+ phx-key="escape"
+ >
+ <.input_with_clipboard
+ id="audit-entry-identifier"
+ name="audit-entry-identifier"
+ label="Audit Entry Identifier"
+ value={@revealed_audit_entry_id}
+ />
+ <div class="relative">
+ <.input
+ rows="16"
+ type="textarea"
+ id="audit-entry-change"
+ name="audit-entry-change"
+ value={
+ Jason.encode!(
+ Enum.find(@audit_page.entries, &(&1.id == @revealed_audit_entry_id)).change,
+ pretty: true
+ )
+ }
+ >
+ </.input>
+ <.styled_link
+ class="text-sm float-right"
+ onclick="var textarea = document.getElementById('audit-entry-change'); textarea.focus(); textarea.select(); document.execCommand('copy');"
+ href="#"
+ >
+ <div class="flex items-center absolute top-4 right-4 text-xs gap-x-1">
+ <Heroicons.document_duplicate class="h-4 w-4 text-indigo-700" /> COPY
+ </div>
+ </.styled_link>
+
+ <.styled_link
+ phx-click="reveal-audit-entry"
+ phx-target={@myself}
+ class="float-right pt-4 text-sm"
+ >
+ &larr; Return
+ <kbd class="rounded border border-gray-200 dark:border-gray-600 px-2 font-mono font-normal text-xs text-gray-400">
+ ESC
+ </kbd>
+ </.styled_link>
+ </div>
+ </div>
+
+ <.table :if={is_nil(@revealed_audit_entry_id)} rows={@audit_page.entries}>
+ <:thead>
+ <.th invisible></.th>
+ <.th invisible></.th>
+ <.th>Name</.th>
+ <.th>Entity</.th>
+ <.th>Actor</.th>
+ <.th invisible>Actions</.th>
+ </:thead>
+ <:tbody :let={entry}>
+ <.td>{Calendar.strftime(entry.datetime, "%Y-%m-%d")}</.td>
+ <.td>{Calendar.strftime(entry.datetime, "%H:%M:%S")}</.td>
+ <.td class="font-mono">{entry.name}</.td>
+ <.td truncate>
+ <.audit_entity entry={entry} />
+ </.td>
+ <.td :if={entry.actor_type == :system}>
+ <div class="flex items-center gap-x-1">
+ <Heroicons.cog_6_tooth class="size-4" /> SYSTEM
+ </div>
+ </.td>
+ <.td :if={entry.actor_type == :user} truncate>
+ <.audit_user user={entry.meta.user} />
+ </.td>
+
+ <.td actions>
+ <.edit_button
+ phx-click="reveal-audit-entry"
+ icon={:magnifying_glass_plus}
+ phx-value-id={entry.id}
+ phx-target={@myself}
+ />
+ </.td>
+ </:tbody>
+ </.table>
+
+ <div
+ :if={
+ is_nil(@revealed_audit_entry_id) &&
+ (@audit_page.metadata.before || @audit_page.metadata.after)
+ }
+ class="flex justify-between items-center mt-4"
+ >
+ <.button
+ :if={@audit_page.metadata.before}
+ id="prev-page"
+ phx-click="paginate-audit"
+ phx-value-before={@audit_page.metadata.before}
+ phx-value-limit={@current_limit}
+ phx-target={@myself}
+ theme="bright"
+ >
+ &larr; Prev
+ </.button>
+ <div></div>
+ <.button
+ :if={@audit_page.metadata.after}
+ id="next-page"
+ phx-click="paginate-audit"
+ phx-value-after={@audit_page.metadata.after}
+ phx-value-limit={@current_limit}
+ phx-target={@myself}
+ theme="bright"
+ >
+ Next &rarr;
+ </.button>
+ </div>
+ </div>
+ """
+ end
+
+ def handle_event("reveal-audit-entry", %{"id" => id}, socket) do
+ {:noreply, assign(socket, revealed_audit_entry_id: id)}
+ end
+
+ def handle_event("reveal-audit-entry", _, socket) do
+ {:noreply, assign(socket, revealed_audit_entry_id: nil)}
+ end
+
+ def handle_event("paginate-audit", params, socket) do
+ pagination_params = get_pagination_params(params)
+ team = socket.assigns.team
+
+ query_params = %{"tab" => "audit"} |> Map.merge(pagination_params)
+
+ {:noreply,
+ push_patch(socket,
+ to: Routes.customer_support_team_path(PlausibleWeb.Endpoint, :show, team.id, query_params)
+ )}
+ end
+
+ defp process_audit_entries(entries) do
+ Enum.map(entries, fn entry ->
+ meta = entry.meta
+
+ meta =
+ if entry.user_id && entry.user_id > 0 do
+ user = Plausible.Repo.get(Plausible.Auth.User, entry.user_id)
+ Map.put(meta, :user, user)
+ else
+ meta
+ end
+
+ meta =
+ if entry.entity == "Plausible.Auth.User" do
+ user = Plausible.Repo.get(Plausible.Auth.User, String.to_integer(entry.entity_id))
+ Map.put(meta, :entity, user)
+ else
+ meta
+ end
+
+ Map.put(entry, :meta, meta)
+ end)
+ end
+
+ attr :entry, Plausible.Audit.Entry
+
+ defp audit_entity(assigns) do
+ ~H"""
+ <%= if @entry.entity == "Plausible.Auth.User" do %>
+ <.audit_user user={@entry.meta.entity} />
+ <% else %>
+ {@entry.entity |> String.split(".") |> List.last()} #{String.slice(@entry.entity_id, 0, 8)}
+ <% end %>
+ """
+ end
+
+ attr :user, Plausible.Auth.User
+
+ defp audit_user(%{user: nil} = assigns) do
+ ~H"""
+ (N/A)
+ """
+ end
+
+ defp audit_user(assigns) do
+ ~H"""
+ <div class="flex items-center gap-x-1">
+ <img
+ class="w-4"
+ src={
+ Plausible.Auth.User.profile_img_url(%Plausible.Auth.User{
+ email: @user.email
+ })
+ }
+ />
+
+ <.styled_link
+ patch={Routes.customer_support_user_path(PlausibleWeb.Endpoint, :show, @user.id)}
+ class="cursor-pointer flex block items-center"
+ >
+ {@user.name}
+ </.styled_link>
+ </div>
+ """
+ end
+
+ defp get_pagination_params(params) do
+ params
+ |> Map.take(["after", "before", "limit"])
+ |> Map.put_new("limit", 15)
+ end
+end
diff --git a/extra/lib/plausible_web/live/customer_support/team/components/billing.ex b/extra/lib/plausible_web/live/customer_support/team/components/billing.ex
new file mode 100644
index 0000000000..6a347ab9b2
--- /dev/null
+++ b/extra/lib/plausible_web/live/customer_support/team/components/billing.ex
@@ -0,0 +1,428 @@
+defmodule PlausibleWeb.CustomerSupport.Team.Components.Billing do
+ @moduledoc """
+ Team billing component - handles subscription and custom plans
+ """
+ use PlausibleWeb, :live_component
+ import PlausibleWeb.CustomerSupport.Live
+
+ alias Plausible.Billing.EnterprisePlan
+ alias Plausible.Billing.Plans
+ alias Plausible.Teams
+ import Ecto.Query, only: [from: 2]
+ import PlausibleWeb.Components.Generic
+
+ require Plausible.Billing.Subscription.Status
+
+ def update(%{team: team}, socket) do
+ usage = Teams.Billing.quota_usage(team, with_features: true)
+
+ limits = %{
+ monthly_pageviews: Teams.Billing.monthly_pageview_limit(team),
+ sites: Teams.Billing.site_limit(team),
+ team_members: Teams.Billing.team_member_limit(team)
+ }
+
+ plans = get_plans(team.id)
+ plan = Plans.get_subscription_plan(team.subscription)
+
+ attrs = get_plan_attrs(plan)
+ plan_form = to_form(EnterprisePlan.changeset(%EnterprisePlan{}, attrs))
+
+ {:ok,
+ assign(socket,
+ team: team,
+ usage: usage,
+ limits: limits,
+ plan: plan,
+ plans: plans,
+ plan_form: plan_form,
+ show_plan_form?: false,
+ editing_plan: nil,
+ cost_estimate: 0
+ )}
+ end
+
+ def render(assigns) do
+ ~H"""
+ <div>
+ <script type="text/javascript">
+ const featureChangeCallback = function(e) {
+ const value = e.target.value
+ const checked = e.target.checked
+ const form = e.target.closest('form')
+
+ if (value === 'sites_api' && checked) {
+ form.querySelector('input[value=stats_api]').checked = true
+ } else if (value === 'stats_api' && !checked) {
+ form.querySelector('input[value=sites_api]').checked = false
+ }
+ }
+ </script>
+ <div class="mt-4 mb-4 text-gray-900 dark:text-gray-400">
+ <h1 class="text-xs font-semibold">Usage</h1>
+ <.table rows={monthly_pageviews_usage(@usage.monthly_pageviews, @limits.monthly_pageviews)}>
+ <:thead>
+ <.th invisible>Cycle</.th>
+ <.th invisible>Dates</.th>
+ <.th>Total</.th>
+ <.th>Limit</.th>
+ </:thead>
+ <:tbody :let={{cycle, date, total, limit}}>
+ <.td>{cycle}</.td>
+ <.td>{date}</.td>
+ <.td>
+ <span class={if total > limit, do: "text-red-600"}>{number_format(total)}</span>
+ </.td>
+ <.td>{number_format(limit)}</.td>
+ </:tbody>
+ </.table>
+
+ <p :if={@usage.features != []} class="mt-6 mb-4">
+ <h1 class="text-xs font-semibold">Features Used</h1>
+ <span class="text-sm">
+ {@usage.features |> Enum.map(& &1.display_name()) |> Enum.join(", ")}
+ </span>
+ </p>
+
+ <h1 :if={!@show_plan_form? and @plans != []} class="mt-8 text-xs font-semibold">
+ Custom Plans
+ </h1>
+ <.table :if={!@show_plan_form?} rows={@plans}>
+ <:thead>
+ <.th invisible>Interval</.th>
+ <.th>Paddle Plan ID</.th>
+ <.th>Limits</.th>
+ <.th>Features</.th>
+ <.th invisible>Actions</.th>
+ </:thead>
+ <:tbody :let={plan}>
+ <.td class="align-top">
+ {plan.billing_interval}
+ </.td>
+ <.td class="align-top">
+ {plan.paddle_plan_id}
+
+ <span
+ :if={(@team.subscription && @team.subscription.paddle_plan_id) == plan.paddle_plan_id}
+ class="inline-flex items-center px-2 py-0.5 rounded text-xs font-xs bg-red-100 text-red-800"
+ >
+ CURRENT
+ </span>
+ </.td>
+ <.td max_width="max-w-40">
+ <.table rows={[
+ {"Pageviews", number_format(plan.monthly_pageview_limit)},
+ {"Sites", number_format(plan.site_limit)},
+ {"Members", number_format(plan.team_member_limit)},
+ {"API Requests", number_format(plan.hourly_api_request_limit)}
+ ]}>
+ <:tbody :let={{label, value}}>
+ <.td>{label}</.td>
+ <.td>{value}</.td>
+ </:tbody>
+ </.table>
+ </.td>
+ <.td class="align-top">
+ <span :for={feat <- plan.features}>{feat.display_name()}<br /></span>
+ </.td>
+ <.td class="align-top">
+ <.edit_button phx-click="edit-plan" phx-value-id={plan.id} phx-target={@myself} />
+ </.td>
+ </:tbody>
+ </.table>
+
+ <.form
+ :let={f}
+ :if={@show_plan_form?}
+ for={@plan_form}
+ id="save-plan"
+ phx-submit={if @editing_plan, do: "update-plan", else: "save-plan"}
+ phx-target={@myself}
+ phx-change="estimate-cost"
+ >
+ <.input field={f[:paddle_plan_id]} label="Paddle Plan ID" autocomplete="off" />
+ <.input
+ type="select"
+ options={["monthly", "yearly"]}
+ field={f[:billing_interval]}
+ label="Billing Interval"
+ autocomplete="off"
+ />
+
+ <div class="flex items-center gap-x-4">
+ <.input
+ field={f[:monthly_pageview_limit]}
+ label="Monthly Pageview Limit"
+ autocomplete="off"
+ width="w-[500]"
+ />
+ <.preview for={f[:monthly_pageview_limit]} />
+ </div>
+
+ <div class="flex items-center gap-x-4">
+ <.input width="w-[500]" field={f[:site_limit]} label="Site Limit" autocomplete="off" />
+ <.preview for={f[:site_limit]} />
+ </div>
+
+ <div class="flex items-center gap-x-4">
+ <.input
+ field={f[:team_member_limit]}
+ label="Team Member Limit"
+ autocomplete="off"
+ width="w-[500]"
+ />
+ <.preview for={f[:team_member_limit]} />
+ </div>
+
+ <div class="flex items-center gap-x-4">
+ <.input
+ field={f[:hourly_api_request_limit]}
+ label="Hourly API Request Limit"
+ autocomplete="off"
+ width="w-[500]"
+ />
+ <.preview for={f[:hourly_api_request_limit]} />
+ </div>
+
+ <.input
+ :for={
+ mod <-
+ Plausible.Billing.Feature.list()
+ |> Enum.sort_by(fn item -> if item.name() == :stats_api, do: 0, else: 1 end)
+ }
+ :if={not mod.free?()}
+ x-on:change="featureChangeCallback(event)"
+ type="checkbox"
+ value={mod in (f.source.changes[:features] || f.source.data.features || [])}
+ name={"#{f.name}[features[]][#{mod.name()}]"}
+ label={mod.display_name()}
+ />
+
+ <div class="mt-8 flex align-center gap-x-4">
+ <.input_with_clipboard
+ id="cost-estimate"
+ name="cost-estimate"
+ label={"#{(f[:billing_interval].value || "monthly")} cost estimate"}
+ value={@cost_estimate}
+ />
+
+ <.button theme="bright" phx-click="hide-plan-form" phx-target={@myself}>
+ Cancel
+ </.button>
+
+ <.button type="submit">
+ {if @editing_plan, do: "Update Plan", else: "Save Custom Plan"}
+ </.button>
+ </div>
+ </.form>
+
+ <.button
+ :if={!@show_plan_form?}
+ id="new-custom-plan"
+ phx-click="show-plan-form"
+ phx-target={@myself}
+ >
+ New Custom Plan
+ </.button>
+ </div>
+ </div>
+ """
+ end
+
+ # Event handlers
+ def handle_event("show-plan-form", _, socket) do
+ {:noreply, assign(socket, show_plan_form?: true, editing_plan: nil)}
+ end
+
+ def handle_event("edit-plan", %{"id" => plan_id}, socket) do
+ {plan_id, _} = Integer.parse(plan_id)
+ plan = Enum.find(socket.assigns.plans, &(&1.id == plan_id))
+
+ if plan do
+ plan_form = to_form(EnterprisePlan.changeset(plan, %{}))
+ {:noreply, assign(socket, show_plan_form?: true, editing_plan: plan, plan_form: plan_form)}
+ else
+ {:noreply, socket}
+ end
+ end
+
+ def handle_event("hide-plan-form", _, socket) do
+ {:noreply, assign(socket, show_plan_form?: false, editing_plan: nil)}
+ end
+
+ def handle_event("estimate-cost", %{"enterprise_plan" => params}, socket) do
+ params = update_features_to_list(params)
+
+ form = to_form(EnterprisePlan.changeset(%EnterprisePlan{}, params))
+ params = sanitize_params(params)
+
+ cost_estimate =
+ Plausible.CustomerSupport.EnterprisePlan.estimate(
+ params["billing_interval"],
+ get_int_param(params, "monthly_pageview_limit"),
+ get_int_param(params, "site_limit"),
+ get_int_param(params, "team_member_limit"),
+ get_int_param(params, "hourly_api_request_limit"),
+ params["features"]
+ )
+
+ {:noreply, assign(socket, cost_estimate: cost_estimate, plan_form: form)}
+ end
+
+ def handle_event("save-plan", %{"enterprise_plan" => params}, socket) do
+ params = params |> update_features_to_list() |> sanitize_params()
+ changeset = EnterprisePlan.changeset(%EnterprisePlan{team_id: socket.assigns.team.id}, params)
+
+ case Plausible.Repo.insert(changeset) do
+ {:ok, _plan} ->
+ success("Plan saved")
+ plans = get_plans(socket.assigns.team.id)
+
+ {:noreply,
+ assign(socket,
+ plans: plans,
+ plan_form: to_form(changeset),
+ show_plan_form?: false,
+ editing_plan: nil
+ )}
+
+ {:error, changeset} ->
+ failure("Error saving plan: #{inspect(changeset.errors)}")
+ {:noreply, assign(socket, plan_form: to_form(changeset))}
+ end
+ end
+
+ def handle_event("update-plan", %{"enterprise_plan" => params}, socket) do
+ params = params |> update_features_to_list() |> sanitize_params()
+ changeset = EnterprisePlan.changeset(socket.assigns.editing_plan, params)
+
+ case Plausible.Repo.update(changeset) do
+ {:ok, _plan} ->
+ success("Plan updated")
+ plans = get_plans(socket.assigns.team.id)
+
+ {:noreply,
+ assign(socket,
+ plans: plans,
+ plan_form: to_form(changeset),
+ show_plan_form?: false,
+ editing_plan: nil
+ )}
+
+ {:error, changeset} ->
+ failure("Error updating plan: #{inspect(changeset.errors)}")
+ {:noreply, assign(socket, plan_form: to_form(changeset))}
+ end
+ end
+
+ # Helper functions
+ defp get_plan_attrs(plan) when is_map(plan) do
+ Map.take(plan, [
+ :billing_interval,
+ :monthly_pageview_limit,
+ :site_limit,
+ :team_member_limit,
+ :hourly_api_request_limit,
+ :features
+ ])
+ |> Map.update(:features, [], fn features ->
+ Enum.map(features, &to_string(&1.name()))
+ end)
+ end
+
+ defp get_plan_attrs(_) do
+ %{
+ monthly_pageview_limit: 10_000,
+ hourly_api_request_limit: 600,
+ site_limit: 10,
+ team_member_limit: 10,
+ features: Plausible.Billing.Feature.list() -- [Plausible.Billing.Feature.SSO]
+ }
+ end
+
+ defp monthly_pageviews_usage(usage, limit) do
+ usage
+ |> Enum.sort_by(fn {_cycle, usage} -> usage.date_range.first end, :desc)
+ |> Enum.map(fn {cycle, usage} ->
+ {cycle, PlausibleWeb.TextHelpers.format_date_range(usage.date_range), usage.total, limit}
+ end)
+ end
+
+ defp get_plans(team_id) do
+ Plausible.Repo.all(
+ from ep in EnterprisePlan,
+ where: ep.team_id == ^team_id,
+ order_by: [desc: :id]
+ )
+ end
+
+ defp number_format(unlimited) when unlimited in [-1, "unlimited", :unlimited] do
+ "unlimited"
+ end
+
+ defp number_format(number) when is_integer(number) do
+ Cldr.Number.to_string!(number)
+ end
+
+ defp number_format(other), do: other
+
+ defp sanitize_params(params) do
+ params
+ |> Enum.map(&clear_param/1)
+ |> Enum.reject(&(&1 == ""))
+ |> Map.new()
+ end
+
+ defp clear_param({key, value}) when is_binary(value) do
+ {key, String.trim(value)}
+ end
+
+ defp clear_param(other) do
+ other
+ end
+
+ defp get_int_param(params, key) do
+ param = Map.get(params, key)
+ param = if param in ["", nil], do: "0", else: param
+
+ case Integer.parse(param) do
+ {integer, ""} -> integer
+ _ -> 0
+ end
+ end
+
+ defp update_features_to_list(params) do
+ features =
+ params["features[]"]
+ |> Enum.reject(fn {_key, value} -> value == "false" or value == "" end)
+ |> Enum.map(fn {key, _value} -> key end)
+
+ Map.put(params, "features", features)
+ end
+
+ defp preview_number(n) do
+ case Integer.parse("#{n}") do
+ {n, ""} ->
+ number_format(n) <> " (#{PlausibleWeb.StatsView.large_number_format(n)})"
+
+ _ ->
+ "0"
+ end
+ end
+
+ attr :for, :any, required: true
+
+ defp preview(assigns) do
+ ~H"""
+ <.input
+ name={"#{@for.name}-preview"}
+ label="Preview"
+ autocomplete="off"
+ width="w-[500]"
+ readonly
+ value={preview_number(@for.value)}
+ class="bg-transparent border-0 p-0 m-0 text-sm w-full"
+ />
+ """
+ end
+end
diff --git a/extra/lib/plausible_web/live/customer_support/team/components/members.ex b/extra/lib/plausible_web/live/customer_support/team/components/members.ex
new file mode 100644
index 0000000000..4597156802
--- /dev/null
+++ b/extra/lib/plausible_web/live/customer_support/team/components/members.ex
@@ -0,0 +1,94 @@
+defmodule PlausibleWeb.CustomerSupport.Team.Components.Members do
+ @moduledoc """
+ Team members component - handles team member management
+ """
+ use PlausibleWeb, :live_component
+ import PlausibleWeb.CustomerSupport.Live
+ alias Plausible.Teams
+
+ def update(%{team: team}, socket) do
+ {:ok, refresh_members(socket, team)}
+ end
+
+ def render(assigns) do
+ ~H"""
+ <div class="mt-2">
+ <.table rows={Teams.Management.Layout.sorted_for_display(@team_layout)}>
+ <:thead>
+ <.th>User</.th>
+ <.th>Sessions</.th>
+ <.th>Type</.th>
+ <.th>Role</.th>
+ </:thead>
+ <:tbody :let={{_, member}}>
+ <.td truncate>
+ <div :if={member.id != 0}>
+ <.styled_link
+ patch={Routes.customer_support_user_path(PlausibleWeb.Endpoint, :show, member.id)}
+ class="cursor-pointer flex block items-center"
+ >
+ <img
+ src={Plausible.Auth.User.profile_img_url(%Plausible.Auth.User{email: member.email})}
+ class="mr-4 w-6 rounded-full bg-gray-300"
+ />
+ {member.name} &lt;{member.email}&gt;
+ </.styled_link>
+ </div>
+ <div :if={member.id == 0} class="flex items-center">
+ <img
+ src={Plausible.Auth.User.profile_img_url(%Plausible.Auth.User{email: member.email})}
+ class="mr-4 w-6 rounded-full bg-gray-300"
+ />
+ {member.name} &lt;{member.email}&gt;
+ </div>
+ </.td>
+ <.td>
+ {if member.type == :membership, do: @session_counts[member.meta.user.id] || 0, else: 0}
+ </.td>
+ <.td>
+ <div class="flex items-center gap-x-1">
+ <span :if={member.type == :membership && member.meta.user.type == :sso}>SSO </span>{member.type}
+
+ <.delete_button
+ :if={member.type == :membership && member.meta.user.type == :sso}
+ id={"deprovision-sso-user-#{member.id}"}
+ phx-click="deprovision-sso-user"
+ phx-value-identifier={member.id}
+ phx-target={@myself}
+ class="text-sm"
+ icon={:user_minus}
+ data-confirm="Are you sure you want to deprovision SSO user and convert them to a standard user? This will sign them out and force to use regular e-mail/password combination to log in again."
+ />
+ </div>
+ </.td>
+ <.td>
+ {member.role}
+ </.td>
+ </:tbody>
+ </.table>
+ </div>
+ """
+ end
+
+ def handle_event("deprovision-sso-user", %{"identifier" => user_id}, socket) do
+ [id: String.to_integer(user_id)]
+ |> Plausible.Auth.find_user_by()
+ |> Plausible.Auth.SSO.deprovision_user!()
+
+ success("SSO user deprovisioned")
+ {:noreply, refresh_members(socket, socket.assigns.team)}
+ end
+
+ defp refresh_members(socket, team) do
+ team_layout = Teams.Management.Layout.init(team)
+
+ session_counts =
+ team_layout
+ |> Enum.map(fn {_, entry} -> if entry.type == :membership, do: entry.meta.user end)
+ |> Enum.reject(&is_nil/1)
+ |> Plausible.Auth.UserSessions.count_for_users()
+ |> Enum.into(%{})
+
+ assign(socket, team: team, team_layout: team_layout, session_counts: session_counts)
+ end
+end
diff --git a/extra/lib/plausible_web/live/customer_support/team/components/overview.ex b/extra/lib/plausible_web/live/customer_support/team/components/overview.ex
new file mode 100644
index 0000000000..3fd1866cec
--- /dev/null
+++ b/extra/lib/plausible_web/live/customer_support/team/components/overview.ex
@@ -0,0 +1,74 @@
+defmodule PlausibleWeb.CustomerSupport.Team.Components.Overview do
+ @moduledoc """
+ Team overview component - handles team basic info, trial dates, notes
+ """
+ use PlausibleWeb, :live_component
+ import PlausibleWeb.CustomerSupport.Live
+
+ def update(%{team: team}, socket) do
+ changeset = Plausible.Teams.Team.crm_changeset(team, %{})
+ form = to_form(changeset)
+
+ {:ok, assign(socket, team: team, form: form)}
+ end
+
+ def render(assigns) do
+ ~H"""
+ <div class="mt-8">
+ <.form :let={f} for={@form} phx-submit="save-team" phx-target={@myself}>
+ <.input field={f[:trial_expiry_date]} type="date" label="Trial Expiry Date" />
+ <.input field={f[:accept_traffic_until]} type="date" label="Accept traffic Until" />
+ <.input
+ type="checkbox"
+ field={f[:allow_next_upgrade_override]}
+ label="Allow Next Upgrade Override"
+ />
+
+ <.input type="textarea" field={f[:notes]} label="Notes" />
+
+ <div class="flex justify-between">
+ <.button type="submit">
+ Save
+ </.button>
+
+ <.button
+ phx-target={@myself}
+ phx-click="delete-team"
+ data-confirm="Are you sure you want to delete this team?"
+ theme="danger"
+ >
+ Delete Team
+ </.button>
+ </div>
+ </.form>
+ </div>
+ """
+ end
+
+ def handle_event("save-team", %{"team" => params}, socket) do
+ changeset = Plausible.Teams.Team.crm_changeset(socket.assigns.team, params)
+
+ case Plausible.Repo.update(changeset) do
+ {:ok, team} ->
+ success("Team saved")
+ {:noreply, assign(socket, team: team, form: to_form(changeset))}
+
+ {:error, changeset} ->
+ failure("Error saving team: #{inspect(changeset.errors)}")
+ {:noreply, assign(socket, form: to_form(changeset))}
+ end
+ end
+
+ def handle_event("delete-team", _params, socket) do
+ case Plausible.Teams.delete(socket.assigns.team) do
+ {:ok, :deleted} ->
+ navigate_with_success(Routes.customer_support_path(socket, :index), "Team deleted")
+ {:noreply, socket}
+
+ {:error, :active_subscription} ->
+ failure("The team has an active subscription which must be canceled first.")
+
+ {:noreply, socket}
+ end
+ end
+end
diff --git a/extra/lib/plausible_web/live/customer_support/team/components/sites.ex b/extra/lib/plausible_web/live/customer_support/team/components/sites.ex
new file mode 100644
index 0000000000..89edf14fa8
--- /dev/null
+++ b/extra/lib/plausible_web/live/customer_support/team/components/sites.ex
@@ -0,0 +1,68 @@
+defmodule PlausibleWeb.CustomerSupport.Team.Components.Sites do
+ @moduledoc """
+ Team sites component - handles team sites listing
+ """
+ use PlausibleWeb, :live_component
+ alias Plausible.Teams
+
+ def update(%{team: team}, socket) do
+ sites = Teams.owned_sites(team, 100)
+ sites_count = Teams.owned_sites_count(team)
+
+ {:ok, assign(socket, team: team, sites: sites, sites_count: sites_count)}
+ end
+
+ def render(assigns) do
+ ~H"""
+ <div class="mt-2">
+ <.notice :if={@sites_count > 100} class="mt-4 mb-4">
+ This team owns more than 100 sites. Displaying first 100 below.
+ </.notice>
+ <.table rows={@sites}>
+ <:thead>
+ <.th>Domain</.th>
+ <.th>Previous Domain</.th>
+ <.th>Timezone</.th>
+ <.th invisible>Settings</.th>
+ <.th invisible>Dashboard</.th>
+ </:thead>
+ <:tbody :let={site}>
+ <.td>
+ <div class="flex items-center">
+ <img
+ src="/favicon/sources/{site.domain}"
+ onerror="this.onerror=null; this.src='/favicon/sources/placeholder';"
+ class="w-4 h-4 flex-shrink-0 mt-px mr-2"
+ />
+ <.styled_link
+ patch={Routes.customer_support_site_path(PlausibleWeb.Endpoint, :show, site.id)}
+ class="cursor-pointer flex block items-center"
+ >
+ {site.domain}
+ </.styled_link>
+ </div>
+ </.td>
+ <.td>{site.domain_changed_from || "--"}</.td>
+ <.td>{site.timezone}</.td>
+ <.td>
+ <.styled_link
+ new_tab={true}
+ href={Routes.stats_path(PlausibleWeb.Endpoint, :stats, site.domain, [])}
+ >
+ Dashboard
+ </.styled_link>
+ </.td>
+ <.td>
+ <.styled_link
+ new_tab={true}
+ href={Routes.site_path(PlausibleWeb.Endpoint, :settings_general, site.domain, [])}
+ >
+ Settings
+ </.styled_link>
+ </.td>
+ </:tbody>
+ </.table>
+ </div>
+ """
+ end
+end
diff --git a/extra/lib/plausible_web/live/customer_support/team/components/sso.ex b/extra/lib/plausible_web/live/customer_support/team/components/sso.ex
new file mode 100644
index 0000000000..6c321194ca
--- /dev/null
+++ b/extra/lib/plausible_web/live/customer_support/team/components/sso.ex
@@ -0,0 +1,108 @@
+defmodule PlausibleWeb.CustomerSupport.Team.Components.SSO do
+ @moduledoc """
+ Team SSO component - handles SSO integration management
+ """
+ use PlausibleWeb, :live_component
+ import PlausibleWeb.CustomerSupport.Live
+ alias Plausible.Auth.SSO
+
+ def update(%{team: team}, socket) do
+ sso_integration = get_sso_integration(team)
+ {:ok, assign(socket, team: team, sso_integration: sso_integration)}
+ end
+
+ def render(assigns) do
+ ~H"""
+ <div class="mt-4 mb-4 text-gray-900 dark:text-gray-400">
+ <div :if={@sso_integration}>
+ <div class="flex gap-x-8 mb-4 justify-between items-start">
+ <p>
+ Configured?: <code>{SSO.Integration.configured?(@sso_integration)}</code>
+ <br /> IDP Signin URL:
+ <code>
+ {@sso_integration.config.idp_signin_url}
+ </code>
+ <br />IDP Entity ID: <code>{@sso_integration.config.idp_entity_id}</code>
+ </p>
+ <div class="ml-auto">
+ <.button
+ data-confirm="Are you sure you want to remove this SSO team integration, including all its domains and users?"
+ id="remove-sso-integration"
+ phx-click="remove-sso-integration"
+ phx-target={@myself}
+ theme="danger"
+ >
+ Remove Integration
+ </.button>
+ </div>
+ </div>
+ <.table rows={@sso_integration.sso_domains}>
+ <:thead>
+ <.th>Domain</.th>
+ <.th>Status</.th>
+ <.th></.th>
+ </:thead>
+ <:tbody :let={sso_domain}>
+ <.td>
+ {sso_domain.domain}
+ </.td>
+ <.td>
+ {sso_domain.status}
+ <span :if={sso_domain.verified_via}>
+ (via {sso_domain.verified_via} at {Calendar.strftime(
+ sso_domain.last_verified_at,
+ "%b %-d, %Y"
+ )})
+ </span>
+ </.td>
+ <.td actions>
+ <.delete_button
+ id={"remove-sso-domain-#{sso_domain.identifier}"}
+ phx-click="remove-sso-domain"
+ phx-value-identifier={sso_domain.identifier}
+ phx-target={@myself}
+ class="text-sm text-red-600"
+ data-confirm={"Are you sure you want to remove domain '#{sso_domain.domain}'? All SSO users will be deprovisioned and logged out."}
+ />
+ </.td>
+ </:tbody>
+ </.table>
+ </div>
+ <div :if={!@sso_integration} class="text-center py-8 text-gray-500">
+ <p>No SSO integration configured for this team.</p>
+ </div>
+ </div>
+ """
+ end
+
+ def handle_event("remove-sso-integration", _, socket) do
+ :ok = SSO.remove_integration(socket.assigns.sso_integration, force_deprovision?: true)
+
+ socket =
+ socket
+ |> assign(sso_integration: nil)
+ |> push_navigate(
+ to: Routes.customer_support_team_path(socket, :show, socket.assigns.team.id)
+ )
+
+ success("SSO integration removed")
+
+ {:noreply, socket}
+ end
+
+ def handle_event("remove-sso-domain", %{"identifier" => i}, socket) do
+ domain = Enum.find(socket.assigns.sso_integration.sso_domains, &(&1.identifier == i))
+ :ok = SSO.Domains.remove(domain, force_deprovision?: true)
+
+ success("SSO domain removed")
+
+ {:noreply, assign(socket, sso_integration: get_sso_integration(socket.assigns.team))}
+ end
+
+ defp get_sso_integration(team) do
+ case SSO.get_integration_for(team) do
+ {:error, :not_found} -> nil
+ {:ok, integration} -> integration
+ end
+ end
+end
diff --git a/extra/lib/plausible_web/live/customer_support/user.ex b/extra/lib/plausible_web/live/customer_support/user.ex
new file mode 100644
index 0000000000..c1ef154795
--- /dev/null
+++ b/extra/lib/plausible_web/live/customer_support/user.ex
@@ -0,0 +1,115 @@
+defmodule PlausibleWeb.Live.CustomerSupport.User do
+ @moduledoc """
+ User coordinator LiveView for Customer Support interface.
+
+ Manages tab-based navigation and delegates rendering to specialized
+ components: Overview and API Keys.
+ """
+ use PlausibleWeb.CustomerSupport.Live
+
+ import Ecto.Query
+ alias Plausible.Repo
+
+ alias PlausibleWeb.CustomerSupport.User.Components.{
+ Overview,
+ Keys
+ }
+
+ def handle_params(%{"id" => user_id} = params, _uri, socket) do
+ tab = params["tab"] || "overview"
+ user = Resource.User.get(user_id)
+
+ if user do
+ keys_count = count_keys(user)
+
+ socket =
+ socket
+ |> assign(:user, user)
+ |> assign(:tab, tab)
+ |> assign(:keys_count, keys_count)
+
+ {:noreply, go_to_tab(socket, tab, params, :user, tab_component(tab))}
+ else
+ {:noreply, redirect(socket, to: Routes.customer_support_path(socket, :index))}
+ end
+ end
+
+ def render(assigns) do
+ ~H"""
+ <Layout.layout show_search={false} flash={@flash}>
+ <div class="overflow-hidden rounded-lg">
+ <.user_header user={@user} />
+ <.user_tab_navigation user={@user} tab={@tab} keys_count={@keys_count} />
+
+ <.live_component
+ module={tab_component(@tab)}
+ user={@user}
+ tab={@tab}
+ id={"user-#{@user.id}-#{@tab}"}
+ />
+ </div>
+ </Layout.layout>
+ """
+ end
+
+ defp user_header(assigns) do
+ ~H"""
+ <div class="sm:flex sm:items-center sm:justify-between">
+ <div class="sm:flex sm:space-x-5">
+ <div class="shrink-0">
+ <div class="rounded-full p-1 flex items-center justify-center">
+ <img
+ src={Plausible.Auth.User.profile_img_url(@user)}
+ class="w-14 rounded-full bg-gray-300"
+ />
+ </div>
+ </div>
+ <div class="mt-4 text-center sm:mt-0 sm:pt-1 sm:text-left">
+ <p class="text-xl font-bold sm:text-2xl">
+ <div class="flex items-center gap-x-2">
+ {@user.name}
+ <span :if={@user.type == :sso} class="bg-green-700 text-gray-100 text-xs p-1 rounded">
+ SSO
+ </span>
+ </div>
+ </p>
+ <p class="text-sm font-medium">{@user.email}</p>
+ </div>
+ </div>
+
+ <div class="mt-5 flex justify-center sm:mt-0">
+ <.input_with_clipboard
+ id="user-identifier"
+ name="user-identifier"
+ label="User Identifier"
+ value={@user.id}
+ />
+ </div>
+ </div>
+ """
+ end
+
+ defp user_tab_navigation(assigns) do
+ ~H"""
+ <.tab_navigation tab={@tab}>
+ <:tabs>
+ <.tab to="overview" tab={@tab}>Overview</.tab>
+ <.tab to="keys" tab={@tab}>
+ API Keys ({@keys_count})
+ </.tab>
+ </:tabs>
+ </.tab_navigation>
+ """
+ end
+
+ defp tab_component("overview"), do: Overview
+ defp tab_component("keys"), do: Keys
+ defp tab_component(_), do: Overview
+
+ defp count_keys(user) do
+ from(api_key in Plausible.Auth.ApiKey,
+ where: api_key.user_id == ^user.id
+ )
+ |> Repo.aggregate(:count)
+ end
+end
diff --git a/extra/lib/plausible_web/live/customer_support/user/components/keys.ex b/extra/lib/plausible_web/live/customer_support/user/components/keys.ex
new file mode 100644
index 0000000000..311c9f73f5
--- /dev/null
+++ b/extra/lib/plausible_web/live/customer_support/user/components/keys.ex
@@ -0,0 +1,52 @@
+defmodule PlausibleWeb.CustomerSupport.User.Components.Keys do
+ @moduledoc """
+ User API keys component - handles displaying user's API keys
+ """
+ use PlausibleWeb, :live_component
+ import Ecto.Query
+ alias Plausible.Repo
+
+ def update(%{user: user}, socket) do
+ keys = keys(user)
+ {:ok, assign(socket, user: user, keys: keys)}
+ end
+
+ def render(assigns) do
+ ~H"""
+ <div class="mt-8">
+ <.table rows={@keys}>
+ <:thead>
+ <.th>Team</.th>
+ <.th>Name</.th>
+ <.th>Scopes</.th>
+ <.th>Prefix</.th>
+ </:thead>
+ <:tbody :let={api_key}>
+ <.td :if={is_nil(api_key.team)}>N/A</.td>
+ <.td :if={api_key.team}>
+ <.styled_link patch={
+ Routes.customer_support_team_path(PlausibleWeb.Endpoint, :show, api_key.team.id)
+ }>
+ {api_key.team.name}
+ </.styled_link>
+ </.td>
+ <.td>{api_key.name}</.td>
+ <.td>
+ {api_key.scopes}
+ </.td>
+ <.td>{api_key.key_prefix}</.td>
+ </:tbody>
+ </.table>
+ </div>
+ """
+ end
+
+ defp keys(user) do
+ from(
+ key in Plausible.Auth.ApiKey,
+ where: key.user_id == ^user.id,
+ preload: :team
+ )
+ |> Repo.all()
+ end
+end
diff --git a/extra/lib/plausible_web/live/customer_support/user/components/overview.ex b/extra/lib/plausible_web/live/customer_support/user/components/overview.ex
new file mode 100644
index 0000000000..3845deff3f
--- /dev/null
+++ b/extra/lib/plausible_web/live/customer_support/user/components/overview.ex
@@ -0,0 +1,86 @@
+defmodule PlausibleWeb.CustomerSupport.User.Components.Overview do
+ @moduledoc """
+ User overview component - handles user settings, team memberships, and user management
+ """
+ use PlausibleWeb, :live_component
+ import PlausibleWeb.CustomerSupport.Live
+
+ def update(%{user: user}, socket) do
+ form = user |> Plausible.Auth.User.changeset() |> to_form()
+ {:ok, assign(socket, user: user, form: form)}
+ end
+
+ def render(assigns) do
+ ~H"""
+ <div class="mt-8">
+ <.table rows={@user.team_memberships}>
+ <:thead>
+ <.th>Team</.th>
+ <.th>Role</.th>
+ </:thead>
+ <:tbody :let={membership}>
+ <.td>
+ <.styled_link patch={
+ Routes.customer_support_team_path(PlausibleWeb.Endpoint, :show, membership.team.id)
+ }>
+ {membership.team.name}
+ </.styled_link>
+ </.td>
+ <.td>{membership.role}</.td>
+ </:tbody>
+ </.table>
+
+ <.form :let={f} for={@form} phx-target={@myself} phx-submit="save-user" class="mt-8">
+ <.input type="textarea" field={f[:notes]} label="Notes" />
+ <div class="flex justify-between">
+ <.button phx-target={@myself} type="submit">
+ Save
+ </.button>
+ <.button
+ phx-target={@myself}
+ phx-click="delete-user"
+ data-confirm="Are you sure you want to delete this user?"
+ theme="danger"
+ >
+ Delete User
+ </.button>
+ </div>
+ </.form>
+ </div>
+ """
+ end
+
+ def handle_event("delete-user", _params, socket) do
+ user = socket.assigns.user
+
+ case Plausible.Auth.delete_user(user) do
+ {:ok, _} ->
+ navigate_with_success(Routes.customer_support_path(socket, :index), "User deleted")
+ {:noreply, socket}
+
+ {:error, :active_subscription} ->
+ failure("Cannot delete user with active subscription")
+ {:noreply, socket}
+
+ {:error, reason} ->
+ failure("Failed to delete user: #{inspect(reason)}")
+ {:noreply, socket}
+ end
+ end
+
+ def handle_event("save-user", %{"user" => params}, socket) do
+ user = socket.assigns.user
+
+ case Plausible.Auth.User.changeset(user, params) |> Plausible.Repo.update() do
+ {:ok, updated_user} ->
+ form = updated_user |> Plausible.Auth.User.changeset() |> to_form()
+ success("User updated successfully")
+ {:noreply, assign(socket, user: updated_user, form: form)}
+
+ {:error, changeset} ->
+ form = changeset |> to_form()
+ failure("Failed to update user")
+ {:noreply, assign(socket, form: form)}
+ end
+ end
+end
diff --git a/lib/plausible_web/router.ex b/lib/plausible_web/router.ex
index 20dc27a042..58f8988fd1 100644
--- a/lib/plausible_web/router.ex
+++ b/lib/plausible_web/router.ex
@@ -109,8 +109,9 @@ defmodule PlausibleWeb.Router do
pipe_through [:browser, :csrf, :app_layout, :flags]
live "/cs", CustomerSupport, :index, as: :customer_support
-
- live "/cs/:any/:resource/:id", CustomerSupport, :details, as: :customer_support_resource
+ live "/cs/teams/team/:id", CustomerSupport.Team, :show, as: :customer_support_team
+ live "/cs/users/user/:id", CustomerSupport.User, :show, as: :customer_support_user
+ live "/cs/sites/site/:id", CustomerSupport.Site, :show, as: :customer_support_site
end
end
diff --git a/test/plausible/help_scout_test.exs b/test/plausible/help_scout_test.exs
index 8df6bb2e55..377ad8939d 100644
--- a/test/plausible/help_scout_test.exs
+++ b/test/plausible/help_scout_test.exs
@@ -10,6 +10,8 @@ defmodule Plausible.HelpScoutTest do
alias Plausible.HelpScout
alias Plausible.Repo
+ alias PlausibleWeb.Router.Helpers, as: Routes
+
require Plausible.Billing.Subscription.Status
@v4_business_monthly_plan_id "857105"
@@ -59,7 +61,7 @@ defmodule Plausible.HelpScoutTest do
stub_help_scout_requests(email)
team = team_of(user)
- crm_url = "#{PlausibleWeb.Endpoint.url()}/cs/teams/team/#{team.id}"
+ crm_url = Routes.customer_support_team_url(PlausibleWeb.Endpoint, :show, team.id)
assert {:ok,
%{
@@ -407,7 +409,7 @@ defmodule Plausible.HelpScoutTest do
team = team_of(user)
- crm_url = "#{PlausibleWeb.Endpoint.url()}/cs/teams/team/#{team.id}"
+ crm_url = Routes.customer_support_team_url(PlausibleWeb.Endpoint, :show, team.id)
assert {:ok,
%{
@@ -442,7 +444,7 @@ defmodule Plausible.HelpScoutTest do
new_site(owner: user2)
team2 = team_of(user2)
- crm_url = "#{PlausibleWeb.Endpoint.url()}/cs/teams/team/#{team2.id}"
+ crm_url = Routes.customer_support_team_url(PlausibleWeb.Endpoint, :show, team2.id)
assert {:ok,
%{
diff --git a/test/plausible_web/controllers/help_scout_controller_test.exs b/test/plausible_web/controllers/help_scout_controller_test.exs
index e3b5de3011..5a2eb37b5e 100644
--- a/test/plausible_web/controllers/help_scout_controller_test.exs
+++ b/test/plausible_web/controllers/help_scout_controller_test.exs
@@ -50,7 +50,8 @@ defmodule PlausibleWeb.HelpScoutControllerTest do
"/helpscout/callback?conversation-id=123&customer-id=500&X-HelpScout-Signature=#{signature}"
)
- assert html_response(conn, 200) =~ "/cs/users/user/#{user.id}"
+ assert html_response(conn, 200) =~
+ Routes.customer_support_user_path(PlausibleWeb.Endpoint, :show, user.id)
end
test "returns error on failure", %{conn: conn} do
@@ -129,7 +130,7 @@ defmodule PlausibleWeb.HelpScoutControllerTest do
)
assert html = html_response(conn, 200)
- assert html =~ "/cs/users/user/#{user.id}"
+ assert html =~ Routes.customer_support_user_path(PlausibleWeb.Endpoint, :show, user.id)
assert html =~ "Some note<br>\nwith new line"
end
@@ -158,7 +159,7 @@ defmodule PlausibleWeb.HelpScoutControllerTest do
)
assert html = html_response(conn, 200)
- assert html =~ "/cs/users/user/#{user.id}"
+ assert html =~ Routes.customer_support_user_path(PlausibleWeb.Endpoint, :show, user.id)
assert html =~ "Some user notes"
assert html =~ "My Personal Sites"
assert html =~ "HS Integration Test Team"
diff --git a/test/plausible_web/controllers/stats_controller_test.exs b/test/plausible_web/controllers/stats_controller_test.exs
index 469784a478..e6bc9ecaa9 100644
--- a/test/plausible_web/controllers/stats_controller_test.exs
+++ b/test/plausible_web/controllers/stats_controller_test.exs
@@ -220,7 +220,8 @@ defmodule PlausibleWeb.StatsControllerTest do
test "does not show CRM link to the site", %{conn: conn, site: site} do
conn = get(conn, conn |> get("/" <> site.domain) |> redirected_to())
- refute html_response(conn, 200) =~ "/cs/sites/site/#{site.id}"
+
+ refute html_response(conn, 200) =~ "/cs/sites"
end
test "all segments (personal or site) are stuffed into dataset, with their associated owner_id and owner_name",
@@ -312,10 +313,14 @@ defmodule PlausibleWeb.StatsControllerTest do
assert Enum.all?(attrs, fn {k, v} -> is_binary(k) and is_binary(v) end)
end
- test "shows CRM link to the site", %{conn: conn} do
- site = new_site()
- conn = get(conn, conn |> get("/" <> site.domain) |> redirected_to())
- assert html_response(conn, 200) =~ "/cs/sites/site/#{site.id}"
+ on_ee do
+ test "shows CRM link to the site", %{conn: conn} do
+ site = new_site()
+ conn = get(conn, conn |> get("/" <> site.domain) |> redirected_to())
+
+ assert html_response(conn, 200) =~
+ Routes.customer_support_site_path(PlausibleWeb.Endpoint, :show, site.id)
+ end
end
end
diff --git a/test/plausible_web/live/customer_support/sites_test.exs b/test/plausible_web/live/customer_support/sites_test.exs
index ca87dd6f4a..54a82f386e 100644
--- a/test/plausible_web/live/customer_support/sites_test.exs
+++ b/test/plausible_web/live/customer_support/sites_test.exs
@@ -11,14 +11,7 @@ defmodule PlausibleWeb.Live.CustomerSupport.SitesTest do
import Plausible.Test.Support.HTML
defp open_site(id, opts \\ []) do
- Routes.customer_support_resource_path(
- PlausibleWeb.Endpoint,
- :details,
- :sites,
- :site,
- id,
- opts
- )
+ Routes.customer_support_site_path(PlausibleWeb.Endpoint, :show, id, opts)
end
describe "overview" do
@@ -35,10 +28,10 @@ defmodule PlausibleWeb.Live.CustomerSupport.SitesTest do
assert element_exists?(
html,
- ~s|a[href$="#{URI.encode_www_form(site.domain)}/settings/general"]|
+ ~s|a[href$="#{site.domain}/settings/general"]|
)
- assert element_exists?(html, ~s|a[href$="#{URI.encode_www_form(site.domain)}/"]|)
+ assert element_exists?(html, ~s|a[href="/#{site.domain}"]|)
end
test "404", %{conn: conn} do
@@ -46,6 +39,18 @@ defmodule PlausibleWeb.Live.CustomerSupport.SitesTest do
{:ok, _lv, _html} = live(conn, open_site(9999))
end
end
+
+ test "delete site", %{conn: conn, site: site} do
+ {:ok, lv, _html} = live(conn, open_site(site.id))
+
+ lv
+ |> element(~s|button[phx-click="delete-site"]|)
+ |> render_click()
+
+ assert_redirect(lv, Routes.customer_support_path(PlausibleWeb.Endpoint, :index))
+
+ refute Plausible.Sites.get_by_domain(site.domain)
+ end
end
describe "rescue zone" do
diff --git a/test/plausible_web/live/customer_support/teams_test.exs b/test/plausible_web/live/customer_support/teams_test.exs
index 90dd6c03a3..76b29c6597 100644
--- a/test/plausible_web/live/customer_support/teams_test.exs
+++ b/test/plausible_web/live/customer_support/teams_test.exs
@@ -13,14 +13,7 @@ defmodule PlausibleWeb.Live.CustomerSupport.TeamsTest do
require Plausible.Billing.Subscription.Status
defp open_team(id, qs \\ []) do
- Routes.customer_support_resource_path(
- PlausibleWeb.Endpoint,
- :details,
- :teams,
- :team,
- id,
- qs
- )
+ Routes.customer_support_team_path(PlausibleWeb.Endpoint, :show, id, qs)
end
describe "overview" do
@@ -36,6 +29,35 @@ defmodule PlausibleWeb.Live.CustomerSupport.TeamsTest do
assert text(html) =~ team.name
end
+ test "delete team", %{conn: conn, user: user} do
+ team = team_of(user)
+ {:ok, lv, _html} = live(conn, open_team(team.id))
+
+ lv
+ |> element(~s|button[phx-click="delete-team"]|)
+ |> render_click()
+
+ assert_redirect(lv, Routes.customer_support_path(PlausibleWeb.Endpoint, :index))
+
+ refute Plausible.Repo.get(Plausible.Teams.Team, team.id)
+ end
+
+ test "delete team with active subscription", %{conn: conn, user: user} do
+ user = subscribe_to_growth_plan(user)
+ team = team_of(user)
+ {:ok, lv, _html} = live(conn, open_team(team.id))
+
+ lv
+ |> element(~s|button[phx-click="delete-team"]|)
+ |> render_click()
+
+ text = lv |> render() |> text()
+
+ assert text =~ "The team has an active subscription which must be canceled first"
+
+ assert Plausible.Repo.get(Plausible.Teams.Team, team.id)
+ end
+
test "grace period handling", %{conn: conn, user: user} do
team = team_of(user)
{:ok, _, html} = live(conn, open_team(team.id))
@@ -613,7 +635,7 @@ defmodule PlausibleWeb.Live.CustomerSupport.TeamsTest do
assert {:error, {:live_redirect, %{to: to}}} =
lv |> element("button#remove-sso-integration") |> render_click()
- assert to == "/cs/teams/team/#{team.id}"
+ assert to == Routes.customer_support_team_path(PlausibleWeb.Endpoint, :show, team.id)
end
end
diff --git a/test/plausible_web/live/customer_support/users_test.exs b/test/plausible_web/live/customer_support/users_test.exs
index fa7e50a929..ed274feaea 100644
--- a/test/plausible_web/live/customer_support/users_test.exs
+++ b/test/plausible_web/live/customer_support/users_test.exs
@@ -9,14 +9,7 @@ defmodule PlausibleWeb.Live.CustomerSupport.UsersTest do
import Plausible.Test.Support.HTML
defp open_user(id, qs \\ []) do
- Routes.customer_support_resource_path(
- PlausibleWeb.Endpoint,
- :details,
- :users,
- :user,
- id,
- qs
- )
+ Routes.customer_support_user_path(PlausibleWeb.Endpoint, :show, id, qs)
end
describe "overview" do
@@ -36,7 +29,12 @@ defmodule PlausibleWeb.Live.CustomerSupport.UsersTest do
assert text_of_attr(uid, "value") == "#{user.id}"
team = team_of(user)
- assert [_] = find(html, ~s|a[href="/cs/teams/team/#{team.id}"]|)
+
+ assert [_] =
+ find(
+ html,
+ ~s|a[href="#{Routes.customer_support_team_path(PlausibleWeb.Endpoint, :show, team.id)}"]|
+ )
end
test "404", %{conn: conn} do
@@ -44,6 +42,51 @@ defmodule PlausibleWeb.Live.CustomerSupport.UsersTest do
{:ok, _lv, _html} = live(conn, open_user(9999))
end
end
+
+ test "delete user", %{conn: conn, user: user} do
+ {:ok, lv, _html} = live(conn, open_user(user.id))
+
+ lv
+ |> element(~s|button[phx-click="delete-user"]|)
+ |> render_click()
+
+ assert_redirect(lv, Routes.customer_support_path(PlausibleWeb.Endpoint, :index))
+
+ refute Plausible.Repo.get(Plausible.Auth.User, user.id)
+ end
+
+ test "delete user with active subscription", %{conn: conn, user: user} do
+ user |> subscribe_to_growth_plan()
+
+ {:ok, lv, _html} = live(conn, open_user(user.id))
+
+ lv
+ |> element(~s|button[phx-click="delete-user"]|)
+ |> render_click()
+
+ text = lv |> render() |> text()
+
+ assert text =~ "Cannot delete user with active subscription"
+
+ assert Plausible.Repo.get(Plausible.Auth.User, user.id)
+ end
+
+ test "delete user when they're sole team owner", %{conn: conn, user: user} do
+ site = new_site(owner: user)
+ Plausible.Teams.complete_setup(site.team)
+
+ {:ok, lv, _html} = live(conn, open_user(user.id))
+
+ lv
+ |> element(~s|button[phx-click="delete-user"]|)
+ |> render_click()
+
+ text = lv |> render() |> text()
+
+ assert text =~ "Failed to delete user: :is_only_team_owner"
+
+ assert Plausible.Repo.get(Plausible.Auth.User, user.id)
+ end
end
describe "keys" do
diff --git a/test/plausible_web/live/customer_support_test.exs b/test/plausible_web/live/customer_support_test.exs
index 9793402541..f7939f65c4 100644
--- a/test/plausible_web/live/customer_support_test.exs
+++ b/test/plausible_web/live/customer_support_test.exs
@@ -128,13 +128,11 @@ defmodule PlausibleWeb.Live.CustomerSupportTest do
assert [link] = find(doc, ~s|a[data-test-type="#{type}"][data-test-id="#{id}"]|)
assert text_of_attr(link, "href") ==
- Routes.customer_support_resource_path(
+ apply(Routes, :"customer_support_#{type}_path", [
PlausibleWeb.Endpoint,
- :details,
- "#{type}s",
- type,
+ :show,
id
- )
+ ])
end
defp refute_search_result(doc, type, id) do