Show trial timing in navbar

This commit is contained in:
Uku Taht 2019-09-11 17:04:37 +01:00
parent 1417ed1927
commit a20b5592f7
4 changed files with 26 additions and 4 deletions

View File

@ -18,6 +18,7 @@ defmodule Plausible.Auth.User do
has_many :site_memberships, Plausible.Site.Membership has_many :site_memberships, Plausible.Site.Membership
has_many :sites, through: [:site_memberships, :site] has_many :sites, through: [:site_memberships, :site]
has_one :google_auth, Plausible.Site.GoogleAuth has_one :google_auth, Plausible.Site.GoogleAuth
has_one :subscription, Plausible.Billing.Subscription
timestamps() timestamps()
end end

View File

@ -1,5 +1,6 @@
defmodule PlausibleWeb.AuthPlug do defmodule PlausibleWeb.AuthPlug do
import Plug.Conn import Plug.Conn
use Plausible.Repo
def init(options) do def init(options) do
options options
@ -9,7 +10,8 @@ defmodule PlausibleWeb.AuthPlug do
case get_session(conn, :current_user_id) do case get_session(conn, :current_user_id) do
nil -> conn nil -> conn
id -> id ->
user = Plausible.Auth.find_user_by(id: id) user = Repo.get_by(Plausible.Auth.User, id: id)
|> Repo.preload(:subscription)
if user do if user do
assign(conn, :current_user, user) assign(conn, :current_user, user)
else else

View File

@ -21,9 +21,15 @@
<%= cond do %> <%= cond do %>
<% @conn.assigns[:current_user] -> %> <% @conn.assigns[:current_user] -> %>
<ul class="list-reset flex"> <ul class="list-reset flex">
<li class="mr-6 hidden sm:block"> <%= if @conn.assigns[:current_user].subscription == nil do %>
<%= link("Give feedback", to: "/feedback", class: "font-bold rounded py-2 px-3 hover:bg-grey-lighter", style: "line-height: 34px;") %> <li class="mr-6 hidden sm:block">
</li> <%= 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> <li>
<div class="relative font-bold rounded hover:bg-grey-lighter"> <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"> <div data-dropdown-trigger class="flex items-center hover:bg-grey-lighter rounded p-2 cursor-pointer">

View File

@ -1,3 +1,16 @@
defmodule PlausibleWeb.LayoutView do defmodule PlausibleWeb.LayoutView do
use PlausibleWeb, :view 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 end