Skip to content

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

Use Prima for invitation modal (#5843)

Uku Taht16cbc07f3db9
diff --git a/assets/js/liveview/live_socket.js b/assets/js/liveview/live_socket.js
index 37bbfc5164..135372826d 100644
--- a/assets/js/liveview/live_socket.js
+++ b/assets/js/liveview/live_socket.js
@@ -1,11 +1,12 @@
/**
- These 3 modules are resolved from '../deps' folder,
- which does not exist when running the lint command in Github CI
+ The modules below this comment block are resolved from '../deps' folder,
+ which does not exist when running the lint command in Github CI
*/
/* eslint-disable import/no-unresolved */
import 'phoenix_html'
import { Socket } from 'phoenix'
import { LiveSocket } from 'phoenix_live_view'
+import { Modal } from 'prima'
import topbar from 'topbar'
/* eslint-enable import/no-unresolved */
@@ -14,7 +15,7 @@ import Alpine from 'alpinejs'
let csrfToken = document.querySelector("meta[name='csrf-token']")
let websocketUrl = document.querySelector("meta[name='websocket-url']")
if (csrfToken && websocketUrl) {
- let Hooks = {}
+ let Hooks = { Modal }
Hooks.Metrics = {
mounted() {
this.handleEvent('send-metrics', ({ event_name }) => {
diff --git a/lib/plausible_web/components/generic.ex b/lib/plausible_web/components/generic.ex
index 45d0c89d87..94ee011400 100644
--- a/lib/plausible_web/components/generic.ex
+++ b/lib/plausible_web/components/generic.ex
@@ -1060,10 +1060,11 @@ defmodule PlausibleWeb.Components.Generic do
slot :inner_block, required: true
attr :class, :any, default: nil
+ attr :rest, :global
def h2(assigns) do
~H"""
- <h2 class={[@class || "font-semibold leading-6 text-gray-900 dark:text-gray-100"]}>
+ <h2 class={[@class || "font-semibold leading-6 text-gray-900 dark:text-gray-100"]} {@rest}>
{render_slot(@inner_block)}
</h2>
"""
diff --git a/lib/plausible_web/live/components/prima_modal.ex b/lib/plausible_web/live/components/prima_modal.ex
new file mode 100644
index 0000000000..2975071c91
--- /dev/null
+++ b/lib/plausible_web/live/components/prima_modal.ex
@@ -0,0 +1,49 @@
+defmodule PlausibleWeb.Live.Components.PrimaModal do
+ @moduledoc false
+ use PlausibleWeb, :component
+ alias Prima.Modal
+
+ attr :id, :string, required: true
+ slot :inner_block, required: true
+
+ def modal(assigns) do
+ ~H"""
+ <Modal.modal id={@id}>
+ <Modal.modal_overlay
+ transition_enter={{"ease-out duration-300", "opacity-0", "opacity-100"}}
+ transition_leave={{"ease-in duration-200", "opacity-100", "opacity-0"}}
+ class="fixed inset-0 bg-gray-500/75 dark:bg-gray-800/75"
+ />
+
+ <div class="fixed inset-0 w-screen overflow-y-auto">
+ <div class="flex min-h-full items-end justify-center p-4 sm:items-center sm:p-0">
+ <Modal.modal_panel
+ id={@id <> "-panel"}
+ class="relative overflow-hidden rounded-lg bg-white dark:bg-gray-900 text-left shadow-xl sm:w-full sm:max-w-lg"
+ transition_enter={
+ {"ease-out duration-300", "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95",
+ "opacity-100 translate-y-0 sm:scale-100"}
+ }
+ transition_leave={
+ {"ease-in duration-200", "opacity-100 translate-y-0 sm:scale-100",
+ "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"}
+ }
+ >
+ {render_slot(@inner_block)}
+ </Modal.modal_panel>
+ </div>
+ </div>
+ </Modal.modal>
+ """
+ end
+
+ slot :inner_block, required: true
+
+ def modal_title(assigns) do
+ ~H"""
+ <Modal.modal_title as={&h2/1}>
+ {render_slot(@inner_block)}
+ </Modal.modal_title>
+ """
+ end
+end
diff --git a/lib/plausible_web/live/sites.ex b/lib/plausible_web/live/sites.ex
index 571fd01af2..fe32464933 100644
--- a/lib/plausible_web/live/sites.ex
+++ b/lib/plausible_web/live/sites.ex
@@ -54,14 +54,16 @@ defmodule PlausibleWeb.Live.Sites do
end
def render(assigns) do
+ assigns =
+ assign(
+ assigns,
+ :invitations_map,
+ Enum.map(assigns.invitations, &{&1.invitation.invitation_id, &1}) |> Enum.into(%{})
+ )
+
~H"""
<.flash_messages flash={@flash} />
- <div
- x-ref="invitation_data"
- x-data={"{selectedInvitation: null, invitationOpen: false, invitations: #{Enum.map(@invitations, &({&1.invitation.invitation_id, &1})) |> Enum.into(%{}) |> Jason.encode!}}"}
- x-on:keydown.escape.window="invitationOpen = false"
- class="container pt-6"
- >
+ <div class="container pt-6">
<PlausibleWeb.Live.Components.Visitors.gradient_defs />
<.upgrade_nag_screen :if={
@needs_to_upgrade == {:needs_to_upgrade, :no_active_trial_or_subscription}
@@ -131,7 +133,7 @@ defmodule PlausibleWeb.Live.Sites do
<.invitation
:if={site.entry_type == "invitation"}
site={site}
- invitation={hd(site.invitations)}
+ invitation={@invitations_map[hd(site.invitations).invitation_id]}
hourly_stats={Map.get(@hourly_stats, site.domain, :loading)}
/>
<% end %>
@@ -146,7 +148,6 @@ defmodule PlausibleWeb.Live.Sites do
>
Total of <span class="font-medium">{@sites.total_entries}</span> sites
</.pagination>
- <.invitation_modal :if={Enum.any?(@sites.entries, &(&1.entry_type == "invitation"))} />
</div>
</div>
"""
@@ -321,12 +322,16 @@ defmodule PlausibleWeb.Live.Sites do
attr(:hourly_stats, :map, required: true)
def invitation(assigns) do
+ assigns =
+ assigns
+ |> assign(:modal_id, "invitation-modal-#{assigns[:invitation].invitation.invitation_id}")
+
~H"""
<li
class="group relative cursor-pointer"
id={"site-card-#{hash_domain(@site.domain)}"}
data-domain={@site.domain}
- x-on:click={"invitationOpen = true; selectedInvitation = invitations['#{@invitation.invitation_id}']"}
+ phx-click={Prima.Modal.open(@modal_id)}
>
<div class="col-span-1 flex flex-col gap-y-5 bg-white dark:bg-gray-900 rounded-md shadow-sm p-6 group-hover:shadow-lg cursor-pointer transition duration-100">
<div class="w-full flex items-center justify-between gap-x-2.5">
@@ -342,6 +347,7 @@ defmodule PlausibleWeb.Live.Sites do
</div>
<.site_stats hourly_stats={@hourly_stats} />
</div>
+ <.invitation_modal id={@modal_id} site={@site} invitation={@invitation} />
</li>
"""
end
@@ -547,157 +553,121 @@ defmodule PlausibleWeb.Live.Sites do
"""
end
+ attr(:id, :string, required: true)
+ attr(:site, Plausible.Site, required: true)
+ attr(:invitation, :map, required: true)
+
def invitation_modal(assigns) do
~H"""
- <div
- x-cloak
- x-show="invitationOpen"
- class="fixed z-10 inset-0 overflow-y-auto"
- aria-labelledby="modal-title"
- role="dialog"
- aria-modal="true"
- >
- <div class="flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0">
- <div
- x-show="invitationOpen"
- x-transition:enter="transition ease-out duration-300"
- x-transition:enter-start="opacity-0"
- x-transition:enter-end="opacity-100"
- x-transition:leave="transition ease-in duration-200"
- x-transition:leave-start="opacity-100"
- x-transition:leave-end="opacity-0"
- class="fixed inset-0 bg-gray-500/75 dark:bg-gray-800/75 transition-opacity"
- aria-hidden="true"
- x-on:click="invitationOpen = false"
- >
+ <PlausibleWeb.Live.Components.PrimaModal.modal id={@id}>
+ <div class="bg-white dark:bg-gray-850 px-4 pt-5 pb-4 sm:p-6 sm:pb-4">
+ <div class="hidden sm:block absolute top-0 right-0 pt-4 pr-4">
+ <button
+ phx-click={Prima.Modal.close()}
+ class="bg-white dark:bg-gray-800 rounded-md text-gray-400 dark:text-gray-500 hover:text-gray-500 dark:hover:text-gray-400 focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-indigo-500"
+ >
+ <span class="sr-only">Close</span>
+ <Heroicons.x_mark class="size-6" />
+ </button>
</div>
- <!-- This element is to trick the browser into centering the modal contents. -->
- <span class="hidden sm:inline-block sm:align-middle sm:h-screen" aria-hidden="true">
- &#8203;
- </span>
-
- <div
- x-show="invitationOpen"
- x-transition:enter="transition ease-out duration-300"
- x-transition:enter-start="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
- x-transition:enter-end="opacity-100 translate-y-0 sm:scale-100"
- x-transition:leave="transition ease-in duration-200"
- x-transition:leave-start="opacity-100 translate-y-0 sm:scale-100"
- x-transition:leave-end="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
- class="relative inline-block align-bottom bg-white dark:bg-gray-900 rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full"
- >
- <div class="bg-white dark:bg-gray-850 px-4 pt-5 pb-4 sm:p-6 sm:pb-4">
- <div class="hidden sm:block absolute top-0 right-0 pt-4 pr-4">
- <button
- x-on:click="invitationOpen = false"
- class="bg-white dark:bg-gray-800 rounded-md text-gray-400 dark:text-gray-500 hover:text-gray-500 dark:hover:text-gray-400 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"
+ <div class="sm:flex sm:items-start">
+ <div class="mx-auto shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-green-100 sm:mx-0 sm:h-10 sm:w-10">
+ <Heroicons.user_group class="size-6" />
+ </div>
+ <div class="mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left">
+ <PlausibleWeb.Live.Components.PrimaModal.modal_title>
+ Invitation for {@site.domain}
+ </PlausibleWeb.Live.Components.PrimaModal.modal_title>
+ <div class="mt-2">
+ <p class="text-sm text-gray-500 dark:text-gray-200">
+ You've been invited to the {@site.domain} analytics dashboard as <b class="capitalize">{@invitation.invitation.role}</b>.
+ </p>
+ <div
+ :if={
+ !(Map.get(@invitation, :exceeded_limits) || Map.get(@invitation, :no_plan)) &&
+ @invitation.invitation.role == :owner
+ }
+ class="mt-2 text-sm text-gray-500 dark:text-gray-200"
>
- <span class="sr-only">Close</span>
- <Heroicons.x_mark class="h-6 w-6" />
- </button>
- </div>
- <div class="sm:flex sm:items-start">
- <div class="mx-auto shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-green-100 sm:mx-0 sm:h-10 sm:w-10">
- <Heroicons.user_group class="h-6 w-6" />
- </div>
- <div class="mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left">
- <h3
- class="text-lg leading-6 font-medium text-gray-900 dark:text-gray-100"
- id="modal-title"
- >
- Invitation for
- <span x-text="selectedInvitation && selectedInvitation.invitation.site.domain">
- </span>
- </h3>
- <div class="mt-2">
- <p class="text-sm text-gray-500 dark:text-gray-200">
- You've been invited to the
- <span x-text="selectedInvitation && selectedInvitation.invitation.site.domain">
- </span>
- analytics dashboard as <b
- class="capitalize"
- x-text="selectedInvitation && selectedInvitation.invitation.role"
- >Admin</b>.
- </p>
- <div
- x-show="selectedInvitation && !(selectedInvitation.exceeded_limits || selectedInvitation.no_plan) && selectedInvitation.invitation.role === 'owner'"
- class="mt-2 text-sm text-gray-500 dark:text-gray-200"
- >
- If you accept the ownership transfer, you will be responsible for billing going forward.
- </div>
- </div>
+ If you accept the ownership transfer, you will be responsible for billing going forward.
</div>
</div>
- <.notice
- x-show="selectedInvitation && selectedInvitation.missing_features"
- title="Missing features"
- class="mt-4 shadow-xs dark:shadow-none"
- >
- <p>
- The site uses <span x-text="selectedInvitation && selectedInvitation.missing_features"></span>,
- which your current subscription does not support. After accepting ownership of this site,
- you will not be able to access them unless you <.styled_link
- class="inline-block"
- href={Routes.billing_path(PlausibleWeb.Endpoint, :choose_plan)}
- >
- upgrade to a suitable plan
- </.styled_link>.
- </p>
- </.notice>
- <.notice
- x-show="selectedInvitation && selectedInvitation.exceeded_limits"
- title="Unable to accept site ownership"
- class="mt-4 shadow-xs dark:shadow-none"
- >
- <p>
- Owning this site would exceed your <span x-text="selectedInvitation && selectedInvitation.exceeded_limits"></span>. Please check your usage in
- <.styled_link
- class="inline-block"
- href={Routes.settings_path(PlausibleWeb.Endpoint, :subscription)}
- >
- account settings
- </.styled_link>
- and upgrade your subscription to accept the site ownership.
- </p>
- </.notice>
- <.notice
- x-show="selectedInvitation && selectedInvitation.no_plan"
- title="No subscription"
- class="mt-4 shadow-xs dark:shadow-none"
- >
- You are unable to accept the ownership of this site because your account does not have a subscription. To become the owner of this site, you should upgrade to a suitable plan.
- </.notice>
</div>
- <div class="bg-gray-50 dark:bg-gray-850 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse">
- <.button
- x-show="selectedInvitation && !(selectedInvitation.exceeded_limits || selectedInvitation.no_plan)"
- class="sm:ml-3 w-full sm:w-auto sm:text-sm"
- data-method="post"
- data-csrf={Plug.CSRFProtection.get_csrf_token()}
- x-bind:data-to="selectedInvitation && ('/sites/invitations/' + selectedInvitation.invitation.invitation_id + '/accept')"
- >
- Accept &amp; Continue
- </.button>
- <.button_link
- x-show="selectedInvitation && (selectedInvitation.exceeded_limits || selectedInvitation.no_plan)"
+ </div>
+ <.notice
+ :if={Map.get(@invitation, :missing_features)}
+ title="Missing features"
+ class="mt-4 shadow-xs dark:shadow-none"
+ >
+ <p>
+ The site uses {Map.get(@invitation, :missing_features)},
+ which your current subscription does not support. After accepting ownership of this site,
+ you will not be able to access them unless you <.styled_link
+ class="inline-block"
href={Routes.billing_path(PlausibleWeb.Endpoint, :choose_plan)}
- class="sm:ml-3 w-full sm:w-auto sm:text-sm"
>
- Upgrade
- </.button_link>
- <.button_link
- href="#"
- theme="secondary"
- data-method="post"
- data-csrf={Plug.CSRFProtection.get_csrf_token()}
- x-bind:data-to="selectedInvitation && ('/sites/invitations/' + selectedInvitation.invitation.invitation_id + '/reject')"
+ upgrade to a suitable plan
+ </.styled_link>.
+ </p>
+ </.notice>
+ <.notice
+ :if={Map.get(@invitation, :exceeded_limits)}
+ title="Unable to accept site ownership"
+ class="mt-4 shadow-xs dark:shadow-none"
+ >
+ <p>
+ Owning this site would exceed your {Map.get(@invitation, :exceeded_limits)}. Please check your usage in
+ <.styled_link
+ class="inline-block"
+ href={Routes.settings_path(PlausibleWeb.Endpoint, :subscription)}
>
- Reject
- </.button_link>
- </div>
- </div>
+ account settings
+ </.styled_link>
+ and upgrade your subscription to accept the site ownership.
+ </p>
+ </.notice>
+ <.notice
+ :if={Map.get(@invitation, :no_plan)}
+ title="No subscription"
+ class="mt-4 shadow-xs dark:shadow-none"
+ >
+ You are unable to accept the ownership of this site because your account does not have a subscription. To become the owner of this site, you should upgrade to a suitable plan.
+ </.notice>
</div>
- </div>
+ <div class="bg-gray-50 dark:bg-gray-850 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse">
+ <.button
+ :if={!(Map.get(@invitation, :exceeded_limits) || Map.get(@invitation, :no_plan))}
+ mt?={false}
+ class="sm:ml-3 w-full sm:w-auto sm:text-sm"
+ data-method="post"
+ data-csrf={Plug.CSRFProtection.get_csrf_token()}
+ data-to={"/sites/invitations/#{@invitation.invitation.invitation_id}/accept"}
+ data-autofocus
+ >
+ Accept &amp; Continue
+ </.button>
+ <.button_link
+ :if={Map.get(@invitation, :exceeded_limits) || Map.get(@invitation, :no_plan)}
+ mt?={false}
+ href={Routes.billing_path(PlausibleWeb.Endpoint, :choose_plan)}
+ class="sm:ml-3 w-full sm:w-auto sm:text-sm"
+ data-autofocus
+ >
+ Upgrade
+ </.button_link>
+ <.button_link
+ mt?={false}
+ class="w-full sm:w-auto mr-2 sm:text-sm mt-2 sm:mt-0"
+ href="#"
+ theme="secondary"
+ data-method="post"
+ data-csrf={Plug.CSRFProtection.get_csrf_token()}
+ data-to={"/sites/invitations/#{@invitation.invitation.invitation_id}/reject"}
+ >
+ Reject
+ </.button_link>
+ </div>
+ </PlausibleWeb.Live.Components.PrimaModal.modal>
"""
end
diff --git a/mix.exs b/mix.exs
index 50fa20c152..b68bd8abee 100644
--- a/mix.exs
+++ b/mix.exs
@@ -114,6 +114,7 @@ defmodule Plausible.MixProject do
{:phoenix_live_view, "~> 1.1"},
{:php_serializer, "~> 2.0"},
{:plug, "~> 1.13", override: true},
+ {:prima, "~> 0.1.7"},
{:plug_cowboy, "~> 2.3"},
{:polymorphic_embed, "~> 5.0"},
{:postgrex, "~> 0.19.0"},
diff --git a/mix.lock b/mix.lock
index 873c21875d..bdcfff4bae 100644
--- a/mix.lock
+++ b/mix.lock
@@ -21,7 +21,7 @@
"comeonin": {:hex, :comeonin, "5.5.1", "5113e5f3800799787de08a6e0db307133850e635d34e9fab23c70b6501669510", [:mix], [], "hexpm", "65aac8f19938145377cee73973f192c5645873dcf550a8a6b18187d17c13ccdb"},
"con_cache": {:git, "https://github.com/aerosol/con_cache", "d050e133742e512cf2caa4598607e60dd0161072", [branch: "ensure-dirty-ops-emit-telemetry"]},
"cors_plug": {:hex, :cors_plug, "3.0.3", "7c3ac52b39624bc616db2e937c282f3f623f25f8d550068b6710e58d04a0e330", [:mix], [{:plug, "~> 1.13", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "3f2d759e8c272ed3835fab2ef11b46bddab8c1ab9528167bd463b6452edf830d"},
- "cowboy": {:hex, :cowboy, "2.14.0", "565dcf221ba99b1255b0adcec24d2d8dbe79e46ec79f30f8373cceadc6a41e2a", [:make, :rebar3], [{:cowlib, ">= 2.16.0 and < 3.0.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, ">= 1.8.0 and < 3.0.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "ea99769574550fe8a83225c752e8a62780a586770ef408816b82b6fe6d46476b"},
+ "cowboy": {:hex, :cowboy, "2.14.2", "4008be1df6ade45e4f2a4e9e2d22b36d0b5aba4e20b0a0d7049e28d124e34847", [:make, :rebar3], [{:cowlib, ">= 2.16.0 and < 3.0.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, ">= 1.8.0 and < 3.0.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "569081da046e7b41b5df36aa359be71a0c8874e5b9cff6f747073fc57baf1ab9"},
"cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"},
"cowlib": {:hex, :cowlib, "2.16.0", "54592074ebbbb92ee4746c8a8846e5605052f29309d3a873468d76cdf932076f", [:make, :rebar3], [], "hexpm", "7f478d80d66b747344f0ea7708c187645cfcc08b11aa424632f78e25bf05db51"},
"credo": {:hex, :credo, "1.7.7", "771445037228f763f9b2afd612b6aa2fd8e28432a95dbbc60d8e03ce71ba4446", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "8bc87496c9aaacdc3f90f01b7b0582467b69b4bd2441fe8aae3109d843cc2f2e"},
@@ -41,7 +41,7 @@
"envy": {:hex, :envy, "1.1.1", "0bc9bd654dec24fcdf203f7c5aa1b8f30620f12cfb28c589d5e9c38fe1b07475", [:mix], [], "hexpm", "7061eb1a47415fd757145d8dec10dc0b1e48344960265cb108f194c4252c3a89"},
"eqrcode": {:hex, :eqrcode, "0.2.1", "d12838813e8fc87b8940cc05f9baadb189031f6009facdc56ff074375ec73b6e", [:mix], [], "hexpm", "d5828a222b904c68360e7dc2a40c3ef33a1328b7c074583898040f389f928025"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
- "esbuild": {:hex, :esbuild, "0.8.1", "0cbf919f0eccb136d2eeef0df49c4acf55336de864e63594adcea3814f3edf41", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "25fc876a67c13cb0a776e7b5d7974851556baeda2085296c14ab48555ea7560f"},
+ "esbuild": {:hex, :esbuild, "0.10.0", "b0aa3388a1c23e727c5a3e7427c932d89ee791746b0081bbe56103e9ef3d291f", [:mix], [{:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "468489cda427b974a7cc9f03ace55368a83e1a7be12fba7e30969af78e5f8c70"},
"ex_aws": {:hex, :ex_aws, "2.5.1", "7418917974ea42e9e84b25e88b9f3d21a861d5f953ad453e212f48e593d8d39f", [:mix], [{:configparser_ex, "~> 4.0", [hex: :configparser_ex, repo: "hexpm", optional: true]}, {:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: true]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: true]}, {:jsx, "~> 2.8 or ~> 3.0", [hex: :jsx, repo: "hexpm", optional: true]}, {:mime, "~> 1.2 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:sweet_xml, "~> 0.7", [hex: :sweet_xml, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "1b95431f70c446fa1871f0eb9b183043c5a625f75f9948a42d25f43ae2eff12b"},
"ex_aws_s3": {:hex, :ex_aws_s3, "2.5.3", "422468e5c3e1a4da5298e66c3468b465cfd354b842e512cb1f6fbbe4e2f5bdaf", [:mix], [{:ex_aws, "~> 2.0", [hex: :ex_aws, repo: "hexpm", optional: false]}, {:sweet_xml, ">= 0.0.0", [hex: :sweet_xml, repo: "hexpm", optional: true]}], "hexpm", "4f09dd372cc386550e484808c5ac5027766c8d0cd8271ccc578b82ee6ef4f3b8"},
"ex_cldr": {:hex, :ex_cldr, "2.42.0", "17ea930e88b8802b330e1c1e288cdbaba52cbfafcccf371ed34b299a47101ffb", [:mix], [{:cldr_utils, "~> 2.28", [hex: :cldr_utils, repo: "hexpm", optional: false]}, {:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:gettext, "~> 0.19", [hex: :gettext, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: true]}], "hexpm", "07264a7225810ecae6bdd6715d8800c037a1248dc0063923cddc4ca3c4888df6"},
@@ -124,8 +124,8 @@
"phoenix_html": {:hex, :phoenix_html, "4.3.0", "d3577a5df4b6954cd7890c84d955c470b5310bb49647f0a114a6eeecc850f7ad", [:mix], [], "hexpm", "3eaa290a78bab0f075f791a46a981bbe769d94bc776869f4f3063a14f30497ad"},
"phoenix_html_helpers": {:hex, :phoenix_html_helpers, "1.0.1", "7eed85c52eff80a179391036931791ee5d2f713d76a81d0d2c6ebafe1e11e5ec", [:mix], [{:phoenix_html, "~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "cffd2385d1fa4f78b04432df69ab8da63dc5cf63e07b713a4dcf36a3740e3090"},
"phoenix_live_reload": {:hex, :phoenix_live_reload, "1.5.3", "f2161c207fda0e4fb55165f650f7f8db23f02b29e3bff00ff7ef161d6ac1f09d", [:mix], [{:file_system, "~> 0.3 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm", "b4ec9cd73cb01ff1bd1cac92e045d13e7030330b74164297d1aee3907b54803c"},
- "phoenix_live_view": {:hex, :phoenix_live_view, "1.1.13", "11f48f8fbe5d7d0731d4e122a692e0f9ae8d5f98c54d573d29046833c34eada3", [:mix], [{:igniter, ">= 0.6.16 and < 1.0.0-0", [hex: :igniter, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:lazy_html, "~> 0.1.0", [hex: :lazy_html, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.6.15 or ~> 1.7.0 or ~> 1.8.0-rc", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 3.3 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.15", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "9d06e93573b8419ef8ee832b4a9bfe0def10b15f7c129ea477dfa54f0136f7ec"},
- "phoenix_pubsub": {:hex, :phoenix_pubsub, "2.1.3", "3168d78ba41835aecad272d5e8cd51aa87a7ac9eb836eabc42f6e57538e3731d", [:mix], [], "hexpm", "bba06bc1dcfd8cb086759f0edc94a8ba2bc8896d5331a1e2c2902bf8e36ee502"},
+ "phoenix_live_view": {:hex, :phoenix_live_view, "1.1.16", "e42f95337b912a73a1c4ddb077af2eb13491712d7ab79b67e13de4237dfcac50", [:mix], [{:igniter, ">= 0.6.16 and < 1.0.0-0", [hex: :igniter, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:lazy_html, "~> 0.1.0", [hex: :lazy_html, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.6.15 or ~> 1.7.0 or ~> 1.8.0-rc", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 3.3 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.15", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "f2a0093895b8ef4880af76d41de4a9cf7cff6c66ad130e15a70bdabc4d279feb"},
+ "phoenix_pubsub": {:hex, :phoenix_pubsub, "2.2.0", "ff3a5616e1bed6804de7773b92cbccfc0b0f473faf1f63d7daf1206c7aeaaa6f", [:mix], [], "hexpm", "adc313a5bf7136039f63cfd9668fde73bba0765e0614cba80c06ac9460ff3e96"},
"phoenix_storybook": {:hex, :phoenix_storybook, "0.9.3", "4f94e731d4c40d4dd7d1eddf7d5c6914366da7d78552dc565b222e4036d0d76f", [:mix], [{:earmark, "~> 1.4", [hex: :earmark, repo: "hexpm", optional: false]}, {:jason, "~> 1.3", [hex: :jason, repo: "hexpm", optional: true]}, {:makeup_eex, "~> 2.0.2", [hex: :makeup_eex, repo: "hexpm", optional: false]}, {:makeup_html, "~> 0.2.0", [hex: :makeup_html, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.8.1", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html_helpers, "~> 1.0", [hex: :phoenix_html_helpers, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 1.1.0", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: false]}], "hexpm", "4c8658b756fd8238f7e8e4343a0f12bdb91d4eba592b1c4e8118b37b6fd43e4b"},
"phoenix_template": {:hex, :phoenix_template, "1.0.4", "e2092c132f3b5e5b2d49c96695342eb36d0ed514c5b252a77048d5969330d639", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "2c0c81f0e5c6753faf5cca2f229c9709919aba34fab866d3bc05060c9c444206"},
"phoenix_view": {:hex, :phoenix_view, "2.0.4", "b45c9d9cf15b3a1af5fb555c674b525391b6a1fe975f040fb4d913397b31abf4", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}], "hexpm", "4e992022ce14f31fe57335db27a28154afcc94e9983266835bb3040243eb620b"},
@@ -135,6 +135,7 @@
"plug_crypto": {:hex, :plug_crypto, "1.2.5", "918772575e48e81e455818229bf719d4ab4181fcbf7f85b68a35620f78d89ced", [:mix], [], "hexpm", "26549a1d6345e2172eb1c233866756ae44a9609bd33ee6f99147ab3fd87fd842"},
"polymorphic_embed": {:hex, :polymorphic_embed, "5.0.3", "37444e0af941026a2c29b0539b6471bdd6737a6492a19264bf2bb0118e3ac242", [:mix], [{:attrs, "~> 0.6", [hex: :attrs, repo: "hexpm", optional: false]}, {:ecto, "~> 3.12", [hex: :ecto, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 4.1", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:phoenix_html_helpers, "~> 1.0", [hex: :phoenix_html_helpers, repo: "hexpm", optional: true]}, {:phoenix_live_view, "~> 0.20 or ~> 1.0", [hex: :phoenix_live_view, repo: "hexpm", optional: true]}], "hexpm", "2fed44f57abf0a0fc7642e0eb0807a55b65de1562712cc0620772cbbb80e49c1"},
"postgrex": {:hex, :postgrex, "0.19.3", "a0bda6e3bc75ec07fca5b0a89bffd242ca209a4822a9533e7d3e84ee80707e19", [:mix], [{:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "d31c28053655b78f47f948c85bb1cf86a9c1f8ead346ba1aa0d0df017fa05b61"},
+ "prima": {:hex, :prima, "0.1.7", "197fe29aa1cb6cc0c38fddb7daca017b9d4cfc1aef0b30694e02e45fcf22710f", [:mix], [{:esbuild, "~> 0.7", [hex: :esbuild, repo: "hexpm", optional: false]}, {:phoenix, ">= 1.7.0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 4.2", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 1.1", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}], "hexpm", "662ea3f8698358087c1632db8969050a74df101e202d026e2f26bc3f740737f9"},
"prom_ex": {:hex, :prom_ex, "1.11.0", "1f6d67f2dead92224cb4f59beb3e4d319257c5728d9638b4a5e8ceb51a4f9c7e", [:mix], [{:absinthe, ">= 1.7.0", [hex: :absinthe, repo: "hexpm", optional: true]}, {:broadway, ">= 1.1.0", [hex: :broadway, repo: "hexpm", optional: true]}, {:ecto, ">= 3.11.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:finch, "~> 0.18", [hex: :finch, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:oban, ">= 2.10.0", [hex: :oban, repo: "hexpm", optional: true]}, {:octo_fetch, "~> 0.4", [hex: :octo_fetch, repo: "hexpm", optional: false]}, {:peep, "~> 3.0", [hex: :peep, repo: "hexpm", optional: false]}, {:phoenix, ">= 1.7.0", [hex: :phoenix, repo: "hexpm", optional: true]}, {:phoenix_live_view, ">= 0.20.0", [hex: :phoenix_live_view, repo: "hexpm", optional: true]}, {:plug, ">= 1.16.0", [hex: :plug, repo: "hexpm", optional: true]}, {:plug_cowboy, ">= 2.6.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:telemetry, ">= 1.0.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:telemetry_metrics, "~> 1.0", [hex: :telemetry_metrics, repo: "hexpm", optional: false]}, {:telemetry_metrics_prometheus_core, "~> 1.2", [hex: :telemetry_metrics_prometheus_core, repo: "hexpm", optional: false]}, {:telemetry_poller, "~> 1.1", [hex: :telemetry_poller, repo: "hexpm", optional: false]}], "hexpm", "76b074bc3730f0802978a7eb5c7091a65473eaaf07e99ec9e933138dcc327805"},
"public_suffix": {:git, "https://github.com/axelson/publicsuffix-elixir", "fa40c243d4b5d8598b90cff268bc4e33f3bb63f1", []},
"ranch": {:hex, :ranch, "1.8.1", "208169e65292ac5d333d6cdbad49388c1ae198136e4697ae2f474697140f201c", [:make, :rebar3], [], "hexpm", "aed58910f4e21deea992a67bf51632b6d60114895eb03bb392bb733064594dd0"},
@@ -153,11 +154,11 @@
"site_encrypt": {:git, "https://github.com/sasa1977/site_encrypt.git", "8d47801c51eeea11ac385cb73eef4ed9a6565367", []},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.7", "354c321cf377240c7b8716899e182ce4890c5938111a1296add3ec74cf1715df", [:make, :mix, :rebar3], [], "hexpm", "fe4c190e8f37401d30167c8c405eda19469f34577987c76dde613e838bbc67f8"},
"sweet_xml": {:hex, :sweet_xml, "0.7.4", "a8b7e1ce7ecd775c7e8a65d501bc2cd933bff3a9c41ab763f5105688ef485d08", [:mix], [], "hexpm", "e7c4b0bdbf460c928234951def54fe87edf1a170f6896675443279e2dbeba167"},
- "tailwind": {:hex, :tailwind, "0.4.0", "4b2606713080437e3d94a0fa26527e7425737abc001f172b484b42f43e3274c0", [:mix], [], "hexpm", "530bd35699333f8ea0e9038d7146c2f0932dfec2e3636bd4a8016380c4bc382e"},
+ "tailwind": {:hex, :tailwind, "0.4.1", "e7bcc222fe96a1e55f948e76d13dd84a1a7653fb051d2a167135db3b4b08d3e9", [:mix], [], "hexpm", "6249d4f9819052911120dbdbe9e532e6bd64ea23476056adb7f730aa25c220d1"},
"telemetry": {:hex, :telemetry, "1.3.0", "fedebbae410d715cf8e7062c96a1ef32ec22e764197f70cda73d82778d61e7a2", [:rebar3], [], "hexpm", "7015fc8919dbe63764f4b4b87a95b7c0996bd539e0d499be6ec9d7f3875b79e6"},
"telemetry_metrics": {:hex, :telemetry_metrics, "1.1.0", "5bd5f3b5637e0abea0426b947e3ce5dd304f8b3bc6617039e2b5a008adc02f8f", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "e7b79e8ddfde70adb6db8a6623d1778ec66401f366e9a8f5dd0955c56bc8ce67"},
"telemetry_metrics_prometheus_core": {:hex, :telemetry_metrics_prometheus_core, "1.2.1", "c9755987d7b959b557084e6990990cb96a50d6482c683fb9622a63837f3cd3d8", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:telemetry_metrics, "~> 0.6 or ~> 1.0", [hex: :telemetry_metrics, repo: "hexpm", optional: false]}], "hexpm", "5e2c599da4983c4f88a33e9571f1458bf98b0cf6ba930f1dc3a6e8cf45d5afb6"},
- "telemetry_poller": {:hex, :telemetry_poller, "1.1.0", "58fa7c216257291caaf8d05678c8d01bd45f4bdbc1286838a28c4bb62ef32999", [:rebar3], [{:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "9eb9d9cbfd81cbd7cdd24682f8711b6e2b691289a0de6826e58452f28c103c8f"},
+ "telemetry_poller": {:hex, :telemetry_poller, "1.3.0", "d5c46420126b5ac2d72bc6580fb4f537d35e851cc0f8dbd571acf6d6e10f5ec7", [:rebar3], [{:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "51f18bed7128544a50f75897db9974436ea9bfba560420b646af27a9a9b35211"},
"timex": {:hex, :timex, "3.7.11", "bb95cb4eb1d06e27346325de506bcc6c30f9c6dea40d1ebe390b262fad1862d1", [:mix], [{:combine, "~> 0.10", [hex: :combine, repo: "hexpm", optional: false]}, {:gettext, "~> 0.20", [hex: :gettext, repo: "hexpm", optional: false]}, {:tzdata, "~> 1.1", [hex: :tzdata, repo: "hexpm", optional: false]}], "hexpm", "8b9024f7efbabaf9bd7aa04f65cf8dcd7c9818ca5737677c7b76acbc6a94d1aa"},
"tls_certificate_check": {:hex, :tls_certificate_check, "1.26.0", "c0e8ffab875748f2b122d4d4e465aeaa7249ea539f1004b7922cb3c61ffe261d", [:rebar3], [{:ssl_verify_fun, "~> 1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm", "1bad73d88637f788b554a8e939c25db2bdaac88b10fffd5bba9d1b65f43a6b54"},
"tzdata": {:hex, :tzdata, "1.1.3", "b1cef7bb6de1de90d4ddc25d33892b32830f907e7fc2fccd1e7e22778ab7dfbc", [:mix], [{:hackney, "~> 1.17", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "d4ca85575a064d29d4e94253ee95912edfb165938743dbf002acdf0dcecb0c28"},
diff --git a/test/plausible_web/live/sites_test.exs b/test/plausible_web/live/sites_test.exs
index 5c5f80ffe2..3b0801c61b 100644
--- a/test/plausible_web/live/sites_test.exs
+++ b/test/plausible_web/live/sites_test.exs
@@ -94,22 +94,6 @@ defmodule PlausibleWeb.Live.SitesTest do
)
end
- test "renders metadata for invitation", %{
- conn: conn,
- user: user
- } do
- inviter = new_user()
- site = new_site(owner: inviter)
-
- invitation = invite_guest(site, user, inviter: inviter, role: :viewer)
-
- {:ok, _lv, html} = live(conn, "/sites")
-
- invitation_data = get_invitation_data(html)
-
- assert get_in(invitation_data, ["invitations", invitation.invitation_id, "invitation"])
- end
-
@tag :ee_only
test "renders ownership transfer invitation for a case with no plan", %{
conn: conn,
@@ -122,9 +106,10 @@ defmodule PlausibleWeb.Live.SitesTest do
{:ok, _lv, html} = live(conn, "/sites")
- invitation_data = get_invitation_data(html)
+ template = find_portal_template(html, "#invitation-modal-#{transfer.transfer_id}")
- assert get_in(invitation_data, ["invitations", transfer.transfer_id, "no_plan"])
+ assert text(template) =~
+ "You are unable to accept the ownership of this site because your account does not have a subscription"
end
@tag :ee_only
@@ -220,10 +205,9 @@ defmodule PlausibleWeb.Live.SitesTest do
{:ok, _lv, html} = live(conn, "/sites")
- invitation_data = get_invitation_data(html)
+ template = find_portal_template(html, "#invitation-modal-#{transfer.transfer_id}")
- assert get_in(invitation_data, ["invitations", transfer.transfer_id, "exceeded_limits"]) ==
- "site limit"
+ assert text(template) =~ "Owning this site would exceed your site limit"
end
@tag :ee_only
@@ -240,10 +224,10 @@ defmodule PlausibleWeb.Live.SitesTest do
{:ok, _lv, html} = live(conn, "/sites")
- invitation_data = get_invitation_data(html)
+ template = find_portal_template(html, "#invitation-modal-#{transfer.transfer_id}")
- assert get_in(invitation_data, ["invitations", transfer.transfer_id, "missing_features"]) ==
- "Custom Properties"
+ assert text(template) =~
+ "The site uses Custom Properties, which your current subscription does not support"
end
test "renders 24h visitors correctly", %{conn: conn, user: user} do
@@ -449,14 +433,4 @@ defmodule PlausibleWeb.Live.SitesTest do
|> element("form")
|> render_change(%{id => text})
end
-
- defp get_invitation_data(html) do
- html
- |> text_of_attr("div[x-ref=\"invitation_data\"][x-data]", "x-data")
- |> String.trim("dropdown")
- |> String.replace("selectedInvitation:", "\"selectedInvitation\":")
- |> String.replace("invitationOpen:", "\"invitationOpen\":")
- |> String.replace("invitations:", "\"invitations\":")
- |> Jason.decode!()
- end
end
diff --git a/test/support/html.ex b/test/support/html.ex
index 792d173f3a..fdde79a227 100644
--- a/test/support/html.ex
+++ b/test/support/html.ex
@@ -81,6 +81,26 @@ defmodule Plausible.Test.Support.HTML do
text_of_attr(element, "name")
end
+ @doc """
+ When using liveview <.portal> element, it renders a <template> that gets rendered into DOM
+ by JS. In order to make assertions about portal contents, we need to find the <template> element
+ and get its contents. Unfortunately <template> elements are not treated like standard elements by LazyHTML.
+ Functions like LazyHTML.text() or LazyHTML.query() return nothing for <template> elements. So this function tricks LazyHTML by:
+ 1. Finding the template element
+ 2. Transforming it into a <div> so it can be used like a normal LazyHTML node
+ )
+ """
+ def find_portal_template(html, id) do
+ template_id = id <> "-portal"
+
+ [{"template", attrs, children}] =
+ lazy_parse(html)
+ |> find(template_id)
+ |> LazyHTML.to_tree()
+
+ LazyHTML.from_tree([{"div", attrs, children}])
+ end
+
defp lazy_parse(%LazyHTML{} = lazy) do
lazy
end