diff --git a/lib/plausible/site/memberships/invitations.ex b/lib/plausible/site/memberships/invitations.ex index f51e5beb9..a1a543668 100644 --- a/lib/plausible/site/memberships/invitations.ex +++ b/lib/plausible/site/memberships/invitations.ex @@ -6,6 +6,15 @@ defmodule Plausible.Site.Memberships.Invitations do alias Plausible.Auth alias Plausible.Repo + @spec list_for_email(String.t()) :: [Auth.Invitation.t()] + def list_for_email(email) do + Repo.all( + from i in Auth.Invitation, + where: i.email == ^email + ) + |> Repo.preload(:site) + end + @spec find_for_user(String.t(), Auth.User.t()) :: {:ok, Auth.Invitation.t()} | {:error, :invitation_not_found} def find_for_user(invitation_id, user) do diff --git a/lib/plausible_web/live/sites.ex b/lib/plausible_web/live/sites.ex index 30f87135c..795843ac3 100644 --- a/lib/plausible_web/live/sites.ex +++ b/lib/plausible_web/live/sites.ex @@ -8,23 +8,77 @@ defmodule PlausibleWeb.Live.Sites do alias Plausible.Auth alias Plausible.Repo + alias Plausible.Site.Memberships.Invitations alias Plausible.Sites def mount(params, %{"current_user_id" => user_id}, socket) do socket = socket |> assign_new(:user, fn -> Repo.get!(Auth.User, user_id) end) - |> assign_new(:sites, fn %{user: user} -> Sites.list(user, params) end) + |> assign_new(:invitations, fn %{user: user} -> + Invitations.list_for_email(user.email) + end) + |> assign_new(:sites, fn %{user: user, invitations: invitations} -> + excluded_site_ids = Enum.map(invitations, & &1.site_id) + Sites.list(user, params, excluded_site_ids) + end) |> assign_new(:visitors, fn %{sites: sites} -> Plausible.Stats.Clickhouse.last_24h_visitors(sites.entries) end) + |> assign_new(:needs_to_upgrade, fn %{user: user, sites: sites} -> + user_owns_sites = + Enum.any?(sites.entries, fn site -> List.first(site.memberships).role == :owner end) || + Auth.user_owns_sites?(user) + + user_owns_sites && Plausible.Billing.check_needs_to_upgrade(user) + end) {:ok, socket} end def render(assigns) do ~H""" -
+ To access the sites you own, you need to subscribe to a monthly or yearly payment plan. <%= link( + "Upgrade now →", + to: "/settings", + class: "text-sm font-medium text-yellow-800" + ) %> +
+You don't have any sites yet
<% end %> + <%= for invitation <- @invitations do %> ++ You've been invited to the + + analytics dashboard as Admin. +
+
+ If you accept the ownership transfer, you will be responsible for billing going forward.
+ <%= if is_nil(@user.trial_expiry_date) && is_nil(@user.subscription) do %>
+
+ You will have to enter your card details immediately with no 30-day trial.
+ <% end %>
+ <%= if Plausible.Billing.on_trial?(@user) do %>
+
NB: Your 30-day free trial will end immediately and
+ you will have to enter your card details
+ to keep using Plausible.
+ <% end %>
+