Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/plausible_web/templates/auth/user_settings.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@

<div class="flex flex-col items-center sm:flex-row sm:items-start justify-between mt-8">
<div class="text-center bg-gray-100 py-4 px-2 rounded h-32 my-4" style="width: 11.75rem;">
<h4 class="font-black">Current plan</h4>
<h4 class="font-black">Monthly quota</h4>
<%= if @subscription do %>
<div class="text-xl py-2 font-medium"><%= subscription_name(@subscription) %></div>
<div class="text-xl py-2 font-medium"><%= subscription_quota(@subscription) %> pageviews</div>
<%= case @subscription.status do %>
<% "active" -> %>
<%= link("Change plan", to: "/billing/change-plan", class: "text-sm text-indigo-500 font-medium") %>
Expand Down Expand Up @@ -63,6 +63,7 @@

<%= if @subscription && @subscription.next_bill_date && @subscription.status in ["active", "past_due"] do %>
<div class="text-xl py-2 font-medium"><%= Timex.format!(@subscription.next_bill_date, "{Mshort} {D}, {YYYY}") %></div>
<div class="text-sm text-gray-600 font-medium">(<%= subscription_interval(@subscription) %> billing)</div>
<% else %>
<div class="text-xl py-2 font-medium">---</div>
<% end %>
Expand Down
51 changes: 31 additions & 20 deletions lib/plausible_web/views/auth_view.ex
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
defmodule PlausibleWeb.AuthView do
use PlausibleWeb, :view

@subscription_names %{
"558018" => "10k / monthly",
"558745" => "100k / monthly",
"597485" => "200k / monthly",
"597487" => "500k / monthly",
"597642" => "1m / monthly",
"558746" => "1m / monthly / grandfathered",
"597309" => "2m / monthly",
"597311" => "5m / monthly",
"572810" => "10k / yearly",
"590752" => "100k / yearly",
"597486" => "200k / yearly",
"597488" => "500k / yearly",
"597643" => "1m / yearly",
"590753" => "1m / yearly / grandfathered",
"597310" => "2m / yearly",
"597312" => "5m / yearly",
"free_10k" => "10k / free"
@monthly_plans ["558018", "558745", "597485", "597487", "597642", "558746", "597309", "597311"]
@yearly_plans ["572810", "590752", "597486", "597488", "597643", "590753", "597310", "597312"]

@subscription_quotas %{
"558018" => "10k",
"558745" => "100k",
"597485" => "200k",
"597487" => "500k",
"597642" => "1m",
"558746" => "1m",
"597309" => "2m",
"597311" => "5m",
"572810" => "10k",
"590752" => "100k",
"597486" => "200k",
"597488" => "500k",
"597643" => "1m",
"590753" => "1m",
"597310" => "2m",
"597312" => "5m",
"free_10k" => "10k"
}

def admin_email do
Expand All @@ -33,8 +36,16 @@ defmodule PlausibleWeb.AuthView do
PlausibleWeb.Endpoint.clean_url()
end

def subscription_name(subscription) do
@subscription_names[subscription.paddle_plan_id]
def subscription_quota(subscription) do
@subscription_quotas[subscription.paddle_plan_id]
end

def subscription_interval(subscription) do
cond do
subscription.paddle_plan_id in @monthly_plans -> "monthly"
subscription.paddle_plan_id in @yearly_plans -> "yeary"
true -> raise "Unknown interval for subscription #{subscription.paddle_plan_id}"
end
end

def delimit_integer(number) do
Expand Down
7 changes: 7 additions & 0 deletions test/plausible_web/controllers/auth_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ defmodule PlausibleWeb.AuthControllerTest do
conn = get(conn, "/settings")
assert html_response(conn, 200) =~ "Account settings"
end

test "shows subscription", %{conn: conn, user: user} do
insert(:subscription, paddle_plan_id: "558018", user: user)
conn = get(conn, "/settings")
assert html_response(conn, 200) =~ "10k pageviews"
assert html_response(conn, 200) =~ "monthly billing"
end
end

describe "PUT /settings" do
Expand Down