Skip to content

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

CRM: Bring back site/member counters in Team tabs; revert search results changes (#5633)

Adam Rutkowski4c89ffc26353
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
index 31d53f0b89..5cb2c00a63 100644
--- a/extra/lib/plausible_web/live/customer_support/components/search_result.ex
+++ b/extra/lib/plausible_web/live/customer_support/components/search_result.ex
@@ -27,25 +27,22 @@ defmodule PlausibleWeb.CustomerSupport.Components.SearchResult do
<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">
- <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>
+ 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>
"""
@@ -71,7 +68,7 @@ defmodule PlausibleWeb.CustomerSupport.Components.SearchResult do
<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)
+ Owns {length(@resource.object.owned_teams)} team(s)
</div>
</div>
"""
@@ -98,10 +95,9 @@ defmodule PlausibleWeb.CustomerSupport.Components.SearchResult do
<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>
+ owned by {@resource.object.team.owners
+ |> Enum.map(& &1.name)
+ |> Enum.join(", ")}
</div>
</div>
"""
diff --git a/extra/lib/plausible_web/live/customer_support/team.ex b/extra/lib/plausible_web/live/customer_support/team.ex
index 6932811e1a..bccbaecca0 100644
--- a/extra/lib/plausible_web/live/customer_support/team.ex
+++ b/extra/lib/plausible_web/live/customer_support/team.ex
@@ -62,11 +62,23 @@ defmodule PlausibleWeb.Live.CustomerSupport.Team do
end
def render(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"""
<Layout.layout show_search={false} flash={@flash}>
<.team_header team={@team} />
- <.team_tab_navigation team={@team} tab={@tab} />
- <.team_stats team={@team} />
+ <.team_tab_navigation team={@team} tab={@tab} limits={@limits} usage={@usage} />
+ <.subscription_bar team={@team} />
<.live_component
module={tab_component(@tab)}
@@ -121,8 +133,12 @@ defmodule PlausibleWeb.Live.CustomerSupport.Team do
<.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 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={has_sso_integration?(@team)} to="sso" tab={@tab}>SSO</.tab>
<.tab to="billing" tab={@tab}>Billing</.tab>
<.tab to="audit" tab={@tab}>Audit</.tab>
@@ -131,18 +147,7 @@ defmodule PlausibleWeb.Live.CustomerSupport.Team do
"""
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)
-
+ defp subscription_bar(assigns) do
~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">
@@ -354,4 +359,14 @@ defmodule PlausibleWeb.Live.CustomerSupport.Team do
socket
end
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
end
diff --git a/test/plausible_web/live/customer_support/teams_test.exs b/test/plausible_web/live/customer_support/teams_test.exs
index 76b29c6597..8f12c4fc8e 100644
--- a/test/plausible_web/live/customer_support/teams_test.exs
+++ b/test/plausible_web/live/customer_support/teams_test.exs
@@ -25,8 +25,30 @@ defmodule PlausibleWeb.Live.CustomerSupport.TeamsTest do
test "renders", %{conn: conn, user: user} do
team = team_of(user)
+ new_site(owner: user)
+ add_member(team, role: :editor)
+
{:ok, _lv, html} = live(conn, open_team(team.id))
- assert text(html) =~ team.name
+ text = text(html)
+
+ assert text =~ team.name
+ assert text =~ "Sites (2/10)"
+ assert text =~ "Members (1/10)"
+ end
+
+ test "renders unlimited limits", %{conn: conn, user: user} do
+ owner = new_user(team: [inserted_at: ~N[2021-01-01 00:00:00]])
+ subscribe_to_enterprise_plan(owner, team_member_limit: :unlimited)
+ team = team_of(owner)
+ add_member(team, user: user, role: :editor)
+ new_site(owner: owner)
+
+ {:ok, _lv, html} = live(conn, open_team(team.id))
+ text = text(html)
+
+ assert text =~ team.name
+ assert text =~ "Sites (1/unlimited)"
+ assert text =~ "Members (1/unlimited)"
end
test "delete team", %{conn: conn, user: user} do