Adapt cookie banner UI and texts per regulation

The server now resolves regulation-specific translations
(opt-out notice for CCPA, simple notice when no regulation
applies) and remaps text keys before returning the config.
The client hides buttons whose text is empty, so the banner
layout adapts without client-side consent-mode logic.

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-05-07 09:50:54 +04:00
parent 4598506076
commit b4bb8715ee
6 changed files with 107 additions and 17 deletions

View File

@@ -171,6 +171,7 @@ type (
CookiePolicyURL string `json:"cookie_policy_url"`
ConsentExpiryDays int `json:"consent_expiry_days"`
ConsentMode string `json:"consent_mode"`
Regulation Regulation `json:"regulation"`
ShowBranding bool `json:"show_branding"`
Categories []coredata.CookieBannerVersionSnapshotCategory `json:"categories"`
Texts map[string]string `json:"texts"`
@@ -1527,6 +1528,7 @@ func (s *Service) GetActiveBannerConfig(
ctx context.Context,
bannerID gid.GID,
lang string,
regulation Regulation,
) (*BannerConfig, error) {
var config *BannerConfig
@@ -1576,6 +1578,12 @@ func (s *Service) GetActiveBannerConfig(
return nil, err
}
config.Regulation = regulation
if cm := ConsentModeForRegulation(regulation); cm != "" {
config.ConsentMode = cm
}
remapTextsForConsentMode(config.Texts, config.ConsentMode, regulation)
return config, nil
}
@@ -1644,6 +1652,37 @@ func buildBannerConfig(
}
}
// remapTextsForConsentMode overrides the generic banner text keys with
// mode-specific variants so the client renders the appropriate copy
// without needing consent-mode awareness itself.
func remapTextsForConsentMode(texts map[string]string, consentMode string, regulation Regulation) {
if texts == nil {
return
}
switch {
case consentMode == ConsentModeOptOut:
remapTextKey(texts, "banner_title_opt_out", "banner_title")
remapTextKey(texts, "banner_description_opt_out", "banner_description")
remapTextKey(texts, "button_acknowledge", "button_accept_all")
remapTextKey(texts, "button_opt_out", "button_customize")
texts["button_reject_all"] = ""
case regulation == RegulationNone:
remapTextKey(texts, "banner_title_notice", "banner_title")
remapTextKey(texts, "banner_description_notice", "banner_description")
remapTextKey(texts, "button_dismiss", "button_accept_all")
texts["button_reject_all"] = ""
texts["button_customize"] = ""
}
}
func remapTextKey(texts map[string]string, src, dst string) {
if v, ok := texts[src]; ok && v != "" {
texts[dst] = v
}
}
func (s *Service) SetShowBranding(
ctx context.Context,
bannerID gid.GID,