From 2578391be273cf20f7e5b97ec08f17e51b706908 Mon Sep 17 00:00:00 2001 From: Vini Brasil Date: Wed, 8 Nov 2023 11:59:03 -0300 Subject: [PATCH] Display private preview for non business accounts (#3502) * Display private preview for non business accounts * Update lib/plausible_web/components/billing.ex Co-authored-by: RobertJoonas <56999674+RobertJoonas@users.noreply.github.com> --------- Co-authored-by: RobertJoonas <56999674+RobertJoonas@users.noreply.github.com> --- lib/plausible_web/components/billing.ex | 133 +++++++++--------- .../plausible_web/components/billing_test.exs | 22 ++- .../controllers/site_controller_test.exs | 2 +- 3 files changed, 76 insertions(+), 81 deletions(-) diff --git a/lib/plausible_web/components/billing.ex b/lib/plausible_web/components/billing.ex index f980038b4..cdb3db572 100644 --- a/lib/plausible_web/components/billing.ex +++ b/lib/plausible_web/components/billing.ex @@ -18,47 +18,50 @@ defmodule PlausibleWeb.Components.Billing do def premium_feature_notice(assigns) do billable_user = Plausible.Users.with_subscription(assigns.billable_user) plan = Plans.get_regular_plan(billable_user.subscription, only_non_expired: true) - growth? = plan && plan.kind == :growth + business? = plan && plan.kind == :business private_preview? = FunWithFlags.enabled?(:premium_features_private_preview) - display_upgrade_link? = assigns.current_user.id == assigns.billable_user.id has_access? = assigns.feature_mod.check_availability(assigns.billable_user) == :ok - message = - cond do - Plausible.Billing.on_trial?(assigns.billable_user) -> - "#{assigns.feature_mod.display_name()} is part of the Plausible Business plan. You can access it during your trial, but you'll need to subscribe to the Business plan to retain access after the trial ends." - - private_preview? && display_upgrade_link? && growth? -> - ~H""" - Business plans are now live! The private preview of <%= @feature_mod.display_name() %> for Plausible Growth plans ends <%= private_preview_days_remaining() %>. If you wish to continue using this feature, please - <.link class="underline" href={Routes.billing_path(PlausibleWeb.Endpoint, :upgrade)}> - upgrade your subscription - to the Plausible Business plan. - """ - - not has_access? && display_upgrade_link? -> - ~H""" - <%= @feature_mod.display_name() %> is part of the Plausible Business plan. To get access to it, please - <.link class="underline inline-block" href={Plausible.Billing.upgrade_route_for(@current_user)}> - upgrade your subscription - to the Business plan. - """ - - not has_access? && not display_upgrade_link? -> - "#{assigns.feature_mod.display_name()} is part of the Plausible Business plan. To get access to it, please reach out to the site owner to upgrade your subscription to the Business plan." + cond do + Plausible.Billing.on_trial?(assigns.billable_user) -> + ~H""" + <.notice class="rounded-t-md rounded-b-none" size={@size} {@rest}> + <%= @feature_mod.display_name() %> is part of the Plausible Business plan. You can access it during your trial, but you'll need to subscribe to the Business plan to retain access after the trial ends." + + """ + + private_preview? && !business? -> + ~H""" + <.notice class="rounded-t-md rounded-b-none" size={@size} {@rest}> + Business plans are now live! The private preview of <%= @feature_mod.display_name() %> ends <%= private_preview_days_remaining() %>. If you wish to continue using this feature, + <.upgrade_call_to_action current_user={@current_user} billable_user={@billable_user} />. + + """ + + 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, + <.upgrade_call_to_action current_user={@current_user} billable_user={@billable_user} />. + + """ + + true -> + ~H"" + end + end - true -> - nil - end + defp private_preview_days_remaining do + private_preview_ends_at = Timex.shift(Plausible.Billing.Plans.business_tier_launch(), days: 7) - assigns = assign(assigns, :message, message) + days_remaining = Timex.diff(private_preview_ends_at, NaiveDateTime.utc_now(), :day) - ~H""" - <.notice :if={@message} class="rounded-t-md rounded-b-none" size={@size} {@rest}> - <%= @message %> - - """ + cond do + days_remaining <= 0 -> "today" + days_remaining == 1 -> "tomorrow" + true -> "in #{days_remaining} days" + end end attr(:billable_user, Plausible.Auth.User, required: true) @@ -77,43 +80,37 @@ defmodule PlausibleWeb.Components.Billing do trial? = Plausible.Billing.on_trial?(assigns.billable_user) growth? = plan && plan.kind == :growth - display_upgrade_link? = assigns.current_user.id == assigns.billable_user.id - - message = - cond do - !display_upgrade_link? -> - "This account is limited to #{assigns.limit} #{assigns.resource}. To increase this limit, please reach out to the site owner to upgrade their subscription" - - growth? || trial? -> - ~H""" - Your account is limited to <%= @limit %> <%= @resource %>. To increase this limit, please - <.link class="underline inline-block" href={Plausible.Billing.upgrade_route_for(@current_user)}> - upgrade your subscription - to the Business plan. - """ - - true -> - "Your account is limited to #{assigns.limit} #{assigns.resource}. To increase this limit, please contact support@plausible.io about the Enterprise plan" - end - - assigns = assign(assigns, :message, message) - - ~H""" - <.notice :if={@message} {@rest}> - <%= @message %> - - """ + 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} />. + + """ + else + ~H""" + <.notice {@rest}> + Your account is limited to <%= @limit %> <%= @resource %>. To increase this limit, please contact support@plausible.io about the Enterprise plan + + """ + end end - defp private_preview_days_remaining do - private_preview_ends_at = Timex.shift(Plausible.Billing.Plans.business_tier_launch(), days: 7) - - days_remaining = Timex.diff(private_preview_ends_at, NaiveDateTime.utc_now(), :day) - - if days_remaining <= 0 do - "today" + 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={Routes.billing_path(PlausibleWeb.Endpoint, :upgrade)}> + upgrade your subscription + + """ else - "in #{days_remaining} days" + ~H""" + please reach out to the site owner to upgrade their subscription + """ end end diff --git a/test/plausible_web/components/billing_test.exs b/test/plausible_web/components/billing_test.exs index aff369bce..3525c1bd2 100644 --- a/test/plausible_web/components/billing_test.exs +++ b/test/plausible_web/components/billing_test.exs @@ -24,9 +24,9 @@ defmodule PlausibleWeb.Components.BillingTest do feature_mod: Plausible.Billing.Feature.Props ) - assert rendered =~ "Custom Properties is part of the Plausible Business plan." + assert rendered =~ "This account does not have access to Custom Properties" assert rendered =~ "upgrade your subscription" - assert rendered =~ "/billing/choose-plan" + assert rendered =~ "/billing/upgrade" end test "premium_feature_notice/1 does not render an upgrade link when user is not the site owner" do @@ -40,10 +40,8 @@ defmodule PlausibleWeb.Components.BillingTest do feature_mod: Plausible.Billing.Feature.Funnels ) - assert rendered =~ - "Funnels is part of the Plausible Business plan. To get access to it, please reach out to the site owner to upgrade your subscription to the Business plan." - - refute rendered =~ "/billing/choose-plan" + assert rendered =~ "This account does not have access to Funnels" + assert rendered =~ "please reach out to the site owner to upgrade their subscription" end test "premium_feature_notice/1 does not render a notice when the user has access to the feature" do @@ -70,9 +68,9 @@ defmodule PlausibleWeb.Components.BillingTest do resource: "users" ) - assert rendered =~ "Your account is limited to 10 users. To increase this limit" + assert rendered =~ "This account is limited to 10 users. To increase this limit" assert rendered =~ "upgrade your subscription" - assert rendered =~ "/billing/choose-plan" + assert rendered =~ "/billing/upgrade" end test "limit_exceeded_notice/1 when billable user is on growth but is not current user does not display upgrade link" do @@ -86,8 +84,8 @@ defmodule PlausibleWeb.Components.BillingTest do resource: "users" ) - assert rendered =~ - "This account is limited to 10 users. To increase this limit, please reach out to the site owner to upgrade their subscription" + assert rendered =~ "This account is limited to 10 users" + assert rendered =~ "please reach out to the site owner to upgrade their subscription" end test "limit_exceeded_notice/1 when billable user is on trial displays upgrade link" do @@ -101,9 +99,9 @@ defmodule PlausibleWeb.Components.BillingTest do resource: "users" ) - assert rendered =~ "Your account is limited to 10 users. To increase this limit" + assert rendered =~ "This account is limited to 10 users" assert rendered =~ "upgrade your subscription" - assert rendered =~ "/billing/choose-plan" + assert rendered =~ "/billing/upgrade" end test "limit_exceeded_notice/1 when billable user is on an enterprise plan displays support email" do diff --git a/test/plausible_web/controllers/site_controller_test.exs b/test/plausible_web/controllers/site_controller_test.exs index 09dbf0425..02bb23387 100644 --- a/test/plausible_web/controllers/site_controller_test.exs +++ b/test/plausible_web/controllers/site_controller_test.exs @@ -271,7 +271,7 @@ defmodule PlausibleWeb.SiteControllerTest do }) assert html = html_response(conn, 200) - assert html =~ "Your account is limited to 10 sites" + assert html =~ "This account is limited to 10 sites" refute Repo.get_by(Plausible.Site, domain: "over-limit.example.com") end