Derive consent mode from geolocation, not banner config

The consent mode is now determined dynamically by the visitor's
country and its applicable regulation. The configured consent_mode
column is dropped from cookie_banners and added to
cookie_consent_records to persist the geo-derived mode at
consent-recording time. When no regulation matches, the default
is OPT_OUT.

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-05-13 12:17:34 +04:00
parent e9d786c5d6
commit e739473bcd
30 changed files with 68 additions and 246 deletions

View File

@@ -21,10 +21,7 @@ import {
Card,
Field,
Input,
Label,
Option,
PageHeader,
Select,
useToast,
} from "@probo/ui";
import { type FormEvent, useState } from "react";
@@ -63,7 +60,6 @@ export default function NewCookieBannerPage() {
const [cookiePolicyUrl, setCookiePolicyUrl] = useState("");
const [privacyPolicyUrl, setPrivacyPolicyUrl] = useState("");
const [consentExpiryDays, setConsentExpiryDays] = useState("365");
const [consentMode, setConsentMode] = useState("OPT_IN");
const handleSubmit = (e: FormEvent<HTMLFormElement>) => {
e.preventDefault();
@@ -77,7 +73,6 @@ export default function NewCookieBannerPage() {
cookiePolicyUrl,
privacyPolicyUrl: privacyPolicyUrl || undefined,
consentExpiryDays: parseInt(consentExpiryDays, 10),
consentMode: consentMode as "OPT_IN" | "OPT_OUT",
},
},
onCompleted(data) {
@@ -155,26 +150,15 @@ export default function NewCookieBannerPage() {
/>
</Field>
<div className="grid grid-cols-2 gap-4">
<div className="space-y-2">
<Label>{__("Consent Expiry (days)")}</Label>
<Input
type="number"
value={consentExpiryDays}
onChange={e => setConsentExpiryDays(e.target.value)}
min="1"
required
/>
</div>
<div className="space-y-2">
<Label>{__("Consent Mode")}</Label>
<Select value={consentMode} onValueChange={setConsentMode}>
<Option value="OPT_IN">{__("Opt-in")}</Option>
<Option value="OPT_OUT">{__("Opt-out")}</Option>
</Select>
</div>
</div>
<Field label={__("Consent Expiry (days)")}>
<Input
type="number"
value={consentExpiryDays}
onChange={e => setConsentExpiryDays(e.target.value)}
min="1"
required
/>
</Field>
<Button type="submit" disabled={isCreating}>
{isCreating ? __("Creating...") : __("Create Banner")}

View File

@@ -30,7 +30,6 @@ const bannerSettingsFormFragment = graphql`
cookiePolicyUrl
privacyPolicyUrl
consentExpiryDays
consentMode
defaultLanguage
}
`;
@@ -44,7 +43,6 @@ const updateBannerMutation = graphql`
cookiePolicyUrl
privacyPolicyUrl
consentExpiryDays
consentMode
defaultLanguage
latestVersion {
id
@@ -61,7 +59,6 @@ interface BannerSettingsFormValues {
cookiePolicyUrl: string;
privacyPolicyUrl: string;
consentExpiryDays: string;
consentMode: "OPT_IN" | "OPT_OUT";
defaultLanguage: string;
}
@@ -83,7 +80,6 @@ export function BannerSettingsForm({ cookieBannerKey }: BannerSettingsFormProps)
cookiePolicyUrl: banner.cookiePolicyUrl,
privacyPolicyUrl: banner.privacyPolicyUrl ?? "",
consentExpiryDays: String(banner.consentExpiryDays),
consentMode: banner.consentMode,
defaultLanguage: banner.defaultLanguage,
},
});
@@ -97,7 +93,6 @@ export function BannerSettingsForm({ cookieBannerKey }: BannerSettingsFormProps)
cookiePolicyUrl: data.cookiePolicyUrl,
privacyPolicyUrl: data.privacyPolicyUrl || undefined,
consentExpiryDays: parseInt(data.consentExpiryDays, 10),
consentMode: data.consentMode,
defaultLanguage: data.defaultLanguage,
},
},
@@ -131,7 +126,7 @@ export function BannerSettingsForm({ cookieBannerKey }: BannerSettingsFormProps)
<Input {...register("privacyPolicyUrl")} />
</Field>
<div className="grid grid-cols-3 gap-4">
<div className="grid grid-cols-2 gap-4">
<div className="space-y-2">
<Label>{__("Consent Expiry (days)")}</Label>
<Input
@@ -141,19 +136,6 @@ export function BannerSettingsForm({ cookieBannerKey }: BannerSettingsFormProps)
required
/>
</div>
<div className="space-y-2">
<Label>{__("Consent Mode")}</Label>
<Controller
name="consentMode"
control={control}
render={({ field }) => (
<Select value={field.value} onValueChange={field.onChange}>
<Option value="OPT_IN">{__("Opt-in")}</Option>
<Option value="OPT_OUT">{__("Opt-out")}</Option>
</Select>
)}
/>
</div>
<div className="space-y-2">
<Label>{__("Default Language")}</Label>
<Controller