Skip to content

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

Starter feature gates (UI) (#5426)

RobertJoonase38bda6d0006
diff --git a/assets/js/dashboard/segments/routeless-segment-modals.tsx b/assets/js/dashboard/segments/routeless-segment-modals.tsx
index 6053bc9692..024a9d4b8f 100644
--- a/assets/js/dashboard/segments/routeless-segment-modals.tsx
+++ b/assets/js/dashboard/segments/routeless-segment-modals.tsx
@@ -17,7 +17,7 @@ import { useSiteContext } from '../site-context'
import { cleanLabels, remapToApiFilters } from '../util/filters'
import { useAppNavigate } from '../navigation/use-app-navigate'
import { useQueryContext } from '../query-context'
-import { Role, useUserContext } from '../user-context'
+import { useUserContext } from '../user-context'
import { mutation } from '../api'
import { useRoutelessModalsContext } from '../navigation/routeless-modals-context'
import { useSegmentsContext } from '../filtering/segments-context'
@@ -147,18 +147,11 @@ export const RoutelessSegmentModals = () => {
return null
}
- const userCanSelectSiteSegment = [
- Role.admin,
- Role.owner,
- Role.editor,
- 'super_admin'
- ].includes(user.role)
-
return (
<>
{modal === 'update' && expandedSegment && (
<UpdateSegmentModal
- userCanSelectSiteSegment={userCanSelectSiteSegment}
+ user={user}
siteSegmentsAvailable={site.siteSegmentsAvailable}
segment={expandedSegment}
namePlaceholder={getSegmentNamePlaceholder(query)}
@@ -184,7 +177,7 @@ export const RoutelessSegmentModals = () => {
)}
{modal === 'create' && (
<CreateSegmentModal
- userCanSelectSiteSegment={userCanSelectSiteSegment}
+ user={user}
siteSegmentsAvailable={site.siteSegmentsAvailable}
namePlaceholder={getSegmentNamePlaceholder(query)}
segment={expandedSegment ?? undefined}
diff --git a/assets/js/dashboard/segments/segment-modals.tsx b/assets/js/dashboard/segments/segment-modals.tsx
index 67589a6aa4..a183f80138 100644
--- a/assets/js/dashboard/segments/segment-modals.tsx
+++ b/assets/js/dashboard/segments/segment-modals.tsx
@@ -1,4 +1,4 @@
-import React, { ReactNode, useState } from 'react'
+import React, { ReactNode, useCallback, useState } from 'react'
import ModalWithRouting from '../stats/modals/modal'
import {
canSeeSegmentDetails,
@@ -23,7 +23,7 @@ import { ApiError } from '../api'
import { ErrorPanel } from '../components/error-panel'
import { useSegmentsContext } from '../filtering/segments-context'
import { useSiteContext } from '../site-context'
-import { useUserContext } from '../user-context'
+import { Role, UserContextValue, useUserContext } from '../user-context'
import { removeFilterButtonClassname } from '../components/remove-filter-button'
interface ApiRequestProps {
@@ -32,12 +32,9 @@ interface ApiRequestProps {
reset: () => void
}
-interface SegmentTypeSelectorProps {
+interface SegmentModalProps {
+ user: UserContextValue
siteSegmentsAvailable: boolean
- userCanSelectSiteSegment: boolean
-}
-
-interface SharedSegmentModalProps {
onClose: () => void
namePlaceholder: string
}
@@ -77,14 +74,13 @@ export const CreateSegmentModal = ({
onClose,
onSave,
siteSegmentsAvailable: siteSegmentsAvailable,
- userCanSelectSiteSegment,
+ user,
namePlaceholder,
error,
reset,
status
-}: SharedSegmentModalProps &
- ApiRequestProps &
- SegmentTypeSelectorProps & {
+}: SegmentModalProps &
+ ApiRequestProps & {
segment?: SavedSegment
onSave: (input: Pick<SavedSegment, 'name' | 'type'>) => void
}) => {
@@ -95,12 +91,19 @@ export const CreateSegmentModal = ({
const defaultType =
segment?.type === SegmentType.site &&
siteSegmentsAvailable &&
- userCanSelectSiteSegment
+ hasSiteSegmentPermission(user)
? SegmentType.site
: SegmentType.personal
const [type, setType] = useState<SegmentType>(defaultType)
+ const { disabled, disabledMessage, onSegmentTypeChange } =
+ useSegmentTypeDisabledState({
+ siteSegmentsAvailable,
+ user,
+ setType
+ })
+
return (
<SegmentActionModal onClose={onClose}>
<FormTitle>Create segment</FormTitle>
@@ -109,29 +112,19 @@ export const CreateSegmentModal = ({
onChange={setName}
namePlaceholder={namePlaceholder}
/>
- <SegmentTypeSelector
- value={type}
- onChange={setType}
- siteSegmentsAvailable={siteSegmentsAvailable}
- userCanSelectSiteSegment={userCanSelectSiteSegment}
- />
+ <SegmentTypeSelector value={type} onChange={onSegmentTypeChange} />
+ {disabled && <SegmentTypeDisabledMessage message={disabledMessage} />}
<ButtonsRow>
- <button
- className={primaryNeutralButtonClassName}
- onClick={
- status !== 'pending'
- ? () => {
- const trimmedName = name.trim()
- const saveableName = trimmedName.length
- ? trimmedName
- : namePlaceholder
- onSave({ name: saveableName, type })
- }
- : () => {}
- }
- >
- Save
- </button>
+ <SaveSegmentButton
+ disabled={status === 'pending' || disabled}
+ onSave={() => {
+ const trimmedName = name.trim()
+ const saveableName = trimmedName.length
+ ? trimmedName
+ : namePlaceholder
+ onSave({ name: saveableName, type })
+ }}
+ />
<button className={secondaryButtonClassName} onClick={onClose}>
Cancel
</button>
@@ -253,10 +246,8 @@ const SegmentNameInput = ({
const SegmentTypeSelector = ({
value,
- onChange,
- siteSegmentsAvailable,
- userCanSelectSiteSegment
-}: SegmentTypeSelectorProps & {
+ onChange
+}: {
value: SegmentType
onChange: (value: SegmentType) => void
}) => {
@@ -264,34 +255,18 @@ const SegmentTypeSelector = ({
{
type: SegmentType.personal,
name: SEGMENT_TYPE_LABELS[SegmentType.personal],
- description: 'Visible only to you',
- disabled: false
+ description: 'Visible only to you'
},
{
type: SegmentType.site,
name: SEGMENT_TYPE_LABELS[SegmentType.site],
- description: 'Visible to others on the site',
- disabled: !userCanSelectSiteSegment || !siteSegmentsAvailable,
- disabledReason: !userCanSelectSiteSegment ? (
- <>
- {"You don't have enough permissions to change segment to this type."}
- </>
- ) : !siteSegmentsAvailable ? (
- <>
- {`Your account does not have access to site segments. To use this
- segment type, `}
- <a href="/billing/choose-plan" className="underline">
- please upgrade your subscription
- </a>
- .
- </>
- ) : null
+ description: 'Visible to others on the site'
}
]
return (
<div className="mt-4 flex flex-col gap-y-4">
- {options.map(({ type, name, description, disabled, disabledReason }) => (
+ {options.map(({ type, name, description }) => (
<div key={type}>
<div className="flex">
<input
@@ -310,37 +285,128 @@ const SegmentTypeSelector = ({
<div className="mt-1">{description}</div>
</label>
</div>
- {value === type && disabled && !!disabledReason && (
- <div className="mt-2 flex gap-x-2 text-sm">
- <ExclamationTriangleIcon className="mt-1 block w-4 h-4 shrink-0" />
- <div>{disabledReason}</div>
- </div>
- )}
</div>
))}
</div>
)
}
+const useSegmentTypeDisabledState = ({
+ siteSegmentsAvailable,
+ user,
+ setType
+}: {
+ siteSegmentsAvailable: boolean
+ user: UserContextValue
+ setType: (type: SegmentType) => void
+}) => {
+ const [disabled, setDisabled] = useState<boolean>(false)
+ const [disabledMessage, setDisabledMessage] = useState<ReactNode | null>(null)
+
+ const userIsOwner = user.role === Role.owner
+ const canSelectSiteSegment = hasSiteSegmentPermission(user)
+
+ const onSegmentTypeChange = useCallback(
+ (type: SegmentType) => {
+ setType(type)
+
+ if (type === SegmentType.site && !canSelectSiteSegment) {
+ setDisabled(true)
+ setDisabledMessage(
+ <>
+ {"You don't have enough permissions to change segment to this type"}
+ </>
+ )
+ } else if (type === SegmentType.site && !siteSegmentsAvailable) {
+ setDisabled(true)
+ setDisabledMessage(
+ <>
+ To use this segment type,&#32;
+ {userIsOwner ? (
+ <a href="/billing/choose-plan" className="underline">
+ please upgrade your subscription
+ </a>
+ ) : (
+ <>
+ please reach out to a team owner to upgrade their subscription.
+ </>
+ )}
+ </>
+ )
+ } else {
+ setDisabled(false)
+ setDisabledMessage(null)
+ }
+ },
+ [setType, siteSegmentsAvailable, userIsOwner, canSelectSiteSegment]
+ )
+
+ return {
+ disabled,
+ disabledMessage,
+ onSegmentTypeChange
+ }
+}
+
+const SaveSegmentButton = ({
+ disabled,
+ onSave
+}: {
+ disabled: boolean
+ onSave: () => void
+}) => {
+ return (
+ <button
+ className={primaryNeutralButtonClassName}
+ type="button"
+ disabled={disabled}
+ onClick={disabled ? () => {} : onSave}
+ >
+ Save
+ </button>
+ )
+}
+
+const SegmentTypeDisabledMessage = ({
+ message
+}: {
+ message: ReactNode | null
+}) => {
+ if (!message) return null
+
+ return (
+ <div className="mt-2 flex gap-x-2 text-sm">
+ <ExclamationTriangleIcon className="mt-1 block w-4 h-4 shrink-0" />
+ <div>{message}</div>
+ </div>
+ )
+}
+
export const UpdateSegmentModal = ({
onClose,
onSave,
segment,
siteSegmentsAvailable,
- userCanSelectSiteSegment,
+ user,
namePlaceholder,
status,
error,
reset
-}: SharedSegmentModalProps &
- ApiRequestProps &
- SegmentTypeSelectorProps & {
+}: SegmentModalProps &
+ ApiRequestProps & {
onSave: (input: Pick<SavedSegment, 'id' | 'name' | 'type'>) => void
segment: SavedSegment
}) => {
const [name, setName] = useState(segment.name)
const [type, setType] = useState<SegmentType>(segment.type)
+ const { disabled, disabledMessage, onSegmentTypeChange } =
+ useSegmentTypeDisabledState({
+ siteSegmentsAvailable,
+ user,
+ setType
+ })
+
return (
<SegmentActionModal onClose={onClose}>
<FormTitle>Update segment</FormTitle>
@@ -349,30 +415,19 @@ export const UpdateSegmentModal = ({
onChange={setName}
namePlaceholder={namePlaceholder}
/>
- <SegmentTypeSelector
- value={type}
- onChange={setType}
- siteSegmentsAvailable={siteSegmentsAvailable}
- userCanSelectSiteSegment={userCanSelectSiteSegment}
- />
+ <SegmentTypeSelector value={type} onChange={onSegmentTypeChange} />
+ {disabled && <SegmentTypeDisabledMessage message={disabledMessage} />}
<ButtonsRow>
- <button
- className={primaryNeutralButtonClassName}
- disabled={status === 'pending'}
- onClick={
- status === 'pending'
- ? () => {}
- : () => {
- const trimmedName = name.trim()
- const saveableName = trimmedName.length
- ? trimmedName
- : namePlaceholder
- onSave({ id: segment.id, name: saveableName, type })
- }
- }
- >
- Save
- </button>
+ <SaveSegmentButton
+ disabled={status === 'pending' || disabled}
+ onSave={() => {
+ const trimmedName = name.trim()
+ const saveableName = trimmedName.length
+ ? trimmedName
+ : namePlaceholder
+ onSave({ id: segment.id, name: saveableName, type })
+ }}
+ />
<button className={secondaryButtonClassName} onClick={onClose}>
Cancel
</button>
@@ -430,6 +485,12 @@ const Placeholder = ({
</span>
)
+const hasSiteSegmentPermission = (user: UserContextValue) => {
+ return [Role.admin, Role.owner, Role.editor, 'super_admin'].includes(
+ user.role
+ )
+}
+
export const SegmentModal = ({ id }: { id: SavedSegment['id'] }) => {
const site = useSiteContext()
const user = useUserContext()
diff --git a/extra/lib/plausible_web/live/funnel_settings.ex b/extra/lib/plausible_web/live/funnel_settings.ex
index ae0f852e4a..9a69679136 100644
--- a/extra/lib/plausible_web/live/funnel_settings.ex
+++ b/extra/lib/plausible_web/live/funnel_settings.ex
@@ -68,16 +68,19 @@ defmodule PlausibleWeb.Live.FunnelSettings do
/>
</div>
- <div :if={@goal_count < Funnel.min_steps()}>
- <.notice class="mt-4" title="Not enough goals">
- You need to define at least two goals to create a funnel. Go ahead and
- <.styled_link href={
- PlausibleWeb.Router.Helpers.site_path(@socket, :settings_goals, @domain)
- }>
- add goals
- </.styled_link>
- to proceed.
- </.notice>
+ <div :if={@goal_count < Funnel.min_steps()} class="flex flex-col items-center">
+ <h1 class="mt-4 text-center">
+ Ready to dig into user flows?
+ </h1>
+ <p class="mt-4 mb-6 max-w-lg text-sm text-gray-500 dark:text-gray-400 leading-5 text-center">
+ Set up a few goals first (e.g. <b>"Signup"</b>, <b>"Visit /"</b>, or <b>"Scroll 50% on /blog/*"</b>) and return here to build your first funnel!
+ </p>
+ <.button_link
+ class="mb-2"
+ href={PlausibleWeb.Router.Helpers.site_path(@socket, :settings_goals, @domain)}
+ >
+ Set up goals →
+ </.button_link>
</div>
</div>
"""
diff --git a/lib/plausible/billing/feature.ex b/lib/plausible/billing/feature.ex
index 6e94ff25fb..3ca3706316 100644
--- a/lib/plausible/billing/feature.ex
+++ b/lib/plausible/billing/feature.ex
@@ -204,7 +204,7 @@ defmodule Plausible.Billing.Feature.Teams do
@moduledoc false
use Plausible.Billing.Feature,
name: :teams,
- display_name: "Team Accounts"
+ display_name: "Team Management"
end
defmodule Plausible.Billing.Feature.SharedLinks do
diff --git a/lib/plausible_web/components/billing/billing.ex b/lib/plausible_web/components/billing/billing.ex
index 5a404cd198..c88d755dd7 100644
--- a/lib/plausible_web/components/billing/billing.ex
+++ b/lib/plausible_web/components/billing/billing.ex
@@ -5,7 +5,41 @@ defmodule PlausibleWeb.Components.Billing do
use Plausible
require Plausible.Billing.Subscription.Status
- alias Plausible.Billing.{Subscription, Subscriptions}
+ alias Plausible.Billing.{Subscription, Subscriptions, Feature, Plan, Plans, EnterprisePlan}
+
+ attr :current_role, :atom, required: true
+ attr :current_team, :any, required: true
+ attr :feature_mod, :atom, required: true, values: Feature.list()
+ slot :inner_block, required: true
+
+ def feature_gate(assigns) do
+ assigns =
+ assign(
+ assigns,
+ :locked?,
+ assigns.feature_mod.check_availability(assigns.current_team) != :ok
+ )
+
+ ~H"""
+ <div id="feature-gate-inner-block-container" class={if(@locked?, do: "pointer-events-none")}>
+ {render_slot(@inner_block)}
+ </div>
+ <div
+ :if={@locked?}
+ id="feature-gate-overlay"
+ class="absolute backdrop-blur-[6px] bg-white/50 dark:bg-gray-800/50 inset-0 flex justify-center items-center rounded-md"
+ >
+ <div class="px-6 flex flex-col items-center text-gray-500 dark:text-gray-400">
+ <Heroicons.lock_closed solid class="size-8 mb-2" />
+
+ <span id="lock-notice" class="text-center max-w-sm sm:max-w-md">
+ To gain access to this feature,
+ <.upgrade_call_to_action current_role={@current_role} current_team={@current_team} />.
+ </span>
+ </div>
+ </div>
+ """
+ end
def render_monthly_pageview_usage(%{usage: usage} = assigns)
when is_map_key(usage, :last_30_days) do
@@ -182,7 +216,7 @@ defmodule PlausibleWeb.Components.Billing do
~H"""
<div
id="monthly-quota-box"
- class="w-full md:w-1/3 h-32 px-2 py-4 my-4 text-center bg-gray-100 rounded dark:bg-gray-900 w-max-md"
+ class="w-full flex-1 h-32 px-2 py-4 text-center bg-gray-100 rounded dark:bg-gray-900 w-max-md"
>
<h4 class="font-black dark:text-gray-100">Monthly quota</h4>
<div class="py-2 text-xl font-medium dark:text-gray-100">
@@ -315,4 +349,37 @@ defmodule PlausibleWeb.Components.Billing do
do: "Upgrade"
defp change_plan_or_upgrade_text(_subscription), do: "Change plan"
+
+ def upgrade_call_to_action(assigns) do
+ team = Plausible.Teams.with_subscription(assigns.current_team)
+
+ upgrade_assistance_required? =
+ case Plans.get_subscription_plan(team && team.subscription) do
+ %Plan{kind: :business} -> true
+ %EnterprisePlan{} -> true
+ _ -> false
+ end
+
+ cond do
+ not is_nil(assigns.current_role) and assigns.current_role not in [:owner, :billing] ->
+ ~H"please reach out to the team owner to upgrade their subscription"
+
+ upgrade_assistance_required? ->
+ ~H"""
+ please contact <a href="mailto:[email protected]" class="underline">[email protected]</a>
+ to upgrade your subscription
+ """
+
+ true ->
+ ~H"""
+ please
+ <.link
+ class="underline inline-block"
+ href={Routes.billing_path(PlausibleWeb.Endpoint, :choose_plan)}
+ >
+ upgrade your subscription
+ </.link>
+ """
+ end
+ end
end
diff --git a/lib/plausible_web/components/billing/notice.ex b/lib/plausible_web/components/billing/notice.ex
index 2c8ecb8be7..a94d841c59 100644
--- a/lib/plausible_web/components/billing/notice.ex
+++ b/lib/plausible_web/components/billing/notice.ex
@@ -4,7 +4,7 @@ defmodule PlausibleWeb.Components.Billing.Notice do
use PlausibleWeb, :component
require Plausible.Billing.Subscription.Status
- alias Plausible.Billing.{Subscription, Plans, Subscriptions, Feature}
+ alias Plausible.Billing.{Subscription, Plans, Subscriptions}
def active_grace_period(assigns) do
if assigns.enterprise? do
@@ -63,26 +63,6 @@ defmodule PlausibleWeb.Components.Billing.Notice do
"""
end
- attr(:current_role, :atom, required: true)
- attr(:current_team, :any, required: true)
- attr(:feature_mod, :atom, required: true, values: Feature.list())
- attr(:grandfathered?, :boolean, default: false)
- attr(:rest, :global)
-
- def premium_feature(assigns) do
- ~H"""
- <.notice
- :if={@feature_mod.check_availability(@current_team) !== :ok}
- class="rounded-t-md rounded-b-none"
- title="Notice"
- {@rest}
- >
- {account_label(@current_team)} does not have access to {@feature_mod.display_name()}. To gain access to this feature,
- <.upgrade_call_to_action current_role={@current_role} current_team={@current_team} />.
- </.notice>
- """
- end
-
attr(:current_team, :any, required: true)
attr(:current_role, :atom, required: true)
attr(:limit, :integer, required: true)
@@ -91,13 +71,24 @@ defmodule PlausibleWeb.Components.Billing.Notice do
def limit_exceeded(assigns) do
~H"""
- <.notice {@rest} title="Notice">
- {account_label(@current_team)} is limited to {@limit} {@resource}. To increase this limit,
- <.upgrade_call_to_action current_team={@current_team} current_role={@current_role} />.
+ <.notice {@rest} title="Notice" data-test="limit-exceeded-notice">
+ {account_label(@current_team)} is limited to {pretty_print_resource_limit(@limit, @resource)}. To increase this limit,
+ <PlausibleWeb.Components.Billing.upgrade_call_to_action
+ current_team={@current_team}
+ current_role={@current_role}
+ />.
</.notice>
"""
end
+ defp pretty_print_resource_limit(1 = _limit, resource_plural) do
+ "a single #{String.trim_trailing(resource_plural, "s")}"
+ end
+
+ defp pretty_print_resource_limit(limit, resource_plural) do
+ "#{limit} #{resource_plural}"
+ end
+
attr(:subscription, :map, required: true)
attr(:dismissable, :boolean, default: true)
@@ -316,47 +307,6 @@ defmodule PlausibleWeb.Components.Billing.Notice do
"""
end
- attr(:current_role, :atom)
- attr(:current_team, :any)
-
- defp upgrade_call_to_action(assigns) do
- team = Plausible.Teams.with_subscription(assigns.current_team)
-
- upgrade_assistance_required? =
- case Plans.get_subscription_plan(team && team.subscription) do
- %Plausible.Billing.Plan{kind: :business} -> true
- %Plausible.Billing.EnterprisePlan{} -> true
- _ -> false
- end
-
- cond do
- not is_nil(assigns.current_role) and assigns.current_role not in [:owner, :billing] ->
- ~H"please reach out to the team owner to upgrade their subscription"
-
- upgrade_assistance_required? ->
- ~H"""
- please contact <a href="mailto:[email protected]" class="underline">[email protected]</a>
- to upgrade your subscription
- """
-
- true ->
- ~H"""
- please
- <.link
- class="underline inline-block"
- href={Routes.billing_path(PlausibleWeb.Endpoint, :choose_plan)}
- >
- upgrade your subscription
- </.link>
- """
- end
- end
-
- defp account_label(current_team) do
- if current_team do
- "This team"
- else
- "This account"
- end
- end
+ defp account_label(%Plausible.Teams.Team{setup_complete: true}), do: "This team"
+ defp account_label(_team), do: "This account"
end
diff --git a/lib/plausible_web/components/billing/plan_benefits.ex b/lib/plausible_web/components/billing/plan_benefits.ex
index 0a4f6847cc..9a2ebb83a5 100644
--- a/lib/plausible_web/components/billing/plan_benefits.ex
+++ b/lib/plausible_web/components/billing/plan_benefits.ex
@@ -126,7 +126,12 @@ defmodule PlausibleWeb.Components.Billing.PlanBenefits do
end
end
- defp site_limit_benefit(%Plan{} = plan), do: "Up to #{plan.site_limit} sites"
+ defp site_limit_benefit(%Plan{} = plan) do
+ case plan.site_limit do
+ 1 -> "One site"
+ site_limit -> "Up to #{site_limit} sites"
+ end
+ end
defp feature_benefits(%Plan{} = plan) do
Enum.flat_map(plan.features, fn feature_mod ->
diff --git a/lib/plausible_web/components/billing/plan_box.ex b/lib/plausible_web/components/billing/plan_box.ex
index 3568459d11..039d7c2b09 100644
--- a/lib/plausible_web/components/billing/plan_box.ex
+++ b/lib/plausible_web/components/billing/plan_box.ex
@@ -126,7 +126,10 @@ defmodule PlausibleWeb.Components.Billing.PlanBox do
defp render_price_info(assigns) do
~H"""
<.price_tag kind={@kind} selected_interval={@selected_interval} plan_to_render={@plan_to_render} />
- <div id={"#{@kind}-vat-notice"} class="absolute top-5 right-0 text-xs text-gray-500">
+ <div
+ id={"#{@kind}-vat-notice"}
+ class="absolute top-[32px] sm:top-[29px] md:top-[32px] lg:top-[29px] xl:top-[32px] right-0 text-xs text-gray-500"
+ >
+ VAT
<span class="hidden sm:inline lg:hidden xl:inline">
if applicable
@@ -288,18 +291,22 @@ defmodule PlausibleWeb.Components.Billing.PlanBox do
Upgrade
</PlausibleWeb.Components.Billing.paddle_button>
<% end %>
- <.tooltip :if={@exceeded_plan_limits != [] && @disabled_message}>
- <div class="absolute top-0 text-sm w-full flex items-center text-red-700 dark:text-red-500 justify-center">
- {@disabled_message}
- <Heroicons.information_circle class="hidden sm:block w-5 h-5 sm:ml-2" />
- </div>
- <:tooltip_content>
- Your usage exceeds the following limit(s):<br /><br />
- <p :for={limit <- @exceeded_plan_limits}>
- {Phoenix.Naming.humanize(limit)}<br />
- </p>
- </:tooltip_content>
- </.tooltip>
+ <div :if={@exceeded_plan_limits != [] && @disabled_message} class="flex flex-col items-center">
+ <.tooltip>
+ <div class="h-0 text-sm">
+ <div class="flex items-center text-red-700 dark:text-red-500 justify-center">
+ {@disabled_message}
+ <Heroicons.information_circle class="hidden sm:block w-5 h-5 sm:ml-2" />
+ </div>
+ </div>
+ <:tooltip_content>
+ Your usage exceeds the following limit(s):<br /><br />
+ <p :for={limit <- @exceeded_plan_limits}>
+ {Phoenix.Naming.humanize(limit)}<br />
+ </p>
+ </:tooltip_content>
+ </.tooltip>
+ </div>
<div
:if={@disabled_message && @exceeded_plan_limits == []}
class="pt-2 text-sm w-full text-red-700 dark:text-red-500 text-center"
diff --git a/lib/plausible_web/components/generic.ex b/lib/plausible_web/components/generic.ex
index 978709f206..925c0787f9 100644
--- a/lib/plausible_web/components/generic.ex
+++ b/lib/plausible_web/components/generic.ex
@@ -399,6 +399,37 @@ defmodule PlausibleWeb.Components.Generic do
"""
end
+ attr :id, :string, required: true
+ attr :js_active_var, :string, required: true
+ attr :id_suffix, :string, default: ""
+ attr :disabled, :boolean, default: false
+
+ def toggle_switch(assigns) do
+ ~H"""
+ <button
+ id={"#{@id}-#{@id_suffix}"}
+ class={["h-6", if(@disabled, do: "cursor-not-allowed", else: "cursor-pointer")]}
+ aria-labelledby={@id}
+ role="switch"
+ type="button"
+ x-on:click={"#{@js_active_var} = !#{@js_active_var}"}
+ x-bind:aria-checked={@js_active_var}
+ disabled={@disabled}
+ >
+ <span
+ class="relative inline-flex h-6 w-11 flex-shrink-0 rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-indigo-600 focus:ring-offset-2"
+ x-bind:class={"#{@js_active_var} ? 'bg-indigo-600' : 'dark:bg-gray-700 bg-gray-200'"}
+ >
+ <span
+ aria-hidden="true"
+ class="pointer-events-none inline-block h-5 w-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out"
+ x-bind:class={"#{@js_active_var} ? 'dark:bg-gray-800 translate-x-5' : 'dark:bg-gray-800 translate-x-0'"}
+ />
+ </span>
+ </button>
+ """
+ end
+
def settings_tiles(assigns) do
~H"""
<div class="text-gray-900 leading-5 dark:text-gray-100">
@@ -412,6 +443,9 @@ defmodule PlausibleWeb.Components.Generic do
slot :title, required: true
slot :subtitle, required: true
attr :feature_mod, :atom, default: nil
+ attr :feature_toggle?, :boolean, default: false
+ attr :current_role, :atom, default: nil
+ attr :current_team, :any, default: nil
attr :site, :any
attr :conn, :any
@@ -427,24 +461,37 @@ defmodule PlausibleWeb.Components.Generic do
<div class="text-sm mt-px text-gray-500 dark:text-gray-400 leading-5">
{render_slot(@subtitle)}
</div>
+ <PlausibleWeb.Components.Site.Feature.toggle
+ :if={@feature_toggle?}
+ feature_mod={@feature_mod}
+ site={@site}
+ conn={@conn}
+ />
+ </header>
+ <div class="border-b dark:border-gray-700 mx-6"></div>
+ <div class="relative">
<%= if @feature_mod do %>
- <PlausibleWeb.Components.Site.Feature.toggle
+ <PlausibleWeb.Components.Billing.feature_gate
feature_mod={@feature_mod}
- site={@site}
- conn={@conn}
- />
+ current_role={@current_role}
+ current_team={@current_team}
+ >
+ <div class="py-4 px-6">
+ {render_slot(@inner_block)}
+ </div>
+ </PlausibleWeb.Components.Billing.feature_gate>
+ <% else %>
+ <div class="py-4 px-6">
+ {render_slot(@inner_block)}
+ </div>
<% end %>
- <div class="border-b dark:border-gray-700 pb-4"></div>
- </header>
-
- <div class="pb-4 px-6">
- {render_slot(@inner_block)}
</div>
</div>
"""
end
attr(:sticky?, :boolean, default: true)
+ attr(:enabled?, :boolean, default: true)
slot(:inner_block, required: true)
slot(:tooltip_content, required: true)
@@ -456,31 +503,37 @@ defmodule PlausibleWeb.Components.Generic do
assigns = assign(assigns, wrapper_data: wrapper_data, show_inner: show_inner)
- ~H"""
- <div x-data={@wrapper_data} class="tooltip-wrapper w-full relative z-[1000]">
- <div
- x-cloak
- x-show={@show_inner}
- class="tooltip-content z-[1000] bg-gray-900 rounded text-white absolute bottom-24 sm:bottom-7 left-0 sm:w-72 p-4 text-sm font-medium"
- x-transition:enter="transition ease-out duration-200"
- x-transition:enter-start="opacity-0"
- x-transition:enter-end="opacity-100"
- x-transition:leave="transition ease-in duration-150"
- x-transition:leave-start="opacity-100"
- x-transition:leave-end="opacity-0"
- >
- {render_slot(List.first(@tooltip_content))}
- </div>
+ if assigns.enabled? do
+ ~H"""
<div
- x-on:click="sticky = true; hovered = true"
- x-on:click.outside="sticky = false; hovered = false"
- x-on:mouseover="hovered = true"
- x-on:mouseout="hovered = false"
+ x-data={@wrapper_data}
+ x-on:mouseenter="hovered = true"
+ x-on:mouseleave="hovered = false"
+ class={["w-max relative z-[1000]"]}
>
- {render_slot(@inner_block)}
+ <div
+ x-cloak
+ x-show={@show_inner}
+ class={["tooltip-content absolute pb-2 top-0 -translate-y-full z-[1000] sm:w-72"]}
+ x-transition:enter="transition ease-out duration-200"
+ x-transition:enter-start="opacity-0"
+ x-transition:enter-end="opacity-100"
+ x-transition:leave="transition ease-in duration-150"
+ x-transition:leave-start="opacity-100"
+ x-transition:leave-end="opacity-0"
+ >
+ <div class="bg-gray-900 text-white rounded p-4 text-sm font-medium">
+ {render_slot(@tooltip_content)}
+ </div>
+ </div>
+ <div x-on:click="sticky = true; hovered = true" x-on:click.outside="sticky = false">
+ {render_slot(@inner_block)}
+ </div>
</div>
- </div>
- """
+ """
+ else
+ ~H"{render_slot(@inner_block)}"
+ end
end
slot :inner_block, required: true
diff --git a/lib/plausible_web/controllers/billing_controller.ex b/lib/plausible_web/controllers/billing_controller.ex
index eb8f509933..52517f0b6a 100644
--- a/lib/plausible_web/controllers/billing_controller.ex
+++ b/lib/plausible_web/controllers/billing_controller.ex
@@ -78,7 +78,7 @@ defmodule PlausibleWeb.BillingController do
end
def upgrade_success(conn, _params) do
- render(conn, "upgrade_success.html")
+ render(conn, "upgrade_success.html", disable_global_notices?: true)
end
def change_plan_preview(conn, %{"plan_id" => new_plan_id}) do
diff --git a/lib/plausible_web/live/components/form.ex b/lib/plausible_web/live/components/form.ex
index 7b0d4057e0..064a6561df 100644
--- a/lib/plausible_web/live/components/form.ex
+++ b/lib/plausible_web/live/components/form.ex
@@ -18,7 +18,7 @@ defmodule PlausibleWeb.Live.Components.Form do
<.input name="my-input" errors={["oh no!"]} />
"""
- @default_input_class "text-sm text-gray-900 dark:text-white dark:bg-gray-900 block pl-3.5 py-2.5 border-gray-300 dark:border-gray-500 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 rounded-md"
+ @default_input_class "text-sm text-gray-900 dark:text-white dark:bg-gray-900 block pl-3.5 py-2.5 border-gray-300 dark:border-gray-700 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 rounded-md"
attr(:id, :any, default: nil)
attr(:name, :any)
diff --git a/lib/plausible_web/live/goal_settings/form.ex b/lib/plausible_web/live/goal_settings/form.ex
index f020fd7b66..33bd58ec22 100644
--- a/lib/plausible_web/live/goal_settings/form.ex
+++ b/lib/plausible_web/live/goal_settings/form.ex
@@ -387,6 +387,12 @@ defmodule PlausibleWeb.Live.GoalSettings.Form do
"""
end
+ def revenue_goal_settings(%{goal: %{currency: nil}} = assigns) do
+ ~H"""
+ <div class="h-2"></div>
+ """
+ end
+
def revenue_goal_settings(assigns) do
js_data =
Jason.encode!(%{
@@ -397,57 +403,20 @@ defmodule PlausibleWeb.Live.GoalSettings.Form do
assigns = assign(assigns, selected_currency: currency_option(assigns.goal), js_data: js_data)
~H"""
- <div class="mt-6 space-y-3" x-data={@js_data}>
- <PlausibleWeb.Components.Billing.Notice.premium_feature
- current_role={@site_role}
- current_team={@site_team}
- feature_mod={Plausible.Billing.Feature.RevenueGoals}
- class="rounded-b-md"
- />
- <button
- id={"currency-toggle-#{@suffix}"}
- class={[
- "flex items-center w-max mb-3",
- if @has_access_to_revenue_goals? and is_nil(@goal) do
- "cursor-pointer"
- else
- "cursor-not-allowed"
- end
- ]}
- aria-labelledby="enable-revenue-tracking"
- role="switch"
- type="button"
- x-on:click="active = !active; currency = ''"
- x-bind:aria-checked="active"
- disabled={not @has_access_to_revenue_goals? or not is_nil(@goal)}
- >
- <span
- id={"currency-container1-#{@suffix}"}
- class="relative inline-flex h-6 w-11 flex-shrink-0 rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-indigo-600 focus:ring-offset-2"
- x-bind:class="active ? 'bg-indigo-600' : 'dark:bg-gray-700 bg-gray-200'"
- >
- <span
- id={"currency-container2-#{@suffix}"}
- aria-hidden="true"
- class="pointer-events-none inline-block h-5 w-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out"
- x-bind:class="active ? 'dark:bg-gray-800 translate-x-5' : 'dark:bg-gray-800 translate-x-0'"
- />
- </span>
- <span
- class={[
- "ml-3 text-sm font-medium",
- if(@has_access_to_revenue_goals?,
- do: "text-gray-900 dark:text-gray-100",
- else: "text-gray-500 dark:text-gray-400"
- )
- ]}
- id="enable-revenue-tracking"
+ <div x-data={@js_data}>
+ <%= if is_nil(@goal) do %>
+ <div class="mt-6 mb-3">
+ <.revenue_toggle {assigns} />
+ </div>
+ <% else %>
+ <label
+ data-test="goal-currency-label"
+ class="mt-4 mb-2 text-sm block font-medium dark:text-gray-100"
>
- Enable Revenue Tracking
- </span>
- </button>
-
- <div x-show="active" id={"revenue-input-#{@suffix}"}>
+ Currency
+ </label>
+ <% end %>
+ <div class="mb-2" x-show="active" id={"revenue-input-#{@suffix}"}>
<.live_component
id={"currency_input_#{@suffix}"}
submit_name={@f[:currency].name}
@@ -616,4 +585,37 @@ defmodule PlausibleWeb.Live.GoalSettings.Form do
else
defp currency_option(_), do: nil
end
+
+ defp revenue_toggle(assigns) do
+ ~H"""
+ <.tooltip enabled?={not @has_access_to_revenue_goals?}>
+ <:tooltip_content>
+ <div class="text-xs">
+ To get access to this feature
+ <PlausibleWeb.Components.Billing.upgrade_call_to_action
+ current_role={@site_role}
+ current_team={@site_team}
+ />.
+ </div>
+ </:tooltip_content>
+ <div class="flex itemx-center mb-3">
+ <PlausibleWeb.Components.Generic.toggle_switch
+ id="enable-revenue-tracking"
+ id_suffix={@suffix}
+ js_active_var="active"
+ disabled={not @has_access_to_revenue_goals?}
+ />
+ <span class={[
+ "ml-3 text-sm font-medium",
+ if(@has_access_to_revenue_goals?,
+ do: "text-gray-900 dark:text-gray-100",
+ else: "text-gray-500 dark:text-gray-400"
+ )
+ ]}>
+ Enable Revenue Tracking
+ </span>
+ </div>
+ </.tooltip>
+ """
+ end
end
diff --git a/lib/plausible_web/live/goal_settings/list.ex b/lib/plausible_web/live/goal_settings/list.ex
index 3476ebd210..3573726c2f 100644
--- a/lib/plausible_web/live/goal_settings/list.ex
+++ b/lib/plausible_web/live/goal_settings/list.ex
@@ -31,23 +31,26 @@ defmodule PlausibleWeb.Live.GoalSettings.List do
<%= if Enum.count(@goals) > 0 do %>
<.table rows={@goals}>
<:tbody :let={goal}>
- <.td truncate max_width="max-w-40" height="h-16">
- <div class="flex">
- <div class="truncate block">
- <%= if not @revenue_goals_enabled? && goal.currency do %>
- <div class="truncate">
- {goal}
- <br />
- <span class="text-red-600">
- Unlock Revenue Goals by upgrading to a business plan
- </span>
- </div>
- <% else %>
- <.goal_description goal={goal} />
- <span>{goal}</span>
- <% end %>
+ <.td max_width="max-w-40" height="h-16">
+ <%= if not @revenue_goals_enabled? && goal.currency do %>
+ <div class="truncate">{goal}</div>
+ <.tooltip>
+ <:tooltip_content>
+ <p class="text-xs">
+ Revenue Goals act like regular custom<br />
+ events without a Business subscription<br />
+ </p>
+ </:tooltip_content>
+ <span class="w-max flex items-center text-gray-500 italic text-sm">
+ <Heroicons.lock_closed solid class="size-4 mr-1" /> Upgrade Required
+ </span>
+ </.tooltip>
+ <% else %>
+ <div class="truncate">
+ <.goal_description goal={goal} />
</div>
- </div>
+ <div class="truncate">{goal}</div>
+ <% end %>
</.td>
<.td hide_on_mobile height="h-16">
<span :if={goal.page_path && goal.scroll_threshold > -1}>Scroll</span>
diff --git a/lib/plausible_web/live/team_management.ex b/lib/plausible_web/live/team_management.ex
index 9c940cbc99..2203902ba4 100644
--- a/lib/plausible_web/live/team_management.ex
+++ b/lib/plausible_web/live/team_management.ex
@@ -42,7 +42,7 @@ defmodule PlausibleWeb.Live.TeamManagement do
<.flash_messages flash={@flash} />
<PlausibleWeb.Components.Billing.Notice.limit_exceeded
- :if={at_limit?(@layout, @team_members_limit)}
+ :if={@team_members_limit != 0 and at_limit?(@layout, @team_members_limit)}
current_role={@current_team_role}
current_team={@current_team}
limit={@team_members_limit}
diff --git a/lib/plausible_web/templates/layout/_header.html.heex b/lib/plausible_web/templates/layout/_header.html.heex
index da20b8d3ee..652813ba39 100644
--- a/lib/plausible_web/templates/layout/_header.html.heex
+++ b/lib/plausible_web/templates/layout/_header.html.heex
@@ -92,9 +92,12 @@
Account Settings
</.dropdown_item>
- <div :if={@my_team && @my_team.id == @current_team.id}>
+ <div :if={
+ @my_team && @my_team.id == @current_team.id &&
+ Plausible.Billing.Feature.Teams.check_availability(@current_team) == :ok
+ }>
<.dropdown_item class="flex" href={Routes.team_setup_path(@conn, :setup)}>
- <span class="flex-1">
+ <span data-test="create-a-team-cta" class="flex-1">
Create a Team
</span>
<span class="ml-1 bg-indigo-700 text-gray-100 text-xs p-1 rounded">
diff --git a/lib/plausible_web/templates/settings/api_keys.html.heex b/lib/plausible_web/templates/settings/api_keys.html.heex
index 191aaddc8d..99c8ac0437 100644
--- a/lib/plausible_web/templates/settings/api_keys.html.heex
+++ b/lib/plausible_web/templates/settings/api_keys.html.heex
@@ -1,5 +1,10 @@
<.settings_tiles>
- <.tile docs="stats-api">
+ <.tile
+ docs="stats-api"
+ current_role={@current_team_role}
+ current_team={@current_team}
+ feature_mod={Plausible.Billing.Feature.StatsAPI}
+ >
<:title>
<a id="api-keys">API Keys</a>
</:title>
@@ -7,21 +12,16 @@
Manage your API keys
</:subtitle>
- <PlausibleWeb.Components.Billing.Notice.premium_feature
- current_role={@current_team_role}
- current_team={@current_team}
- feature_mod={Plausible.Billing.Feature.StatsAPI}
- />
-
<.filter_bar filtering_enabled?={false}>
- <.button_link
- :if={Plausible.Billing.Feature.StatsAPI.check_availability(@current_team) == :ok}
- href={Routes.settings_path(@conn, :new_api_key)}
- >
+ <.button_link mt?={false} href={Routes.settings_path(@conn, :new_api_key)}>
New API Key
</.button_link>
</.filter_bar>
+ <p :if={Enum.empty?(@api_keys)} class="mb-8 text-center text-sm">
+ No API keys configured yet.
+ </p>
+
<.table rows={@api_keys}>
<:thead>
<.th>
diff --git a/lib/plausible_web/templates/settings/new_api_key.html.heex b/lib/plausible_web/templates/settings/new_api_key.html.heex
index af41d5db63..cc8d6262d3 100644
--- a/lib/plausible_web/templates/settings/new_api_key.html.heex
+++ b/lib/plausible_web/templates/settings/new_api_key.html.heex
@@ -1,74 +1,81 @@
<.focus_box>
<:title>Create new API key</:title>
- <.form :let={f} for={@changeset} action={Routes.settings_path(@conn, :api_keys)}>
- <.input type="text" field={f[:name]} label="Name" placeholder="Development" />
+ <div x-data="{ submitDisabled: false }">
+ <.form :let={f} for={@changeset} action={Routes.settings_path(@conn, :api_keys)}>
+ <.input type="text" field={f[:name]} label="Name" placeholder="Development" />
- <input :if={ce?()} type="hidden" name={f[:type].name} value={f[:type].value} />
+ <input :if={ce?()} type="hidden" name={f[:type].name} value={f[:type].value} />
- <div :if={ee?()} x-data="{ showNotice: false }" class="mt-4 flex flex-col gap-y-2">
- <div>
- <.label>Type</.label>
- </div>
+ <div :if={ee?()} class="mt-4 flex flex-col gap-y-2">
+ <div>
+ <.label>Type</.label>
+ </div>
- <.input
- x-on:click="showNotice = false"
- type="radio"
- class="block h-5 w-5 dark:bg-gray-700 border-gray-300 text-indigo-600 focus:ring-indigo-600"
- id={f[:type].id <> "_0"}
- name={f[:type].name}
- value="stats_api"
- checked={f[:type].value == "stats_api"}
- label="Stats API"
- >
- <:help_content>
- Full access to
- <.styled_link href="https://plausible.io/docs/stats-api">Stats API</.styled_link>
- </:help_content>
- </.input>
+ <.input
+ x-on:click="submitDisabled = false"
+ type="radio"
+ class="block h-5 w-5 dark:bg-gray-700 border-gray-300 text-indigo-600 focus:ring-indigo-600"
+ id={f[:type].id <> "_0"}
+ name={f[:type].name}
+ value="stats_api"
+ checked={f[:type].value == "stats_api"}
+ label="Stats API"
+ >
+ <:help_content>
+ Full access to
+ <.styled_link href="https://plausible.io/docs/stats-api">Stats API</.styled_link>
+ </:help_content>
+ </.input>
- <.input
- x-on:click={"showNotice = " <> if(@sites_api_enabled?, do: "false", else: "true")}
- type="radio"
- id={f[:type].id <> "_1"}
- name={f[:type].name}
- value="sites_api"
- checked={f[:type].value == "sites_api"}
- label="Sites API"
- >
- <:help_content>
- Full access to
- <.styled_link href="https://plausible.io/docs/stats-api">Stats API</.styled_link>
- and
- <.styled_link href="https://plausible.io/docs/sites-api">Sites API</.styled_link>
- </:help_content>
- </.input>
+ <.input
+ x-on:click={"submitDisabled = " <> if(@sites_api_enabled?, do: "false", else: "true")}
+ type="radio"
+ id={f[:type].id <> "_1"}
+ name={f[:type].name}
+ value="sites_api"
+ checked={f[:type].value == "sites_api"}
+ label="Sites API"
+ >
+ <:help_content>
+ Full access to
+ <.styled_link href="https://plausible.io/docs/stats-api">Stats API</.styled_link>
+ and
+ <.styled_link href="https://plausible.io/docs/sites-api">Sites API</.styled_link>
+ </:help_content>
+ </.input>
- <div x-show="showNotice" class="flex gap-x-2 text-sm">
- <Heroicons.exclamation_triangle class="mt-1 block w-4 h-4 shrink-0" />
- <div>
- Your current subscription plan does not include Sites API access.
- <a href="https://plausible.io/contact" class="underline">Contact us</a>
- if interested.
+ <div x-show="submitDisabled" class="flex gap-x-2 text-sm">
+ <Heroicons.exclamation_triangle class="mt-1 block w-4 h-4 shrink-0" />
+ <div>
+ Your current subscription plan does not include Sites API access.
+ <a href="https://plausible.io/contact" class="underline">Contact us</a>
+ if interested.
+ </div>
</div>
</div>
- </div>
- <div class="mt-4">
- <.input_with_clipboard id="key-input" name="api_key[key]" label="Key" value={f[:key].value} />
+ <div class="mt-4">
+ <.input_with_clipboard
+ id="key-input"
+ name="api_key[key]"
+ label="Key"
+ value={f[:key].value}
+ />
- <.error :for={
- msg <- Enum.map(f[:key].errors, &PlausibleWeb.Live.Components.Form.translate_error/1)
- }>
- {msg}
- </.error>
+ <.error :for={
+ msg <- Enum.map(f[:key].errors, &PlausibleWeb.Live.Components.Form.translate_error/1)
+ }>
+ {msg}
+ </.error>
- <p class="mt-2 text-gray-500 dark:text-gray-200">
- Make sure to store the key in a secure place. Once created, we will not be able to show it again.
- </p>
- </div>
- <.button type="submit" class="w-full">
- Create API key
- </.button>
- </.form>
+ <p class="mt-2 text-gray-500 dark:text-gray-200">
+ Make sure to store the key in a secure place. Once created, we will not be able to show it again.
+ </p>
+ </div>
+ <.button type="submit" class="w-full" x-bind:disabled="submitDisabled">
+ Create API key
+ </.button>
+ </.form>
+ </div>
</.focus_box>
diff --git a/lib/plausible_web/templates/settings/subscription.html.heex b/lib/plausible_web/templates/settings/subscription.html.heex
index 92d2cc6b3c..966eae162d 100644
--- a/lib/plausible_web/templates/settings/subscription.html.heex
+++ b/lib/plausible_web/templates/settings/subscription.html.heex
@@ -31,12 +31,12 @@
dismissable={false}
/>
- <div class="flex flex-col items-center justify-between sm:flex-row sm:items-start">
+ <div class="flex flex-col gap-4 my-4 items-center justify-between sm:flex-row sm:items-start">
<PlausibleWeb.Components.Billing.monthly_quota_box
team={@current_team}
subscription={@subscription}
/>
- <div class="w-full md:w-1/3 h-32 px-2 py-4 my-4 text-center bg-gray-100 rounded dark:bg-gray-900">
+ <div class="w-full flex-1 h-32 px-2 py-4 text-center bg-gray-100 rounded dark:bg-gray-900">
<h4 class="font-black dark:text-gray-100">Next bill amount</h4>
<%= if Plausible.Billing.Subscription.Status.in?(@subscription, [Plausible.Billing.Subscription.Status.active(), Plausible.Billing.Subscription.Status.past_due()]) do %>
<div class="py-2 text-xl font-medium dark:text-gray-100">
@@ -49,7 +49,7 @@
<div class="py-2 text-xl font-medium dark:text-gray-100">---</div>
<% end %>
</div>
- <div class="w-full md:w-1/3 h-32 px-2 py-4 my-4 text-center bg-gray-100 rounded dark:bg-gray-900">
+ <div class="w-full flex-1 h-32 px-2 py-4 text-center bg-gray-100 rounded dark:bg-gray-900">
<h4 class="font-black dark:text-gray-100">Next bill date</h4>
<%= if @subscription && @subscription.next_bill_date && Plausible.Billing.Subscription.Status.in?(@subscription, [Plausible.Billing.Subscription.Status.active(), Plausible.Billing.Subscription.Status.past_due()]) do %>
diff --git a/lib/plausible_web/templates/settings/team_general.html.heex b/lib/plausible_web/templates/settings/team_general.html.heex
index e8585895a0..e83fe523c4 100644
--- a/lib/plausible_web/templates/settings/team_general.html.heex
+++ b/lib/plausible_web/templates/settings/team_general.html.heex
@@ -25,7 +25,12 @@
</.button>
</.form>
</.tile>
- <.tile docs="users-roles#managing-team-member-roles">
+ <.tile
+ docs="users-roles#managing-team-member-roles"
+ current_role={@current_team_role}
+ current_team={@current_team}
+ feature_mod={Plausible.Billing.Feature.Teams}
+ >
<:title>
<a id="team-members">Team Members</a>
</:title>
diff --git a/lib/plausible_web/templates/site/settings_funnels.html.heex b/lib/plausible_web/templates/site/settings_funnels.html.heex
index e0e3863467..90842598a3 100644
--- a/lib/plausible_web/templates/site/settings_funnels.html.heex
+++ b/lib/plausible_web/templates/site/settings_funnels.html.heex
@@ -2,6 +2,9 @@
<.tile
docs="funnel-analysis"
feature_mod={Plausible.Billing.Feature.Funnels}
+ feature_toggle?={true}
+ current_role={@site_role}
+ current_team={@site_team}
site={@site}
conn={@conn}
>
@@ -12,16 +15,8 @@
Compose Goals into Funnels
</:subtitle>
- <PlausibleWeb.Components.Billing.Notice.premium_feature
- current_role={@site_role}
- current_team={@site_team}
- feature_mod={Plausible.Billing.Feature.Funnels}
- />
-
- <div :if={Plausible.Billing.Feature.Funnels.enabled?(@site)}>
- {live_render(@conn, PlausibleWeb.Live.FunnelSettings,
- session: %{"site_id" => @site.id, "domain" => @site.domain}
- )}
- </div>
+ {live_render(@conn, PlausibleWeb.Live.FunnelSettings,
+ session: %{"site_id" => @site.id, "domain" => @site.domain}
+ )}
</.tile>
</.settings_tiles>
diff --git a/lib/plausible_web/templates/site/settings_goals.html.heex b/lib/plausible_web/templates/site/settings_goals.html.heex
index 7f7732fd09..ba64541773 100644
--- a/lib/plausible_web/templates/site/settings_goals.html.heex
+++ b/lib/plausible_web/templates/site/settings_goals.html.heex
@@ -2,6 +2,7 @@
<.tile
docs="goal-conversions"
feature_mod={Plausible.Billing.Feature.Goals}
+ feature_toggle?={true}
site={@site}
conn={@conn}
>
diff --git a/lib/plausible_web/templates/site/settings_people.html.heex b/lib/plausible_web/templates/site/settings_people.html.heex
index 458f81b968..41b2a420a9 100644
--- a/lib/plausible_web/templates/site/settings_people.html.heex
+++ b/lib/plausible_web/templates/site/settings_people.html.heex
@@ -1,13 +1,17 @@
<.settings_tiles>
- <PlausibleWeb.Team.Notice.owner_cta_banner :if={
- @site_role == :owner and not Plausible.Teams.setup?(@site.team)
- } />
+ <%= if not Plausible.Teams.setup?(@site.team) and Plausible.Billing.Feature.Teams.check_availability(@site.team) == :ok do %>
+ <PlausibleWeb.Team.Notice.owner_cta_banner :if={@site_role == :owner} />
+ <PlausibleWeb.Team.Notice.guest_cta_banner :if={@site_role != :owner} />
+ <% end %>
- <PlausibleWeb.Team.Notice.guest_cta_banner :if={
- @site_role != :owner and not Plausible.Teams.setup?(@site.team)
- } />
-
- <.tile docs="users-roles">
+ <.tile
+ docs="users-roles"
+ feature_mod={Plausible.Billing.Feature.Teams}
+ site={@site}
+ current_role={@site_role}
+ current_team={@site_team}
+ conn={@conn}
+ >
<:title>People</:title>
<:subtitle>Invite your friends or coworkers</:subtitle>
diff --git a/lib/plausible_web/templates/site/settings_props.html.heex b/lib/plausible_web/templates/site/settings_props.html.heex
index 39f888b43f..1648b23c4c 100644
--- a/lib/plausible_web/templates/site/settings_props.html.heex
+++ b/lib/plausible_web/templates/site/settings_props.html.heex
@@ -2,7 +2,10 @@
<.tile
docs="custom-props/introduction"
feature_mod={Plausible.Billing.Feature.Props}
+ feature_toggle?={true}
site={@site}
+ current_role={@site_role}
+ current_team={@site_team}
conn={@conn}
>
<:title>
@@ -13,18 +16,9 @@
create custom metrics.
</:subtitle>
- <PlausibleWeb.Components.Billing.Notice.premium_feature
- current_role={@site_role}
- current_team={@site_team}
- feature_mod={Plausible.Billing.Feature.Props}
- grandfathered?
- />
-
- <div :if={Plausible.Billing.Feature.Props.enabled?(@site)}>
- {live_render(@conn, PlausibleWeb.Live.PropsSettings,
- id: "props-form",
- session: %{"site_id" => @site.id, "domain" => @site.domain}
- )}
- </div>
+ {live_render(@conn, PlausibleWeb.Live.PropsSettings,
+ id: "props-form",
+ session: %{"site_id" => @site.id, "domain" => @site.domain}
+ )}
</.tile>
</.settings_tiles>
diff --git a/lib/plausible_web/templates/site/settings_visibility.html.heex b/lib/plausible_web/templates/site/settings_visibility.html.heex
index 85ab7d79d1..2ede80898c 100644
--- a/lib/plausible_web/templates/site/settings_visibility.html.heex
+++ b/lib/plausible_web/templates/site/settings_visibility.html.heex
@@ -27,7 +27,14 @@
</.form>
</.tile>
- <.tile docs="shared-links">
+ <.tile
+ docs="shared-links"
+ feature_mod={Plausible.Billing.Feature.SharedLinks}
+ site={@site}
+ current_role={@site_role}
+ current_team={@site_team}
+ conn={@conn}
+ >
<:title>
Shared Links
</:title>
@@ -80,7 +87,14 @@
</.table>
</.tile>
- <.tile docs="embed-dashboard">
+ <.tile
+ docs="embed-dashboard"
+ feature_mod={Plausible.Billing.Feature.SharedLinks}
+ site={@site}
+ current_role={@site_role}
+ current_team={@site_team}
+ conn={@conn}
+ >
<:title>
Embed Dashboard
</:title>
diff --git a/priv/plans_v5.json b/priv/plans_v5.json
index afb9d05b69..2705b0585b 100644
--- a/priv/plans_v5.json
+++ b/priv/plans_v5.json
@@ -5,8 +5,8 @@
"monthly_pageview_limit": 10000,
"monthly_product_id": "910413",
"yearly_product_id": "910414",
- "site_limit": 3,
- "team_member_limit": 1,
+ "site_limit": 1,
+ "team_member_limit": 0,
"features": [
"goals"
],
@@ -18,8 +18,8 @@
"monthly_pageview_limit": 100000,
"monthly_product_id": "910415",
"yearly_product_id": "910416",
- "site_limit": 3,
- "team_member_limit": 1,
+ "site_limit": 1,
+ "team_member_limit": 0,
"features": [
"goals"
],
@@ -31,8 +31,8 @@
"monthly_pageview_limit": 200000,
"monthly_product_id": "910417",
"yearly_product_id": "910418",
- "site_limit": 3,
- "team_member_limit": 1,
+ "site_limit": 1,
+ "team_member_limit": 0,
"features": [
"goals"
],
@@ -44,8 +44,8 @@
"monthly_pageview_limit": 500000,
"monthly_product_id": "910419",
"yearly_product_id": "910420",
- "site_limit": 3,
- "team_member_limit": 1,
+ "site_limit": 1,
+ "team_member_limit": 0,
"features": [
"goals"
],
@@ -57,8 +57,8 @@
"monthly_pageview_limit": 1000000,
"monthly_product_id": "910421",
"yearly_product_id": "910422",
- "site_limit": 3,
- "team_member_limit": 1,
+ "site_limit": 1,
+ "team_member_limit": 0,
"features": [
"goals"
],
@@ -70,8 +70,8 @@
"monthly_pageview_limit": 2000000,
"monthly_product_id": "910423",
"yearly_product_id": "910424",
- "site_limit": 3,
- "team_member_limit": 1,
+ "site_limit": 1,
+ "team_member_limit": 0,
"features": [
"goals"
],
@@ -83,8 +83,8 @@
"monthly_pageview_limit": 5000000,
"monthly_product_id": "910425",
"yearly_product_id": "910426",
- "site_limit": 3,
- "team_member_limit": 1,
+ "site_limit": 1,
+ "team_member_limit": 0,
"features": [
"goals"
],
@@ -96,8 +96,8 @@
"monthly_pageview_limit": 10000000,
"monthly_product_id": "910427",
"yearly_product_id": "910428",
- "site_limit": 3,
- "team_member_limit": 1,
+ "site_limit": 1,
+ "team_member_limit": 0,
"features": [
"goals"
],
@@ -109,7 +109,7 @@
"monthly_pageview_limit": 10000,
"monthly_product_id": "910429",
"yearly_product_id": "910430",
- "site_limit": 10,
+ "site_limit": 3,
"team_member_limit": 3,
"features": [
"goals",
@@ -125,7 +125,7 @@
"monthly_pageview_limit": 100000,
"monthly_product_id": "910431",
"yearly_product_id": "910432",
- "site_limit": 10,
+ "site_limit": 3,
"team_member_limit": 3,
"features": [
"goals",
@@ -141,7 +141,7 @@
"monthly_pageview_limit": 200000,
"monthly_product_id": "910433",
"yearly_product_id": "910434",
- "site_limit": 10,
+ "site_limit": 3,
"team_member_limit": 3,
"features": [
"goals",
@@ -157,7 +157,7 @@
"monthly_pageview_limit": 500000,
"monthly_product_id": "910435",
"yearly_product_id": "910436",
- "site_limit": 10,
+ "site_limit": 3,
"team_member_limit": 3,
"features": [
"goals",
@@ -173,7 +173,7 @@
"monthly_pageview_limit": 1000000,
"monthly_product_id": "910437",
"yearly_product_id": "910438",
- "site_limit": 10,
+ "site_limit": 3,
"team_member_limit": 3,
"features": [
"goals",
@@ -189,7 +189,7 @@
"monthly_pageview_limit": 2000000,
"monthly_product_id": "910439",
"yearly_product_id": "910440",
- "site_limit": 10,
+ "site_limit": 3,
"team_member_limit": 3,
"features": [
"goals",
@@ -205,7 +205,7 @@
"monthly_pageview_limit": 5000000,
"monthly_product_id": "910441",
"yearly_product_id": "910442",
- "site_limit": 10,
+ "site_limit": 3,
"team_member_limit": 3,
"features": [
"goals",
@@ -221,7 +221,7 @@
"monthly_pageview_limit": 10000000,
"monthly_product_id": "910443",
"yearly_product_id": "910444",
- "site_limit": 10,
+ "site_limit": 3,
"team_member_limit": 3,
"features": [
"goals",
@@ -237,7 +237,7 @@
"monthly_pageview_limit": 10000,
"monthly_product_id": "910445",
"yearly_product_id": "910446",
- "site_limit": 50,
+ "site_limit": 10,
"team_member_limit": 10,
"features": [
"goals",
@@ -257,7 +257,7 @@
"monthly_pageview_limit": 100000,
"monthly_product_id": "910447",
"yearly_product_id": "910448",
- "site_limit": 50,
+ "site_limit": 10,
"team_member_limit": 10,
"features": [
"goals",
@@ -277,7 +277,7 @@
"monthly_pageview_limit": 200000,
"monthly_product_id": "910449",
"yearly_product_id": "910450",
- "site_limit": 50,
+ "site_limit": 10,
"team_member_limit": 10,
"features": [
"goals",
@@ -297,7 +297,7 @@
"monthly_pageview_limit": 500000,
"monthly_product_id": "910451",
"yearly_product_id": "910452",
- "site_limit": 50,
+ "site_limit": 10,
"team_member_limit": 10,
"features": [
"goals",
@@ -317,7 +317,7 @@
"monthly_pageview_limit": 1000000,
"monthly_product_id": "910453",
"yearly_product_id": "910454",
- "site_limit": 50,
+ "site_limit": 10,
"team_member_limit": 10,
"features": [
"goals",
@@ -337,7 +337,7 @@
"monthly_pageview_limit": 2000000,
"monthly_product_id": "910455",
"yearly_product_id": "910456",
- "site_limit": 50,
+ "site_limit": 10,
"team_member_limit": 10,
"features": [
"goals",
@@ -357,7 +357,7 @@
"monthly_pageview_limit": 5000000,
"monthly_product_id": "910457",
"yearly_product_id": "910458",
- "site_limit": 50,
+ "site_limit": 10,
"team_member_limit": 10,
"features": [
"goals",
@@ -377,7 +377,7 @@
"monthly_pageview_limit": 10000000,
"monthly_product_id": "910459",
"yearly_product_id": "910460",
- "site_limit": 50,
+ "site_limit": 10,
"team_member_limit": 10,
"features": [
"goals",
diff --git a/priv/sandbox_plans_v5.json b/priv/sandbox_plans_v5.json
index 6c593de8f0..2a39c79d51 100644
--- a/priv/sandbox_plans_v5.json
+++ b/priv/sandbox_plans_v5.json
@@ -5,8 +5,8 @@
"monthly_pageview_limit": 10000,
"monthly_product_id": "78943",
"yearly_product_id": "78944",
- "site_limit": 3,
- "team_member_limit": 1,
+ "site_limit": 1,
+ "team_member_limit": 0,
"features": [
"goals"
],
@@ -18,8 +18,8 @@
"monthly_pageview_limit": 100000,
"monthly_product_id": "78945",
"yearly_product_id": "78946",
- "site_limit": 3,
- "team_member_limit": 1,
+ "site_limit": 1,
+ "team_member_limit": 0,
"features": [
"goals"
],
@@ -31,8 +31,8 @@
"monthly_pageview_limit": 200000,
"monthly_product_id": "78947",
"yearly_product_id": "78948",
- "site_limit": 3,
- "team_member_limit": 1,
+ "site_limit": 1,
+ "team_member_limit": 0,
"features": [
"goals"
],
@@ -44,8 +44,8 @@
"monthly_pageview_limit": 500000,
"monthly_product_id": "78949",
"yearly_product_id": "78950",
- "site_limit": 3,
- "team_member_limit": 1,
+ "site_limit": 1,
+ "team_member_limit": 0,
"features": [
"goals"
],
@@ -57,8 +57,8 @@
"monthly_pageview_limit": 1000000,
"monthly_product_id": "78951",
"yearly_product_id": "78952",
- "site_limit": 3,
- "team_member_limit": 1,
+ "site_limit": 1,
+ "team_member_limit": 0,
"features": [
"goals"
],
@@ -70,8 +70,8 @@
"monthly_pageview_limit": 2000000,
"monthly_product_id": "78953",
"yearly_product_id": "78954",
- "site_limit": 3,
- "team_member_limit": 1,
+ "site_limit": 1,
+ "team_member_limit": 0,
"features": [
"goals"
],
@@ -83,8 +83,8 @@
"monthly_pageview_limit": 5000000,
"monthly_product_id": "78955",
"yearly_product_id": "78956",
- "site_limit": 3,
- "team_member_limit": 1,
+ "site_limit": 1,
+ "team_member_limit": 0,
"features": [
"goals"
],
@@ -96,8 +96,8 @@
"monthly_pageview_limit": 10000000,
"monthly_product_id": "78957",
"yearly_product_id": "78958",
- "site_limit": 3,
- "team_member_limit": 1,
+ "site_limit": 1,
+ "team_member_limit": 0,
"features": [
"goals"
],
@@ -109,7 +109,7 @@
"monthly_pageview_limit": 10000,
"monthly_product_id": "78959",
"yearly_product_id": "78960",
- "site_limit": 10,
+ "site_limit": 3,
"team_member_limit": 3,
"features": [
"goals",
@@ -125,7 +125,7 @@
"monthly_pageview_limit": 100000,
"monthly_product_id": "78961",
"yearly_product_id": "78962",
- "site_limit": 10,
+ "site_limit": 3,
"team_member_limit": 3,
"features": [
"goals",
@@ -141,7 +141,7 @@
"monthly_pageview_limit": 200000,
"monthly_product_id": "78963",
"yearly_product_id": "78964",
- "site_limit": 10,
+ "site_limit": 3,
"team_member_limit": 3,
"features": [
"goals",
@@ -157,7 +157,7 @@
"monthly_pageview_limit": 500000,
"monthly_product_id": "78965",
"yearly_product_id": "78966",
- "site_limit": 10,
+ "site_limit": 3,
"team_member_limit": 3,
"features": [
"goals",
@@ -173,7 +173,7 @@
"monthly_pageview_limit": 1000000,
"monthly_product_id": "78967",
"yearly_product_id": "78968",
- "site_limit": 10,
+ "site_limit": 3,
"team_member_limit": 3,
"features": [
"goals",
@@ -189,7 +189,7 @@
"monthly_pageview_limit": 2000000,
"monthly_product_id": "78969",
"yearly_product_id": "78970",
- "site_limit": 10,
+ "site_limit": 3,
"team_member_limit": 3,
"features": [
"goals",
@@ -205,7 +205,7 @@
"monthly_pageview_limit": 5000000,
"monthly_product_id": "78971",
"yearly_product_id": "78972",
- "site_limit": 10,
+ "site_limit": 3,
"team_member_limit": 3,
"features": [
"goals",
@@ -221,7 +221,7 @@
"monthly_pageview_limit": 10000000,
"monthly_product_id": "78973",
"yearly_product_id": "78974",
- "site_limit": 10,
+ "site_limit": 3,
"team_member_limit": 3,
"features": [
"goals",
@@ -237,7 +237,7 @@
"monthly_pageview_limit": 10000,
"monthly_product_id": "78975",
"yearly_product_id": "78976",
- "site_limit": 50,
+ "site_limit": 10,
"team_member_limit": 10,
"features": [
"goals",
@@ -257,7 +257,7 @@
"monthly_pageview_limit": 100000,
"monthly_product_id": "78977",
"yearly_product_id": "78978",
- "site_limit": 50,
+ "site_limit": 10,
"team_member_limit": 10,
"features": [
"goals",
@@ -277,7 +277,7 @@
"monthly_pageview_limit": 200000,
"monthly_product_id": "78979",
"yearly_product_id": "78980",
- "site_limit": 50,
+ "site_limit": 10,
"team_member_limit": 10,
"features": [
"goals",
@@ -297,7 +297,7 @@
"monthly_pageview_limit": 500000,
"monthly_product_id": "78981",
"yearly_product_id": "78982",
- "site_limit": 50,
+ "site_limit": 10,
"team_member_limit": 10,
"features": [
"goals",
@@ -317,7 +317,7 @@
"monthly_pageview_limit": 1000000,
"monthly_product_id": "78983",
"yearly_product_id": "78984",
- "site_limit": 50,
+ "site_limit": 10,
"team_member_limit": 10,
"features": [
"goals",
@@ -337,7 +337,7 @@
"monthly_pageview_limit": 2000000,
"monthly_product_id": "78985",
"yearly_product_id": "78986",
- "site_limit": 50,
+ "site_limit": 10,
"team_member_limit": 10,
"features": [
"goals",
@@ -357,7 +357,7 @@
"monthly_pageview_limit": 5000000,
"monthly_product_id": "78987",
"yearly_product_id": "78988",
- "site_limit": 50,
+ "site_limit": 10,
"team_member_limit": 10,
"features": [
"goals",
@@ -377,7 +377,7 @@
"monthly_pageview_limit": 10000000,
"monthly_product_id": "78989",
"yearly_product_id": "78990",
- "site_limit": 50,
+ "site_limit": 10,
"team_member_limit": 10,
"features": [
"goals",
diff --git a/test/plausible/billing/quota_test.exs b/test/plausible/billing/quota_test.exs
index ee9174b3eb..2f38e4bd5e 100644
--- a/test/plausible/billing/quota_test.exs
+++ b/test/plausible/billing/quota_test.exs
@@ -991,7 +991,7 @@ defmodule Plausible.Billing.QuotaTest do
suggested_tier =
team
|> Plausible.Teams.Billing.quota_usage(with_features: true)
- |> Map.put(:sites, 2)
+ |> Map.put(:sites, 1)
|> Quota.suggest_tier(
@highest_starter_plan,
@highest_growth_plan,
@@ -1007,7 +1007,7 @@ defmodule Plausible.Billing.QuotaTest do
suggested_tier =
team
|> Plausible.Teams.Billing.quota_usage(with_features: true)
- |> Map.put(:sites, 8)
+ |> Map.put(:sites, 2)
|> Quota.suggest_tier(
@highest_starter_plan,
@highest_growth_plan,
diff --git a/test/plausible_web/components/billing/billing_test.exs b/test/plausible_web/components/billing/billing_test.exs
new file mode 100644
index 0000000000..f0f3fd9fc7
--- /dev/null
+++ b/test/plausible_web/components/billing/billing_test.exs
@@ -0,0 +1,103 @@
+defmodule PlausibleWeb.Components.BillingTest do
+ use Plausible.DataCase
+ use Plausible.Teams.Test
+ import Phoenix.Component
+ import Phoenix.LiveViewTest, only: [rendered_to_string: 1]
+ import Plausible.Test.Support.HTML
+
+ describe "feature_gate/1" do
+ setup [:create_user]
+
+ test "renders a blur overlay if the feature is locked", %{user: user} do
+ html =
+ %{
+ current_role: :owner,
+ current_team: user |> subscribe_to_growth_plan() |> team_of(),
+ feature_mod: Plausible.Billing.Feature.Props
+ }
+ |> render_feature_gate()
+
+ assert class_of_element(html, "#feature-gate-inner-block-container") =~
+ "pointer-events-none"
+
+ assert class_of_element(html, "#feature-gate-overlay") =~ "backdrop-blur"
+ end
+
+ test "renders a blur overlay for a teamless account" do
+ html =
+ %{
+ current_role: nil,
+ current_team: nil,
+ feature_mod: Plausible.Billing.Feature.Props
+ }
+ |> render_feature_gate()
+
+ assert class_of_element(html, "#feature-gate-inner-block-container") =~
+ "pointer-events-none"
+
+ assert class_of_element(html, "#feature-gate-overlay") =~ "backdrop-blur"
+ end
+
+ test "does not render a blur overlay if feature access is granted", %{user: user} do
+ html =
+ %{
+ current_role: :owner,
+ current_team: user |> subscribe_to_business_plan() |> team_of(),
+ feature_mod: Plausible.Billing.Feature.Funnels
+ }
+ |> render_feature_gate()
+
+ refute class_of_element(html, "#feature-gate-inner-block-container") =~
+ "pointer-events-none"
+
+ refute class_of_element(html, "#feature-gate-overlay") =~ "backdrop-blur"
+ end
+
+ test "renders upgrade cta linking to the upgrade page if user role is :owner", %{user: user} do
+ html =
+ %{
+ current_role: :owner,
+ current_team: user |> subscribe_to_growth_plan() |> team_of(),
+ feature_mod: Plausible.Billing.Feature.Props
+ }
+ |> render_feature_gate()
+
+ assert text_of_element(html, "#lock-notice") =~ "upgrade your subscription"
+ end
+
+ test "renders upgrade cta linking to the upgrade page if user role is :billing", %{user: user} do
+ html =
+ %{
+ current_role: :billing,
+ current_team: user |> subscribe_to_growth_plan() |> team_of(),
+ feature_mod: Plausible.Billing.Feature.Props
+ }
+ |> render_feature_gate()
+
+ assert text_of_element(html, "#lock-notice") =~ "upgrade your subscription"
+ end
+
+ test "renders upgrade cta instructing to contact owner if user role is not :owner nor :billing",
+ %{
+ user: user
+ } do
+ html =
+ %{
+ current_role: :editor,
+ current_team: user |> subscribe_to_growth_plan() |> team_of(),
+ feature_mod: Plausible.Billing.Feature.Props
+ }
+ |> render_feature_gate()
+
+ assert text_of_element(html, "#lock-notice") =~ "reach out to the team owner"
+ end
+ end
+
+ defp render_feature_gate(assigns) do
+ rendered_to_string(~H"""
+ <PlausibleWeb.Components.Billing.feature_gate {assigns}>
+ <div>content...</div>
+ </PlausibleWeb.Components.Billing.feature_gate>
+ """)
+ end
+end
diff --git a/test/plausible_web/components/billing/notice_test.exs b/test/plausible_web/components/billing/notice_test.exs
index 53923c023a..f0836c8e94 100644
--- a/test/plausible_web/components/billing/notice_test.exs
+++ b/test/plausible_web/components/billing/notice_test.exs
@@ -4,111 +4,47 @@ defmodule PlausibleWeb.Components.Billing.NoticeTest do
import Phoenix.LiveViewTest, only: [render_component: 2]
alias PlausibleWeb.Components.Billing.Notice
- test "premium_feature/1 does not render a notice when team is on trial" do
- me = new_user(trial_expiry_date: Date.utc_today())
-
- assert render_component(&Notice.premium_feature/1,
- current_role: :owner,
- current_team: team_of(me),
- feature_mod: Plausible.Billing.Feature.Props
- ) == ""
- end
-
- test "premium_feature/1 renders an upgrade link when user is the site owner and does not have access to the feature" do
+ test "limit_exceeded/1 when user is on growth displays upgrade link" do
me = new_user() |> subscribe_to_growth_plan()
team = team_of(me)
rendered =
- render_component(&Notice.premium_feature/1,
+ render_component(&Notice.limit_exceeded/1,
current_role: :owner,
current_team: team,
- feature_mod: Plausible.Billing.Feature.Props
- )
-
- assert rendered =~ "This team does not have access to Custom Properties"
- assert rendered =~ "upgrade your subscription"
- assert rendered =~ "/billing/choose-plan"
- end
-
- test "premium_feature/1 renders an upgrade link when user is the billing role and does not have access to the feature" do
- me = new_user() |> subscribe_to_growth_plan()
- team = team_of(me)
-
- rendered =
- render_component(&Notice.premium_feature/1,
- current_role: :billing,
- current_team: team,
- feature_mod: Plausible.Billing.Feature.Props
+ limit: 10,
+ resource: "users"
)
- assert rendered =~ "This team does not have access to Custom Properties"
+ assert rendered =~ "This account is limited to 10 users. To increase this limit"
assert rendered =~ "upgrade your subscription"
assert rendered =~ "/billing/choose-plan"
end
- test "premium_feature/1 does not render an upgrade link when user is not the site owner" do
- me = new_user() |> subscribe_to_growth_plan()
-
- rendered =
- render_component(&Notice.premium_feature/1,
- current_role: :viewer,
- current_team: team_of(me),
- feature_mod: Plausible.Billing.Feature.Funnels
- )
-
- assert rendered =~ "This team does not have access to Funnels"
- assert rendered =~ "please reach out to the team owner to upgrade their subscription"
- end
-
- test "premium_feature/1 does not render a notice when the user has access to the feature" do
- me = new_user() |> subscribe_to_business_plan()
-
- rendered =
- render_component(&Notice.premium_feature/1,
- current_role: :owner,
- current_team: team_of(me),
- feature_mod: Plausible.Billing.Feature.Funnels
- )
-
- assert rendered == ""
- end
-
- test "premium_feature/1 for team-less account" do
- rendered =
- render_component(&Notice.premium_feature/1,
- current_role: nil,
- current_team: nil,
- feature_mod: Plausible.Billing.Feature.Funnels
- )
-
- assert rendered =~ "This account does not have access to Funnels"
- assert rendered =~ "upgrade your subscription"
- end
-
- test "limit_exceeded/1 when team is on growth displays upgrade link" do
+ test "limit_exceeded/1 prints resource in singular case when limit is 1" do
me = new_user() |> subscribe_to_growth_plan()
- team = team_of(me)
rendered =
render_component(&Notice.limit_exceeded/1,
current_role: :owner,
- current_team: team,
- limit: 10,
+ current_team: team_of(me),
+ limit: 1,
resource: "users"
)
- assert rendered =~ "This team is limited to 10 users. To increase this limit"
+ assert rendered =~ "This account is limited to a single user. To increase this limit"
assert rendered =~ "upgrade your subscription"
assert rendered =~ "/billing/choose-plan"
end
- test "limit_exceeded/1 when current role is non-owner" do
+ test "limit_exceeded/1 when current team role is non-owner" do
me = new_user() |> subscribe_to_growth_plan()
+ my_team = team_of(me) |> Plausible.Teams.complete_setup()
rendered =
render_component(&Notice.limit_exceeded/1,
current_role: :editor,
- current_team: team_of(me),
+ current_team: my_team,
limit: 10,
resource: "users"
)
@@ -118,7 +54,7 @@ defmodule PlausibleWeb.Components.Billing.NoticeTest do
end
@tag :ee_only
- test "limit_exceeded/1 when team is on trial displays upgrade link" do
+ test "limit_exceeded/1 when user is on trial displays upgrade link" do
me = new_user(trial_expiry_date: Date.utc_today())
rendered =
@@ -129,13 +65,13 @@ defmodule PlausibleWeb.Components.Billing.NoticeTest do
resource: "users"
)
- assert rendered =~ "This team is limited to 10 users"
+ assert rendered =~ "This account is limited to 10 users"
assert rendered =~ "upgrade your subscription"
assert rendered =~ "/billing/choose-plan"
end
@tag :ee_only
- test "limit_exceeded/1 when team is on an enterprise plan displays support email" do
+ test "limit_exceeded/1 when user is on an enterprise plan displays support email" do
me = new_user() |> subscribe_to_enterprise_plan()
rendered =
@@ -146,14 +82,14 @@ defmodule PlausibleWeb.Components.Billing.NoticeTest do
resource: "users"
)
- assert rendered =~ "This team is limited to 10 users."
+ assert rendered =~ "This account is limited to 10 users."
assert rendered =~ "[email protected]"
assert rendered =~ "upgrade your subscription"
end
@tag :ee_only
- test "limit_exceeded/1 when team is on a business plan displays support email" do
+ test "limit_exceeded/1 when user is on a business plan displays support email" do
me = new_user() |> subscribe_to_business_plan()
team = team_of(me)
@@ -165,7 +101,7 @@ defmodule PlausibleWeb.Components.Billing.NoticeTest do
resource: "users"
)
- assert rendered =~ "This team is limited to 10 users."
+ assert rendered =~ "This account is limited to 10 users."
assert rendered =~ "[email protected]"
assert rendered =~ "upgrade your subscription"
diff --git a/test/plausible_web/controllers/settings_controller_test.exs b/test/plausible_web/controllers/settings_controller_test.exs
index 172bb5ba5e..249e423f1f 100644
--- a/test/plausible_web/controllers/settings_controller_test.exs
+++ b/test/plausible_web/controllers/settings_controller_test.exs
@@ -1411,6 +1411,38 @@ defmodule PlausibleWeb.SettingsControllerTest do
end
end
+ describe "account dropdown menu (_header.html)" do
+ setup [:create_user, :log_in]
+
+ test "renders the 'Create a Team' option", %{conn: conn, user: user} do
+ subscribe_to_growth_plan(user)
+ conn = get(conn, Routes.settings_path(conn, :preferences))
+ html = html_response(conn, 200)
+ assert text_of_element(html, ~s/[data-test="create-a-team-cta"]/) == "Create a Team"
+ end
+
+ test "does not render the 'Create a Team' option if Teams feature is unavailable", %{
+ conn: conn,
+ user: user
+ } do
+ subscribe_to_starter_plan(user)
+ conn = get(conn, Routes.settings_path(conn, :preferences))
+ html = html_response(conn, 200)
+ refute element_exists?(html, ~s/[data-test="create-a-team-cta"]/)
+ end
+
+ test "does not render the 'Create a Team' option if a team is already set up", %{
+ conn: conn,
+ user: user
+ } do
+ {:ok, team} = Plausible.Teams.get_or_create(user)
+ Plausible.Teams.complete_setup(team)
+ conn = get(conn, Routes.settings_path(conn, :preferences))
+ html = html_response(conn, 200)
+ refute element_exists?(html, ~s/[data-test="create-a-team-cta"]/)
+ end
+ end
+
defp configure_enterprise_plan(user, attrs \\ []) do
subscribe_to_enterprise_plan(
user,
diff --git a/test/plausible_web/controllers/site/membership_controller_test.exs b/test/plausible_web/controllers/site/membership_controller_test.exs
index dce20d57b1..4e11107f4a 100644
--- a/test/plausible_web/controllers/site/membership_controller_test.exs
+++ b/test/plausible_web/controllers/site/membership_controller_test.exs
@@ -39,7 +39,8 @@ defmodule PlausibleWeb.Site.MembershipControllerTest do
|> get("/sites/#{site.domain}/memberships/invite")
|> html_response(200)
- assert html =~ "This team is limited to 3 members"
+ assert text_of_element(html, ~s/[data-test="limit-exceeded-notice"]/) =~
+ "This account is limited to 3 members"
end
end
diff --git a/test/plausible_web/controllers/site_controller_test.exs b/test/plausible_web/controllers/site_controller_test.exs
index 1a387d9312..0e06d7da65 100644
--- a/test/plausible_web/controllers/site_controller_test.exs
+++ b/test/plausible_web/controllers/site_controller_test.exs
@@ -329,7 +329,10 @@ defmodule PlausibleWeb.SiteControllerTest do
})
assert html = html_response(conn, 200)
- assert html =~ "This team is limited to 10 sites"
+
+ assert text_of_element(html, ~s/[data-test="limit-exceeded-notice"]/) =~
+ "This account is limited to 10 sites"
+
refute Repo.get_by(Plausible.Site, domain: "over-limit.example.com")
end
@@ -695,6 +698,18 @@ defmodule PlausibleWeb.SiteControllerTest do
refute resp =~ "A Better Way of Inviting People to a Team"
refute resp =~ "Team members automatically have access to this site."
end
+
+ test "does not render team management notice if Teams feature unavailable", %{
+ conn: conn,
+ user: user
+ } do
+ subscribe_to_starter_plan(user)
+
+ site = new_site(owner: user)
+ resp = conn |> get("/#{site.domain}/settings/people") |> html_response(200)
+
+ refute resp =~ "A Better Way of Inviting People"
+ end
end
describe "GET /:domain/settings/goals" do
diff --git a/test/plausible_web/live/choose_plan_test.exs b/test/plausible_web/live/choose_plan_test.exs
index 25b7687c5d..3fd8a3c23e 100644
--- a/test/plausible_web/live/choose_plan_test.exs
+++ b/test/plausible_web/live/choose_plan_test.exs
@@ -94,18 +94,18 @@ defmodule PlausibleWeb.Live.ChoosePlanTest do
assert starter_box =~ "Email/Slack reports"
assert starter_box =~ "Google Analytics import"
assert starter_box =~ "Goals and custom events"
- assert starter_box =~ "Up to 3 sites"
+ assert starter_box =~ "One site"
assert starter_box =~ "3 years of data retention"
assert growth_box =~ "Up to 3 team members"
- assert growth_box =~ "Up to 10 sites"
- assert growth_box =~ "Team Accounts"
+ assert growth_box =~ "Up to 3 sites"
+ assert growth_box =~ "Team Management"
assert growth_box =~ "Shared Links"
assert growth_box =~ "Shared Segments"
assert business_box =~ "Everything in Growth"
assert business_box =~ "Up to 10 team members"
- assert business_box =~ "Up to 50 sites"
+ assert business_box =~ "Up to 10 sites"
assert business_box =~ "Stats API (600 requests per hour)"
assert business_box =~ "Looker Studio Connector"
assert business_box =~ "Custom Properties"
@@ -368,8 +368,8 @@ defmodule PlausibleWeb.Live.ChoosePlanTest do
conn: conn,
user: user
} do
- for _ <- 1..9, do: new_site(owner: user)
- assert user |> team_of() |> Plausible.Teams.Billing.site_usage() == 10
+ for _ <- 1..2, do: new_site(owner: user)
+ assert user |> team_of() |> Plausible.Teams.Billing.site_usage() == 3
another_user = new_user()
pending_ownership_site = new_site(owner: another_user)
@@ -492,18 +492,18 @@ defmodule PlausibleWeb.Live.ChoosePlanTest do
assert starter_box =~ "Email/Slack reports"
assert starter_box =~ "Google Analytics import"
assert starter_box =~ "Goals and custom events"
- assert starter_box =~ "Up to 3 sites"
+ assert starter_box =~ "One site"
assert starter_box =~ "3 years of data retention"
assert growth_box =~ "Up to 3 team members"
- assert growth_box =~ "Up to 10 sites"
- assert growth_box =~ "Team Accounts"
+ assert growth_box =~ "Up to 3 sites"
+ assert growth_box =~ "Team Management"
assert growth_box =~ "Shared Links"
assert growth_box =~ "Shared Segments"
assert business_box =~ "Everything in Growth"
assert business_box =~ "Up to 10 team members"
- assert business_box =~ "Up to 50 sites"
+ assert business_box =~ "Up to 10 sites"
assert business_box =~ "Stats API (600 requests per hour)"
assert business_box =~ "Looker Studio Connector"
assert business_box =~ "Custom Properties"
@@ -569,8 +569,14 @@ defmodule PlausibleWeb.Live.ChoosePlanTest do
check_notice_titles(doc, [Billing.pending_site_ownerships_notice_title()])
assert doc =~ "Your account has been invited to become the owner of a site"
- assert text_of_element(doc, @starter_plan_tooltip) ==
- "Your usage exceeds the following limit(s): Team member limit"
+ assert text_of_element(doc, @starter_plan_tooltip) =~
+ "Your usage exceeds the following limit(s):"
+
+ assert text_of_element(doc, @starter_plan_tooltip) =~
+ "Team member limit"
+
+ assert text_of_element(doc, @starter_plan_tooltip) =~
+ "Site limit"
assert text_of_element(doc, @growth_plan_tooltip) ==
"Your usage exceeds the following limit(s): Team member limit"
@@ -784,9 +790,8 @@ defmodule PlausibleWeb.Live.ChoosePlanTest do
test "checkout is disabled when team member usage exceeds rendered plan limit", %{
conn: conn,
- user: user
+ site: site
} do
- site = new_site(owner: user)
for _ <- 1..4, do: add_guest(site, role: :viewer)
{:ok, _lv, doc} = get_liveview(conn)
@@ -904,12 +909,12 @@ defmodule PlausibleWeb.Live.ChoosePlanTest do
assert starter_box =~ "Email/Slack reports"
assert starter_box =~ "Google Analytics import"
assert starter_box =~ "Goals and custom events"
- assert starter_box =~ "Up to 3 sites"
+ assert starter_box =~ "One site"
assert starter_box =~ "3 years of data retention"
assert growth_box =~ "Up to 3 team members"
- assert growth_box =~ "Up to 10 sites"
- assert growth_box =~ "Team Accounts"
+ assert growth_box =~ "Up to 3 sites"
+ assert growth_box =~ "Team Management"
assert growth_box =~ "Shared Links"
assert growth_box =~ "Shared Segments"
@@ -1173,7 +1178,7 @@ defmodule PlausibleWeb.Live.ChoosePlanTest do
assert starter_box =~ "Email/Slack reports"
assert starter_box =~ "Google Analytics import"
assert starter_box =~ "Goals and custom events"
- assert starter_box =~ "Up to 3 sites"
+ assert starter_box =~ "One site"
assert starter_box =~ "3 years of data retention"
assert business_box =~ "Everything in Growth"
diff --git a/test/plausible_web/live/funnel_settings_test.exs b/test/plausible_web/live/funnel_settings_test.exs
index 6f0c0f0f5a..8627bf37dd 100644
--- a/test/plausible_web/live/funnel_settings_test.exs
+++ b/test/plausible_web/live/funnel_settings_test.exs
@@ -77,7 +77,7 @@ defmodule PlausibleWeb.Live.FunnelSettingsTest do
conn = get(conn, "/#{site.domain}/settings/funnels")
doc = conn |> html_response(200)
- assert Floki.text(doc) =~ "You need to define at least two goals to create a funnel."
+ assert Floki.text(doc) =~ "Set up a few goals first"
add_goals_path = Routes.site_path(conn, :settings_goals, site.domain)
assert element_exists?(doc, ~s/a[href="#{add_goals_path}"]/)
diff --git a/test/plausible_web/live/goal_settings/form_test.exs b/test/plausible_web/live/goal_settings/form_test.exs
index e5b5b040f1..c6b431993d 100644
--- a/test/plausible_web/live/goal_settings/form_test.exs
+++ b/test/plausible_web/live/goal_settings/form_test.exs
@@ -184,11 +184,7 @@ defmodule PlausibleWeb.Live.GoalSettings.FormTest do
refute element_exists?(html, "#pageviews-form")
assert element_exists?(html, "#custom-events-form")
-
- assert element_exists?(
- html,
- ~s/button[role=switch][aria-labelledby=enable-revenue-tracking][disabled="disabled"]/
- )
+ refute String.downcase(text_of_element(html, "#custom-events-form")) =~ "currency"
# revenue goals
lv |> element(~s/button#edit-goal-#{revenue_goal.id}/) |> render_click()
@@ -196,11 +192,7 @@ defmodule PlausibleWeb.Live.GoalSettings.FormTest do
refute element_exists?(html, "#pageviews-form")
assert element_exists?(html, "#custom-events-form")
-
- assert element_exists?(
- html,
- ~s/button[role=switch][aria-labelledby=enable-revenue-tracking][disabled="disabled"]/
- )
+ assert element_exists?(html, ~s/[data-test=goal-currency-label]/)
end
test "updates a custom event", %{conn: conn, site: site} do
diff --git a/test/plausible_web/live/goal_settings_test.exs b/test/plausible_web/live/goal_settings_test.exs
index 06b986ead6..20fc86f68c 100644
--- a/test/plausible_web/live/goal_settings_test.exs
+++ b/test/plausible_web/live/goal_settings_test.exs
@@ -42,7 +42,7 @@ defmodule PlausibleWeb.Live.GoalSettingsTest do
assert g3.currency
assert resp =~ to_string(g3)
- assert resp =~ "Unlock Revenue Goals by upgrading to a business plan"
+ assert resp =~ "Upgrade Required"
refute element_exists?(
resp,
diff --git a/test/plausible_web/live/props_settings_test.exs b/test/plausible_web/live/props_settings_test.exs
index d301bb85a5..d159cb9900 100644
--- a/test/plausible_web/live/props_settings_test.exs
+++ b/test/plausible_web/live/props_settings_test.exs
@@ -8,16 +8,37 @@ defmodule PlausibleWeb.Live.PropsSettingsTest do
setup [:create_user, :log_in, :create_site]
@tag :ee_only
- test "premium feature notice renders", %{conn: conn, site: site, user: user} do
- user
- |> team_of()
- |> Plausible.Teams.Team.end_trial()
- |> Plausible.Repo.update!()
+ test "renders with locked content when subscription is insufficient", %{
+ conn: conn,
+ site: site,
+ user: user
+ } do
+ subscribe_to_growth_plan(user)
- conn = get(conn, "/#{site.domain}/settings/properties")
- resp = conn |> html_response(200) |> text()
+ lock_notice =
+ conn
+ |> get("/#{site.domain}/settings/properties")
+ |> html_response(200)
+ |> text_of_element("#lock-notice")
+
+ assert lock_notice =~ "please upgrade your subscription"
+ end
+
+ @tag :ee_only
+ test "does not lock content when subscription is sufficient", %{
+ conn: conn,
+ site: site,
+ user: user
+ } do
+ subscribe_to_business_plan(user)
+
+ lock_notice =
+ conn
+ |> get("/#{site.domain}/settings/properties")
+ |> html_response(200)
+ |> text_of_element("#lock-notice")
- assert resp =~ "please upgrade your subscription"
+ refute lock_notice =~ "please upgrade your subscription"
end
test "lists props for the site and renders links", %{conn: conn, site: site} do
diff --git a/test/plausible_web/live/team_setup_test.exs b/test/plausible_web/live/team_setup_test.exs
index 5a6f5e806e..2725a21ab9 100644
--- a/test/plausible_web/live/team_setup_test.exs
+++ b/test/plausible_web/live/team_setup_test.exs
@@ -215,7 +215,9 @@ defmodule PlausibleWeb.Live.TeamSetupTest do
assert attr_defined?(html, ~s|#team-layout-form input[name="input-email"]|, "readonly")
assert attr_defined?(html, ~s|#invite-member|, "disabled")
- assert text(html) =~ "This team is limited to 3 members"
+
+ assert text_of_element(html, ~s/[data-test="limit-exceeded-notice"]/) =~
+ "This account is limited to 3 members"
end
test "all options are disabled for the sole owner", %{conn: conn} do
diff --git a/test/support/factory.ex b/test/support/factory.ex
index c4478e1b54..ff17bdb3d5 100644
--- a/test/support/factory.ex
+++ b/test/support/factory.ex
@@ -191,6 +191,10 @@ defmodule Plausible.Factory do
}
end
+ def starter_subscription_factory do
+ build(:subscription, paddle_plan_id: "910413")
+ end
+
def growth_subscription_factory do
build(:subscription, paddle_plan_id: "857097")
end
diff --git a/test/support/teams/test.ex b/test/support/teams/test.ex
index 445a721bbd..d7aa04e5fb 100644
--- a/test/support/teams/test.ex
+++ b/test/support/teams/test.ex
@@ -224,6 +224,14 @@ defmodule Plausible.Teams.Test do
user |> Repo.preload(:team_memberships)
end
+ def subscribe_to_starter_plan(user, attrs \\ []) do
+ {:ok, team} = Teams.get_or_create(user)
+ attrs = Keyword.merge([team: team], attrs)
+
+ insert(:starter_subscription, attrs)
+ user
+ end
+
def subscribe_to_growth_plan(user, attrs \\ []) do
{:ok, team} = Teams.get_or_create(user)
attrs = Keyword.merge([team: team], attrs)