defmodule PlausibleWeb.Components.Billing do
@moduledoc false
use PlausibleWeb, :component
use Plausible
require Plausible.Billing.Subscription.Status
alias Plausible.Billing.{Subscription, Subscriptions, Plan, Plans, EnterprisePlan}
attr :current_role, :atom, required: true
attr :current_team, :any, required: true
attr :locked?, :boolean, required: true
slot :inner_block, required: true
def feature_gate(assigns) do
~H"""
<.title>Monthly pageviews usage
<.billing_cycle_tab
name="Upcoming cycle"
tab={:current_cycle}
date_range={@usage.current_cycle.date_range}
with_separator={true}
/>
<.billing_cycle_tab
name="Last cycle"
tab={:last_cycle}
date_range={@usage.last_cycle.date_range}
with_separator={true}
/>
<.billing_cycle_tab
name="Penultimate cycle"
tab={:penultimate_cycle}
date_range={@usage.penultimate_cycle.date_range}
disabled={@usage.penultimate_cycle.total == 0}
/>
<.monthly_pageview_usage_table
usage={@usage.current_cycle}
limit={@limit}
period={:current_cycle}
/>
<.monthly_pageview_usage_table usage={@usage.last_cycle} limit={@limit} period={:last_cycle} />
<.monthly_pageview_usage_table
usage={@usage.penultimate_cycle}
limit={@limit}
period={:penultimate_cycle}
/>
"""
end
attr(:usage, :map, required: true)
attr(:limit, :any, required: true)
attr(:period, :atom, required: true)
defp monthly_pageview_usage_table(assigns) do
~H"""
<.usage_and_limits_table>
<.usage_and_limits_row
id={"total_pageviews_#{@period}"}
title={"Total billable pageviews#{if @period == :last_30_days, do: " (last 30 days)"}"}
usage={@usage.total}
limit={@limit}
/>
<.usage_and_limits_row
id={"pageviews_#{@period}"}
pad
title="Pageviews"
usage={@usage.pageviews}
/>
<.usage_and_limits_row
id={"custom_events_#{@period}"}
pad
title="Custom events"
usage={@usage.custom_events}
/>
"""
end
attr(:name, :string, required: true)
attr(:date_range, :any, required: true)
attr(:tab, :atom, required: true)
attr(:disabled, :boolean, default: false)
attr(:with_separator, :boolean, default: false)
defp billing_cycle_tab(assigns) do
~H"""
Monthly quota
{PlausibleWeb.AuthView.subscription_quota(@subscription, format: :long)}
<.styled_link
:if={
not (Plausible.Teams.Billing.enterprise_configured?(@team) &&
Subscriptions.halted?(@subscription))
}
id="#upgrade-or-change-plan-link"
href={Routes.billing_path(PlausibleWeb.Endpoint, :choose_plan)}
>
{change_plan_or_upgrade_text(@subscription)}
"""
end
def present_enterprise_plan(assigns) do
~H"""