Fixing Business Tier related bugs (#3504)

* fix underlined blank space in upgrade link

* Add :if clause to site limit notice

* Change test description

* Move growth? and trial? conditionals to CTA function

* Improve wording in billing notices

---------

Co-authored-by: Vinicius Brasil <vini@hey.com>
This commit is contained in:
RobertJoonas 2023-11-10 14:03:02 +00:00 committed by GitHub
parent af87a63cab
commit 26d9e16d7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 57 additions and 38 deletions

View File

@ -50,7 +50,7 @@ defmodule PlausibleWeb.Components.Billing do
not has_access? ->
~H"""
<.notice class="rounded-t-md rounded-b-none" size={@size} {@rest}>
This account does not have access to <%= assigns.feature_mod.display_name() %>. To get access to this feature,
<%= account_label(@current_user, @billable_user) %> does not have access to <%= assigns.feature_mod.display_name() %>. To get access to this feature,
<.upgrade_call_to_action current_user={@current_user} billable_user={@billable_user} />.
</.notice>
"""
@ -80,6 +80,18 @@ defmodule PlausibleWeb.Components.Billing do
# credo:disable-for-next-line Credo.Check.Refactor.CyclomaticComplexity
def limit_exceeded_notice(assigns) do
~H"""
<.notice {@rest}>
<%= account_label(@current_user, @billable_user) %> is limited to <%= @limit %> <%= @resource %>. To increase this limit,
<.upgrade_call_to_action current_user={@current_user} billable_user={@billable_user} />.
</.notice>
"""
end
attr(:current_user, :map)
attr(:billable_user, :map)
defp upgrade_call_to_action(assigns) do
billable_user = Plausible.Users.with_subscription(assigns.billable_user)
plan =
@ -88,37 +100,28 @@ defmodule PlausibleWeb.Components.Billing do
trial? = Plausible.Billing.on_trial?(assigns.billable_user)
growth? = plan && plan.kind == :growth
if growth? || trial? do
~H"""
<.notice {@rest}>
This account is limited to <%= @limit %> <%= @resource %>. To increase this limit,
<.upgrade_call_to_action current_user={@current_user} billable_user={@billable_user} />.
</.notice>
"""
else
~H"""
<.notice {@rest}>
Your account is limited to <%= @limit %> <%= @resource %>. To increase this limit, please contact support@plausible.io about the Enterprise plan
</.notice>
"""
cond do
assigns.billable_user.id !== assigns.current_user.id ->
~H"please reach out to the site owner to upgrade their subscription"
growth? || trial? ->
~H"""
please
<.link class="underline inline-block" href={Plausible.Billing.upgrade_route_for(@current_user)}>
upgrade your subscription
</.link>
"""
true ->
~H"please contact support@plausible.io about the Enterprise plan"
end
end
attr(:current_user, :map)
attr(:billable_user, :map)
defp upgrade_call_to_action(assigns) do
if assigns.current_user.id == assigns.billable_user.id do
~H"""
please
<.link class="underline" href={Plausible.Billing.upgrade_route_for(@current_user)}>
upgrade your subscription
</.link>
"""
defp account_label(current_user, billable_user) do
if current_user.id == billable_user.id do
"Your account"
else
~H"""
please reach out to the site owner to upgrade their subscription
"""
"The owner of this site"
end
end

View File

@ -3,6 +3,7 @@
<h2 class="text-xl font-black dark:text-gray-100 mb-4">Your website details</h2>
<PlausibleWeb.Components.Billing.limit_exceeded_notice
:if={Map.get(assigns, :is_at_limit, false)}
current_user={@current_user}
billable_user={@current_user}
limit={Map.get(assigns, :site_limit, 0)}

View File

@ -24,7 +24,7 @@ defmodule PlausibleWeb.Components.BillingTest do
feature_mod: Plausible.Billing.Feature.Props
)
assert rendered =~ "This account does not have access to Custom Properties"
assert rendered =~ "Your account does not have access to Custom Properties"
assert rendered =~ "upgrade your subscription"
assert rendered =~ "/billing/choose-plan"
end
@ -40,7 +40,7 @@ defmodule PlausibleWeb.Components.BillingTest do
feature_mod: Plausible.Billing.Feature.Funnels
)
assert rendered =~ "This account does not have access to Funnels"
assert rendered =~ "The owner of this site does not have access to Funnels"
assert rendered =~ "please reach out to the site owner to upgrade their subscription"
end
@ -68,7 +68,7 @@ defmodule PlausibleWeb.Components.BillingTest do
resource: "users"
)
assert rendered =~ "This account is limited to 10 users. To increase this limit"
assert rendered =~ "Your account is limited to 10 users. To increase this limit"
assert rendered =~ "upgrade your subscription"
assert rendered =~ "/billing/choose-plan"
end
@ -84,7 +84,7 @@ defmodule PlausibleWeb.Components.BillingTest do
resource: "users"
)
assert rendered =~ "This account is limited to 10 users"
assert rendered =~ "The owner of this site is limited to 10 users"
assert rendered =~ "please reach out to the site owner to upgrade their subscription"
end
@ -99,7 +99,7 @@ defmodule PlausibleWeb.Components.BillingTest do
resource: "users"
)
assert rendered =~ "This account is limited to 10 users"
assert rendered =~ "Your account is limited to 10 users"
assert rendered =~ "upgrade your subscription"
assert rendered =~ "/billing/choose-plan"
end
@ -119,8 +119,8 @@ defmodule PlausibleWeb.Components.BillingTest do
resource: "users"
)
assert rendered =~
"Your account is limited to 10 users. To increase this limit, please contact support@plausible.io about the Enterprise plan"
assert rendered =~ "Your account is limited to 10 users."
assert rendered =~ "please contact support@plausible.io about the Enterprise plan"
end
test "limit_exceeded_notice/1 when billable user is on a business plan displays support email" do
@ -134,7 +134,7 @@ defmodule PlausibleWeb.Components.BillingTest do
resource: "users"
)
assert rendered =~
"Your account is limited to 10 users. To increase this limit, please contact support@plausible.io about the Enterprise plan"
assert rendered =~ "Your account is limited to 10 users."
assert rendered =~ "please contact support@plausible.io about the Enterprise plan"
end
end

View File

@ -32,6 +32,21 @@ defmodule PlausibleWeb.SiteControllerTest do
refute html_response(conn, 200) =~ "Add site info"
end
test "does not display limit notice when user is on an enterprise plan", %{
conn: conn,
user: user
} do
ep = insert(:enterprise_plan, user: user)
insert(:subscription, user: user, paddle_plan_id: ep.paddle_plan_id)
insert(:site, members: [user])
insert(:site, members: [user])
insert(:site, members: [user])
conn = get(conn, "/sites/new")
refute html_response(conn, 200) =~ "is limited to"
end
end
describe "GET /sites" do
@ -271,7 +286,7 @@ defmodule PlausibleWeb.SiteControllerTest do
})
assert html = html_response(conn, 200)
assert html =~ "This account is limited to 10 sites"
assert html =~ "Your account is limited to 10 sites"
refute Repo.get_by(Plausible.Site, domain: "over-limit.example.com")
end