Skip to content

Commit

Permalink
Fixing Business Tier related bugs (#3504)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
RobertJoonas and vinibrsl authored Nov 10, 2023
1 parent af87a63 commit 26d9e16
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 38 deletions.
59 changes: 31 additions & 28 deletions lib/plausible_web/components/billing.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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>
"""
Expand Down Expand Up @@ -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 =
Expand All @@ -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 [email protected] 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 [email protected] 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

Expand Down
1 change: 1 addition & 0 deletions lib/plausible_web/templates/site/new.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down
18 changes: 9 additions & 9 deletions test/plausible_web/components/billing_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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 [email protected] about the Enterprise plan"
assert rendered =~ "Your account is limited to 10 users."
assert rendered =~ "please contact [email protected] about the Enterprise plan"
end

test "limit_exceeded_notice/1 when billable user is on a business plan displays support email" do
Expand All @@ -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 [email protected] about the Enterprise plan"
assert rendered =~ "Your account is limited to 10 users."
assert rendered =~ "please contact [email protected] about the Enterprise plan"
end
end
17 changes: 16 additions & 1 deletion test/plausible_web/controllers/site_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 26d9e16

Please sign in to comment.