Constrain PostHog consent to one normal category per banner

Add a partial unique index ensuring only one category per banner can
have posthog_consent enabled. Default it to the analytics category on
banner creation, clear the previous mapping before setting a new one,
and restrict the toggle to NORMAL categories in both the service layer
and the console UI.

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-04-24 16:35:39 +04:00
parent 7f1dffad80
commit 9fbb716b00
9 changed files with 190 additions and 27 deletions

View File

@@ -490,6 +490,7 @@ export function CategorySection({ categoryKey, onDelete }: CategorySectionProps)
name={category.name}
slug={category.slug}
description={category.description}
kind={category.kind}
gcmConsentTypes={[...category.gcmConsentTypes]}
posthogConsent={category.posthogConsent}
isUpdating={isUpdating}

View File

@@ -30,6 +30,7 @@ interface EditCategoryFormProps {
name: string;
slug: string;
description: string;
kind: string;
gcmConsentTypes: string[];
posthogConsent: boolean;
isUpdating: boolean;
@@ -41,6 +42,7 @@ export function EditCategoryForm({
name,
slug,
description,
kind,
gcmConsentTypes,
posthogConsent,
isUpdating,
@@ -105,23 +107,25 @@ export function EditCategoryForm({
))}
</div>
</div>
<div>
<label className="text-sm font-medium">
{__("PostHog")}
</label>
<p className="text-xs text-muted-foreground mb-2">
{__("Control PostHog tracking consent based on this category.")}
</p>
<label className="flex items-center gap-1.5 text-xs cursor-pointer">
<input
type="checkbox"
checked={editPosthogConsent}
onChange={() => setEditPosthogConsent(prev => !prev)}
className="rounded"
/>
<span>{__("Opt in/out of PostHog tracking")}</span>
</label>
</div>
{kind === "NORMAL" && (
<div>
<label className="text-sm font-medium">
{__("PostHog")}
</label>
<p className="text-xs text-muted-foreground mb-2">
{__("Control PostHog tracking consent based on this category.")}
</p>
<label className="flex items-center gap-1.5 text-xs cursor-pointer">
<input
type="checkbox"
checked={editPosthogConsent}
onChange={() => setEditPosthogConsent(prev => !prev)}
className="rounded"
/>
<span>{__("Opt in/out of PostHog tracking")}</span>
</label>
</div>
)}
<div className="flex items-center gap-2">
<Button
onClick={() => {