<%= 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"""
<.styled_link
:if={@subscription.status == Subscription.Status.active()}
href={Routes.billing_path(PlausibleWeb.Endpoint, :change_plan_form)}
class="text-sm font-medium"
>
Change plan
Change plan
<% else %>
Free trial
<.styled_link
href={Routes.billing_path(PlausibleWeb.Endpoint, :upgrade)}
class="text-sm font-medium"
>
Upgrade
<% end %>
"""
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_notice(assigns)
def subscription_cancelled_notice(
%{
dismissable: true,
user: %User{subscription: %Subscription{status: Subscription.Status.deleted()}}
} = assigns
) do
~H"""
"""
end
def subscription_cancelled_notice(
%{
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_notice(assigns), do: ~H""
attr(:class, :string, default: "")
attr(:subscription, :any, default: nil)
def subscription_past_due_notice(
%{subscription: %Subscription{status: Subscription.Status.past_due()}} = assigns
) do
~H"""
"""
end
def subscription_past_due_notice(assigns), do: ~H""
attr(:class, :string, default: "")
attr(:subscription, :any, default: nil)
def subscription_paused_notice(
%{subscription: %Subscription{status: Subscription.Status.paused()}} = assigns
) do
~H"""
"""
end
def subscription_paused_notice(assigns), do: ~H""
def present_enterprise_plan(assigns) do
~H"""
Up to <%= present_limit(@plan, :monthly_pageview_limit) %> monthly pageviews
Up to <%= present_limit(@plan, :site_limit) %> sites
Up to <%= present_limit(@plan, :hourly_api_request_limit) %> hourly api requests
"""
end
defp present_limit(enterprise_plan, key) do
enterprise_plan
|> Map.fetch!(key)
|> PlausibleWeb.StatsView.large_number_format()
end
@spec format_price(Money.t()) :: String.t()
def format_price(money) do
Money.to_string!(money, fractional_digits: 2, no_fraction_if_integer: true)
end
attr :id, :string, required: true
attr :paddle_product_id, :string, required: true
attr :checkout_disabled, :boolean, default: false
attr :user, :map, required: true
attr :confirm_message, :any, default: nil
slot :inner_block, required: true
def paddle_button(assigns) do
confirmed =
if assigns.confirm_message, do: "confirm(\"#{assigns.confirm_message}\")", else: "true"
assigns = assign(assigns, :confirmed, confirmed)
~H"""
"""
end
def paddle_script(assigns) do
~H"""
"""
end
def upgrade_link(%{business_tier: true} = assigns) do
~H"""
Upgrade
"""
end
def upgrade_link(assigns) do
~H"""
Upgrade
"""
end
defp subscription_cancelled_notice_body(assigns) do
if Plausible.Billing.Subscriptions.expired?(assigns.user.subscription) do
~H"""
<.link class="underline inline-block" href={Plausible.Billing.upgrade_route_for(@user)}>
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={Plausible.Billing.upgrade_route_for(@user)}>
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} = user} = assigns) do
business_tiers_available? = FunWithFlags.enabled?(:business_tier, for: user)
plan = Plans.get_regular_plan(subscription, only_non_expired: true)
loses_grandfathering = business_tiers_available? && 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
defp change_plan_or_upgrade_text(nil), do: "Upgrade"
defp change_plan_or_upgrade_text(%Subscription{status: Subscription.Status.deleted()}),
do: "Upgrade"
defp change_plan_or_upgrade_text(_subscription), do: "Change plan"
end