Skip to content

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

Automatically select and deselect dependent API features in CS (#5396)

Adrian Gruntkowski34c201dc61bb
diff --git a/extra/lib/plausible_web/live/customer_support/live/team.ex b/extra/lib/plausible_web/live/customer_support/live/team.ex
index a5cdf50ad0..9351db51b3 100644
--- a/extra/lib/plausible_web/live/customer_support/live/team.ex
+++ b/extra/lib/plausible_web/live/customer_support/live/team.ex
@@ -92,6 +92,18 @@ defmodule PlausibleWeb.CustomerSupport.Live.Team do
const value = numeric > 0 ? new Intl.NumberFormat("en-GB").format(numeric) : ''
e.target.value = value
}
+
+ const featureChangeCallback = function(e) {
+ const value = e.target.value
+ const checked = e.target.checked
+ const form = e.target.closest('form')
+
+ if (value === 'sites_api' && checked) {
+ form.querySelector('input[value=stats_api]').checked = true
+ } else if (value === 'stats_api' && !checked) {
+ form.querySelector('input[value=sites_api]').checked = false
+ }
+ }
</script>
<div class="overflow-hidden rounded-lg">
<div class="p-6">
@@ -295,6 +307,7 @@ defmodule PlausibleWeb.CustomerSupport.Live.Team do
|> Enum.sort_by(fn item -> if item.name() == :stats_api, do: 0, else: 1 end)
}
:if={not mod.free?()}
+ x-on:change="featureChangeCallback(event)"
type="checkbox"
name={"#{f.name}[features[]][]"}
value={mod.name()}
diff --git a/lib/plausible_web/live/components/form.ex b/lib/plausible_web/live/components/form.ex
index 26d177e207..98a6787d19 100644
--- a/lib/plausible_web/live/components/form.ex
+++ b/lib/plausible_web/live/components/form.ex
@@ -108,6 +108,7 @@ defmodule PlausibleWeb.Live.Components.Form do
id={@id}
name={@name}
class="block h-5 w-5 rounded dark:bg-gray-700 border-gray-300 text-indigo-600 focus:ring-indigo-600"
+ {@rest}
/>
{@label}
</.label>