defmodule PlausibleWeb.Components.Billing do
@moduledoc false
use Phoenix.Component
import PlausibleWeb.Components.Generic
require Plausible.Billing.Subscription.Status
alias PlausibleWeb.Router.Helpers, as: Routes
alias Plausible.Billing.Subscription
attr(:billable_user, Plausible.Auth.User, required: true)
attr(:current_user, Plausible.Auth.User, required: true)
attr(:feature_mod, :atom, required: true, values: Plausible.Billing.Feature.list())
attr(:grandfathered?, :boolean, default: false)
attr(:size, :atom, default: :sm)
attr(:rest, :global)
# credo:disable-for-next-line Credo.Check.Refactor.CyclomaticComplexity
def premium_feature_notice(assigns) do
private_preview? = not FunWithFlags.enabled?(:business_tier, for: assigns.current_user)
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
private_preview? && assigns.grandfathered? ->
"#{assigns.feature_mod.display_name()} is an upcoming premium functionality that's free-to-use during the private preview. Existing subscribers will be grandfathered and will keep having access to this feature without any change to their plan."
private_preview? ->
"#{assigns.feature_mod.display_name()} is an upcoming premium functionality that's free-to-use during the private preview. Pricing will be announced soon."
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."
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" href={Routes.billing_path(PlausibleWeb.Endpoint, :upgrade)}>
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."
true ->
nil
end
assigns = assign(assigns, :message, message)
~H"""
<.notice :if={@message} class="rounded-t-md rounded-b-none" size={@size} {@rest}>
<%= @message %>
"""
end
slot(:inner_block, required: true)
attr(:rest, :global)
def usage_and_limits_table(assigns) do
~H"""
<%= render_quota(@usage) %>
<%= if @limit, do: "/ #{render_quota(@limit)}" %>
"""
end
defp render_quota(quota) do
case quota do
quota when is_number(quota) -> Cldr.Number.to_string!(quota)
:unlimited -> "∞"
nil -> ""
end
end
def monthly_quota_box(%{business_tier: true} = assigns) do
~H"""