mirror of
https://github.com/plausible/analytics.git
synced 2024-12-22 09:01:40 +03:00
Show trial timing in navbar
This commit is contained in:
parent
1417ed1927
commit
a20b5592f7
@ -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
|
||||
|
@ -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
|
||||
|
@ -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">
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user