defmodule PlausibleWeb.Live.Sites do @moduledoc """ LiveView for sites index. """ use Phoenix.LiveView use PlausibleWeb.Live.Flash alias Phoenix.LiveView.JS use Phoenix.HTML import PlausibleWeb.Components.Generic import PlausibleWeb.Live.Components.Pagination alias Plausible.Auth alias Plausible.Repo alias Plausible.Site alias Plausible.Sites def mount(params, %{"current_user_id" => user_id}, socket) do uri = ("/sites?" <> URI.encode_query(Map.take(params, ["filter_text"]))) |> URI.new!() socket = socket |> assign(:uri, uri) |> assign(:filter_text, params["filter_text"] || "") |> assign(:user, Repo.get!(Auth.User, user_id)) {:ok, socket} end def handle_params(params, _uri, socket) do socket = socket |> assign(:params, params) |> load_sites() |> assign_new(:has_sites?, fn %{user: user} -> Site.Memberships.any_or_pending?(user) end) |> assign_new(:needs_to_upgrade, fn %{user: user, sites: sites} -> user_owns_sites = Enum.any?(sites.entries, fn site -> List.first(site.memberships ++ site.invitations).role == :owner end) || Auth.user_owns_sites?(user) user_owns_sites && Plausible.Billing.check_needs_to_upgrade(user) end) {:noreply, socket} end def render(assigns) do invitations = assigns.sites.entries |> Enum.filter(&(&1.entry_type == "invitation")) |> Enum.flat_map(& &1.invitations) assigns = assign(assigns, :invitations, invitations) ~H""" <.flash_messages flash={@flash} />
You don't have any sites yet.
No sites found. Please search for something else.
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" ) %>
<%= PlausibleWeb.StatsView.large_number_format(@hourly_stats.visitors) %> visitors in last 24h
<.percentage_change change={@hourly_stats.change} />〰 0} class="font-semibold text-green-500">↑ ↓ <%= abs(@change) %>%
""" end attr :user, Plausible.Auth.User, required: true def invitation_modal(assigns) do ~H"""You've been invited to the analytics dashboard as Admin.