Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Show trial timing in navbar

Uku Tahta20b5592f7c5
diff --git a/lib/plausible/auth/user.ex b/lib/plausible/auth/user.ex
index b75887a056..c14294fd19 100644
--- a/lib/plausible/auth/user.ex
+++ b/lib/plausible/auth/user.ex
@@ -18,6 +18,7 @@ defmodule Plausible.Auth.User do
has_many :site_memberships, Plausible.Site.Membership
has_many :sites, through: [:site_memberships, :site]
has_one :google_auth, Plausible.Site.GoogleAuth
+ has_one :subscription, Plausible.Billing.Subscription
timestamps()
end
diff --git a/lib/plausible_web/auth_plug.ex b/lib/plausible_web/auth_plug.ex
index 7885b13ea6..9261ea9990 100644
--- a/lib/plausible_web/auth_plug.ex
+++ b/lib/plausible_web/auth_plug.ex
@@ -1,5 +1,6 @@
defmodule PlausibleWeb.AuthPlug do
import Plug.Conn
+ use Plausible.Repo
def init(options) do
options
@@ -9,7 +10,8 @@ defmodule PlausibleWeb.AuthPlug do
case get_session(conn, :current_user_id) do
nil -> conn
id ->
- user = Plausible.Auth.find_user_by(id: id)
+ user = Repo.get_by(Plausible.Auth.User, id: id)
+ |> Repo.preload(:subscription)
if user do
assign(conn, :current_user, user)
else
diff --git a/lib/plausible_web/templates/layout/app.html.eex b/lib/plausible_web/templates/layout/app.html.eex
index e715c19a4a..915a483d46 100644
--- a/lib/plausible_web/templates/layout/app.html.eex
+++ b/lib/plausible_web/templates/layout/app.html.eex
@@ -21,9 +21,15 @@
<%= cond do %>
<% @conn.assigns[:current_user] -> %>
<ul class="list-reset flex">
- <li class="mr-6 hidden sm:block">
- <%= link("Give feedback", to: "/feedback", class: "font-bold rounded py-2 px-3 hover:bg-grey-lighter", style: "line-height: 34px;") %>
- </li>
+ <%= if @conn.assigns[:current_user].subscription == nil do %>
+ <li class="mr-6 hidden sm:block">
+ <%= link(trial_notificaton(@conn.assigns[:current_user]), to: "/settings", class: "font-bold text-orange-darkest rounded py-2 px-3 bg-orange-lighter", style: "line-height: 34px;") %>
+ </li>
+ <% else %>
+ <li class="mr-6 hidden sm:block">
+ <%= link("Give feedback", to: "/feedback", class: "font-bold rounded py-2 px-3 hover:bg-grey-lighter", style: "line-height: 34px;") %>
+ </li>
+ <% end %>
<li>
<div class="relative font-bold rounded hover:bg-grey-lighter">
<div data-dropdown-trigger class="flex items-center hover:bg-grey-lighter rounded p-2 cursor-pointer">
diff --git a/lib/plausible_web/views/layout_view.ex b/lib/plausible_web/views/layout_view.ex
index 7e7699b110..a62957b502 100644
--- a/lib/plausible_web/views/layout_view.ex
+++ b/lib/plausible_web/views/layout_view.ex
@@ -1,3 +1,16 @@
defmodule PlausibleWeb.LayoutView do
use PlausibleWeb, :view
+
+ def trial_notificaton(user) do
+ case Plausible.Billing.trial_days_left(user) do
+ days when days > 1 ->
+ "#{days} trial days left"
+ days when days == 1 ->
+ "Trial ends tomorrow"
+ days when days == 0 ->
+ "Trial ends today"
+ days when days < 0 ->
+ "Trial over, upgrade now"
+ end
+ end
end