From fdf1462c04c51df30fc7ce569b3a339fe622d926 Mon Sep 17 00:00:00 2001 From: RobertJoonas <56999674+RobertJoonas@users.noreply.github.com> Date: Mon, 13 Nov 2023 16:19:58 +0000 Subject: [PATCH] Notice across the app about Funnels and Revenue goals private preview end (#3510) * change upgrade CTA notice message for enterprise and business plans * add dismissable option to Generic.notice * more general notice about losing premium features in X days * save notice dismissed per user ... more than one Plausible account can use the same device, so we should scope the fact that the notice has been dismissed by user id. * fix bug applying classes to Generic.notice * apply shadow to the new notice on light mode * use Heroicons.x_mark instead of raw SVG * use Enum.filter instead of list comprehension --- lib/plausible_web/components/billing.ex | 62 ++++++++++++---- lib/plausible_web/components/generic.ex | 73 ++++++++++++------- .../templates/layout/_notice.html.heex | 20 +++-- .../plausible_web/components/billing_test.exs | 4 +- 4 files changed, 106 insertions(+), 53 deletions(-) diff --git a/lib/plausible_web/components/billing.ex b/lib/plausible_web/components/billing.ex index d4abc1276..10f86458b 100644 --- a/lib/plausible_web/components/billing.ex +++ b/lib/plausible_web/components/billing.ex @@ -4,9 +4,10 @@ defmodule PlausibleWeb.Components.Billing do use Phoenix.Component import PlausibleWeb.Components.Generic require Plausible.Billing.Subscription.Status + alias Plausible.Billing.Feature.{RevenueGoals, Funnels} alias Plausible.Billing.Feature.{Props, StatsAPI} alias PlausibleWeb.Router.Helpers, as: Routes - alias Plausible.Billing.{Subscription, Plans, Subscriptions} + alias Plausible.Billing.{Subscription, Plans, Plan, Subscriptions} attr(:billable_user, Plausible.Auth.User, required: true) attr(:current_user, Plausible.Auth.User, required: true) @@ -17,15 +18,10 @@ defmodule PlausibleWeb.Components.Billing do # credo:disable-for-next-line Credo.Check.Refactor.CyclomaticComplexity 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) - business? = plan && plan.kind == :business - legacy_feature_access? = Timex.before?(assigns.billable_user.inserted_at, Plans.business_tier_launch()) && assigns.feature_mod in [StatsAPI, Props] - private_preview? = FunWithFlags.enabled?(:premium_features_private_preview) has_access? = assigns.feature_mod.check_availability(assigns.billable_user) == :ok cond do @@ -39,14 +35,6 @@ defmodule PlausibleWeb.Components.Billing do """ - 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}> @@ -60,7 +48,7 @@ defmodule PlausibleWeb.Components.Billing do end end - defp private_preview_days_remaining do + defp private_preview_end do private_preview_ends_at = Timex.shift(Plausible.Billing.Plans.business_tier_launch(), days: 8) days_remaining = Timex.diff(private_preview_ends_at, NaiveDateTime.utc_now(), :day) @@ -113,7 +101,7 @@ defmodule PlausibleWeb.Components.Billing do """ true -> - ~H"please contact support@plausible.io about the Enterprise plan" + ~H"please contact hello@plausible.io to upgrade your subscription" end end @@ -317,6 +305,48 @@ defmodule PlausibleWeb.Components.Billing do def subscription_paused_notice(assigns), do: ~H"" + def private_preview_end_notice(assigns) do + user = assigns.user |> Plausible.Users.with_subscription() + + features_to_lose = + case Plans.get_subscription_plan(user.subscription) do + nil -> + [] + + %Plan{kind: :business} -> + [] + + _free_10k_or_enterprise_or_growth -> + used_features = Plausible.Billing.Quota.features_usage(assigns.user) + Enum.filter([Funnels, RevenueGoals], &(&1 in used_features)) + end + + assigns = assign(assigns, :features_to_lose, features_to_lose) + + ~H""" +
- <%= render_slot(@inner_block) %> -
++ <%= render_slot(@inner_block) %> +
+