Skip to content

Commit 12809a7

Browse files
committed
feat: cookiebanner fields optional
1 parent e5376f5 commit 12809a7

9 files changed

Lines changed: 345 additions & 327 deletions

File tree

src/app/(payload)/admin/importMap.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/providers/ConsentManager.tsx

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,31 @@ function getOptionalValue(value?: string | null) {
1717
function mapCookieBannerTranslations(content: CookieBannerContent | null) {
1818
return {
1919
common: {
20-
acceptAll: getOptionalValue(content?.common.acceptAll),
21-
rejectAll: getOptionalValue(content?.common.rejectAll),
22-
customize: getOptionalValue(content?.common.customize),
23-
save: getOptionalValue(content?.common.save),
20+
acceptAll: getOptionalValue(content?.common?.acceptAll),
21+
rejectAll: getOptionalValue(content?.common?.rejectAll),
22+
customize: getOptionalValue(content?.common?.customize),
23+
save: getOptionalValue(content?.common?.save),
2424
},
2525
cookieBanner: {
26-
title: getOptionalValue(content?.cookieBanner.title),
27-
description: getOptionalValue(content?.cookieBanner.description),
26+
title: getOptionalValue(content?.cookieBanner?.title),
27+
description: getOptionalValue(content?.cookieBanner?.description),
2828
},
2929
consentManagerDialog: {
30-
title: getOptionalValue(content?.consentManagerDialog.title),
31-
description: getOptionalValue(content?.consentManagerDialog.description),
30+
title: getOptionalValue(content?.consentManagerDialog?.title),
31+
description: getOptionalValue(content?.consentManagerDialog?.description),
3232
},
3333
consentTypes: {
3434
necessary: {
35-
title: getOptionalValue(content?.consentTypes.necessary.title),
36-
description: getOptionalValue(content?.consentTypes.necessary.description),
35+
title: getOptionalValue(content?.consentTypes?.necessary?.title),
36+
description: getOptionalValue(content?.consentTypes?.necessary?.description),
3737
},
3838
measurement: {
39-
title: getOptionalValue(content?.consentTypes.measurement.title),
40-
description: getOptionalValue(content?.consentTypes.measurement.description),
39+
title: getOptionalValue(content?.consentTypes?.measurement?.title),
40+
description: getOptionalValue(content?.consentTypes?.measurement?.description),
4141
},
4242
marketing: {
43-
title: getOptionalValue(content?.consentTypes.marketing.title),
44-
description: getOptionalValue(content?.consentTypes.marketing.description),
43+
title: getOptionalValue(content?.consentTypes?.marketing?.title),
44+
description: getOptionalValue(content?.consentTypes?.marketing?.description),
4545
},
4646
},
4747
}
@@ -56,12 +56,12 @@ export default async function ConsentManager({ children, locale }: ConsentManage
5656
const gaMeasurementId = getOptionalValue(process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID)
5757
const legalLinks = {
5858
privacyPolicy: {
59-
href: activeContent?.legalLinks.privacyPolicy.href ?? "",
60-
label: getOptionalValue(activeContent?.legalLinks.privacyPolicy.label),
59+
href: activeContent?.legalLinks?.privacyPolicy?.href ?? "",
60+
label: getOptionalValue(activeContent?.legalLinks?.privacyPolicy?.label),
6161
},
6262
termsOfService: {
63-
href: activeContent?.legalLinks.termsOfService.href ?? "",
64-
label: getOptionalValue(activeContent?.legalLinks.termsOfService.label),
63+
href: activeContent?.legalLinks?.termsOfService?.href ?? "",
64+
label: getOptionalValue(activeContent?.legalLinks?.termsOfService?.label),
6565
}
6666
}
6767
const i18n = {

src/globals/cookieBanner.ts

Lines changed: 63 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,81 @@
11
import type { GlobalConfig } from "payload"
22

33
const localizedText = (name: string, label: string) => ({
4-
name,
5-
label,
6-
type: "text" as const,
7-
required: true,
8-
localized: true,
4+
name,
5+
label,
6+
type: "text" as const,
7+
required: false,
8+
localized: true,
99
})
1010

1111
export const CookieBanner: GlobalConfig = {
12-
slug: "cookie-banner",
13-
access: {
14-
read: () => true,
15-
update: ({ req }) => Boolean(req.user),
16-
},
17-
fields: [
18-
{
19-
name: "common",
20-
label: "Common",
21-
type: "group",
22-
fields: [
23-
localizedText("acceptAll", "Accept all"),
24-
localizedText("rejectAll", "Reject all"),
25-
localizedText("customize", "Customize"),
26-
localizedText("save", "Save"),
27-
],
12+
slug: "cookie-banner",
13+
access: {
14+
read: () => true,
15+
update: ({ req }) => Boolean(req.user),
2816
},
29-
{
30-
name: "cookieBanner",
31-
label: "Cookie Banner",
32-
type: "group",
33-
fields: [
34-
localizedText("title", "Title"),
35-
localizedText("description", "Description"),
36-
],
37-
},
38-
{
39-
name: "consentManagerDialog",
40-
label: "Consent Manager Dialog",
41-
type: "group",
42-
fields: [
43-
localizedText("title", "Title"),
44-
localizedText("description", "Description"),
45-
],
46-
},
47-
{
48-
name: "consentTypes",
49-
label: "Consent Types",
50-
type: "group",
51-
fields: [
17+
fields: [
5218
{
53-
name: "necessary",
54-
label: "Necessary",
55-
type: "group",
56-
fields: [
57-
localizedText("title", "Title"),
58-
localizedText("description", "Description"),
59-
],
19+
name: "common",
20+
label: "Common",
21+
type: "group",
22+
fields: [localizedText("acceptAll", "Accept all"), localizedText("rejectAll", "Reject all"), localizedText("customize", "Customize"), localizedText("save", "Save")],
6023
},
6124
{
62-
name: "measurement",
63-
label: "Measurement",
64-
type: "group",
65-
fields: [
66-
localizedText("title", "Title"),
67-
localizedText("description", "Description"),
68-
],
25+
name: "cookieBanner",
26+
label: "Cookie Banner",
27+
type: "group",
28+
fields: [localizedText("title", "Title"), localizedText("description", "Description")],
6929
},
7030
{
71-
name: "marketing",
72-
label: "Marketing",
73-
type: "group",
74-
fields: [
75-
localizedText("title", "Title"),
76-
localizedText("description", "Description"),
77-
],
31+
name: "consentManagerDialog",
32+
label: "Consent Manager Dialog",
33+
type: "group",
34+
fields: [localizedText("title", "Title"), localizedText("description", "Description")],
7835
},
79-
],
80-
},
81-
{
82-
name: "legalLinks",
83-
label: "Legal Links",
84-
type: "group",
85-
fields: [
8636
{
87-
name: "privacyPolicy",
88-
label: "Privacy Policy",
89-
type: "group",
90-
fields: [
91-
localizedText("label", "Label"),
92-
localizedText("href", "Href"),
93-
],
37+
name: "consentTypes",
38+
label: "Consent Types",
39+
type: "group",
40+
fields: [
41+
{
42+
name: "necessary",
43+
label: "Necessary",
44+
type: "group",
45+
fields: [localizedText("title", "Title"), localizedText("description", "Description")],
46+
},
47+
{
48+
name: "measurement",
49+
label: "Measurement",
50+
type: "group",
51+
fields: [localizedText("title", "Title"), localizedText("description", "Description")],
52+
},
53+
{
54+
name: "marketing",
55+
label: "Marketing",
56+
type: "group",
57+
fields: [localizedText("title", "Title"), localizedText("description", "Description")],
58+
},
59+
],
9460
},
9561
{
96-
name: "termsOfService",
97-
label: "Terms of Service",
98-
type: "group",
99-
fields: [
100-
localizedText("label", "Label"),
101-
localizedText("href", "Href"),
102-
],
62+
name: "legalLinks",
63+
label: "Legal Links",
64+
type: "group",
65+
fields: [
66+
{
67+
name: "privacyPolicy",
68+
label: "Privacy Policy",
69+
type: "group",
70+
fields: [localizedText("label", "Label"), localizedText("href", "Href")],
71+
},
72+
{
73+
name: "termsOfService",
74+
label: "Terms of Service",
75+
type: "group",
76+
fields: [localizedText("label", "Label"), localizedText("href", "Href")],
77+
},
78+
],
10379
},
104-
],
105-
},
106-
],
80+
],
10781
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"version": "7",
3+
"dialect": "postgresql",
4+
"tables": {
5+
"public.cookie_banner_locales": {
6+
"name": "cookie_banner_locales",
7+
"schema": "public",
8+
"columns": {
9+
"common_accept_all": { "name": "common_accept_all", "type": "varchar", "primaryKey": false, "notNull": false },
10+
"common_reject_all": { "name": "common_reject_all", "type": "varchar", "primaryKey": false, "notNull": false },
11+
"common_customize": { "name": "common_customize", "type": "varchar", "primaryKey": false, "notNull": false },
12+
"common_save": { "name": "common_save", "type": "varchar", "primaryKey": false, "notNull": false },
13+
"cookie_banner_title": { "name": "cookie_banner_title", "type": "varchar", "primaryKey": false, "notNull": false },
14+
"cookie_banner_description": { "name": "cookie_banner_description", "type": "varchar", "primaryKey": false, "notNull": false },
15+
"consent_manager_dialog_title": { "name": "consent_manager_dialog_title", "type": "varchar", "primaryKey": false, "notNull": false },
16+
"consent_manager_dialog_description": { "name": "consent_manager_dialog_description", "type": "varchar", "primaryKey": false, "notNull": false },
17+
"consent_types_necessary_title": { "name": "consent_types_necessary_title", "type": "varchar", "primaryKey": false, "notNull": false },
18+
"consent_types_necessary_description": { "name": "consent_types_necessary_description", "type": "varchar", "primaryKey": false, "notNull": false },
19+
"consent_types_measurement_title": { "name": "consent_types_measurement_title", "type": "varchar", "primaryKey": false, "notNull": false },
20+
"consent_types_measurement_description": { "name": "consent_types_measurement_description", "type": "varchar", "primaryKey": false, "notNull": false },
21+
"consent_types_marketing_title": { "name": "consent_types_marketing_title", "type": "varchar", "primaryKey": false, "notNull": false },
22+
"consent_types_marketing_description": { "name": "consent_types_marketing_description", "type": "varchar", "primaryKey": false, "notNull": false },
23+
"legal_links_privacy_policy_label": { "name": "legal_links_privacy_policy_label", "type": "varchar", "primaryKey": false, "notNull": false },
24+
"legal_links_privacy_policy_href": { "name": "legal_links_privacy_policy_href", "type": "varchar", "primaryKey": false, "notNull": false },
25+
"legal_links_terms_of_service_label": { "name": "legal_links_terms_of_service_label", "type": "varchar", "primaryKey": false, "notNull": false },
26+
"legal_links_terms_of_service_href": { "name": "legal_links_terms_of_service_href", "type": "varchar", "primaryKey": false, "notNull": false }
27+
},
28+
"indexes": {},
29+
"foreignKeys": {},
30+
"compositePrimaryKeys": {}
31+
}
32+
},
33+
"enums": {},
34+
"schemas": {},
35+
"_meta": {},
36+
"id": "20260726_220500_cookie_banner_optional_fields",
37+
"prevId": "20260724_212500_action_definition_card_labels"
38+
}

0 commit comments

Comments
 (0)