defmodule PlausibleWeb.Components.Billing.Notice do @moduledoc false use Phoenix.Component require Plausible.Billing.Subscription.Status import PlausibleWeb.Components.Generic alias PlausibleWeb.Router.Helpers, as: Routes alias Plausible.Auth.User alias Plausible.Billing.{Subscription, Plans, Subscriptions, Feature} def active_grace_period(assigns) do if assigns.enterprise? do ~H""" """ else ~H""" """ end end def dashboard_locked(assigns) do ~H""" """ end attr(:billable_user, User, required: true) attr(:current_user, User, required: true) attr(:feature_mod, :atom, required: true, values: Feature.list()) attr(:grandfathered?, :boolean, default: false) attr(:size, :atom, default: :sm) attr(:rest, :global) def premium_feature(assigns) do ~H""" <.notice :if={@feature_mod.check_availability(@billable_user) !== :ok} class="rounded-t-md rounded-b-none" size={@size} title="Notice" {@rest} > <%= account_label(@current_user, @billable_user) %> does not have access to <%= @feature_mod.display_name() %>. To get access to this feature, <.upgrade_call_to_action current_user={@current_user} billable_user={@billable_user} />. """ end attr(:billable_user, User, required: true) attr(:current_user, User, required: true) attr(:limit, :integer, required: true) attr(:resource, :string, required: true) attr(:rest, :global) def limit_exceeded(assigns) do ~H""" <.notice {@rest} title="Notice"> <%= 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} />. """ end attr(:user, :map, required: true) attr(:dismissable, :boolean, default: true) @doc """ Given a user with a cancelled subscription, this component renders a cancelled subscription notice. If the given user does not have a subscription or it has a different status, this function returns an empty template. It also takes a dismissable argument which renders the notice dismissable (with the help of JavaScript and localStorage). We show a dismissable notice about a cancelled subscription across the app, but when the user dismisses it, we will start displaying it in the account settings > subscription section instead. So it's either shown across the app, or only on the /settings page. Depending on whether the localStorage flag to dismiss it has been set or not. """ def subscription_cancelled(assigns) def subscription_cancelled( %{ dismissable: true, user: %User{subscription: %Subscription{status: Subscription.Status.deleted()}} } = assigns ) do ~H""" """ end def subscription_cancelled( %{ dismissable: false, user: %User{subscription: %Subscription{status: Subscription.Status.deleted()}} } = assigns ) do assigns = assign(assigns, :container_id, "local-subscription-cancelled-notice") ~H""" """ end def subscription_cancelled(assigns), do: ~H"" attr(:class, :string, default: "") attr(:subscription, :any, default: nil) def subscription_past_due( %{subscription: %Subscription{status: Subscription.Status.past_due()}} = assigns ) do ~H""" """ end def subscription_past_due(assigns), do: ~H"" attr(:class, :string, default: "") attr(:subscription, :any, default: nil) def subscription_paused( %{subscription: %Subscription{status: Subscription.Status.paused()}} = assigns ) do ~H""" """ end def subscription_paused(assigns), do: ~H"" def upgrade_ineligible(assigns) do ~H""" """ end def growth_grandfathered(assigns) do ~H"""
Your subscription has been grandfathered in at the same rate and terms as when you first joined. If you don't need the "Business" features, you're welcome to stay on this plan. You can adjust the pageview limit or change the billing frequency of this grandfathered plan. If you're interested in business features, you can upgrade to the new "Business" plan.
""" end defp subscription_cancelled_notice_body(assigns) do if Subscriptions.expired?(assigns.user.subscription) do ~H""" <.link class="underline inline-block" href={Routes.billing_path(PlausibleWeb.Endpoint, :choose_plan)} > Upgrade your subscription to get access to your stats again. """ else ~H"""

You have access to your stats until <%= Timex.format!(@user.subscription.next_bill_date, "{Mshort} {D}, {YYYY}") %>. <.link class="underline inline-block" href={Routes.billing_path(PlausibleWeb.Endpoint, :choose_plan)} > Upgrade your subscription to make sure you don't lose access.

<.lose_grandfathering_warning user={@user} /> """ end end defp lose_grandfathering_warning(%{user: %{subscription: subscription}} = assigns) do plan = Plans.get_regular_plan(subscription, only_non_expired: true) loses_grandfathering = plan && plan.generation < 4 assigns = assign(assigns, :loses_grandfathering, loses_grandfathering) ~H"""

Please also note that by letting your subscription expire, you lose access to our grandfathered terms. If you want to subscribe again after that, your account will be offered the <.link href="https://plausible.io/#pricing" target="_blank" rel="noopener noreferrer" class="underline" >latest pricing.

""" 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 = Plans.get_regular_plan(billable_user.subscription, only_non_expired: true) trial? = Plausible.Users.on_trial?(assigns.billable_user) growth? = plan && plan.kind == :growth 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={Routes.billing_path(PlausibleWeb.Endpoint, :choose_plan)} > upgrade your subscription """ true -> ~H""" please contact hello@plausible.io to upgrade your subscription """ end end defp account_label(current_user, billable_user) do if current_user.id == billable_user.id do "Your account" else "The owner of this site" end end end