From 00f2405101e3092bff289ecf1a1e1063822676fc Mon Sep 17 00:00:00 2001 From: kilemensi Date: Thu, 23 May 2024 08:35:04 +0300 Subject: [PATCH 1/4] i18n validation message --- apps/codeforafrica/payload.config.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/apps/codeforafrica/payload.config.ts b/apps/codeforafrica/payload.config.ts index 07041f4e6..5a01cf688 100644 --- a/apps/codeforafrica/payload.config.ts +++ b/apps/codeforafrica/payload.config.ts @@ -110,6 +110,13 @@ export default buildConfig({ i18n: { fallbackLng: "en", // default debug: false, // default + resources: { + en: { + "codeforafrica.validation": { + uniquePlatforms: "Please select a unique platform", + }, + }, + }, }, plugins: [ cloudStorage({ From d2f63724e119f8deea0de0c862aa06391a51fab5 Mon Sep 17 00:00:00 2001 From: kilemensi Date: Thu, 23 May 2024 08:35:26 +0300 Subject: [PATCH 2/4] Use correct validation method and options --- .../src/payload/fields/socialLinks.js | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/apps/codeforafrica/src/payload/fields/socialLinks.js b/apps/codeforafrica/src/payload/fields/socialLinks.js index ac5c77d31..2a0bf0e10 100644 --- a/apps/codeforafrica/src/payload/fields/socialLinks.js +++ b/apps/codeforafrica/src/payload/fields/socialLinks.js @@ -1,5 +1,5 @@ import { deepmerge } from "@mui/utils"; -import { array } from "payload/dist/fields/validations"; +import { select } from "payload/dist/fields/validations"; import url from "./url"; @@ -51,12 +51,21 @@ function socialLinks(overrides) { label: "Platform", options: socialMediaOptions, required: true, - validate: (val, options) => { - const { data } = options || {}; - if (data?.links?.filter((l) => l.platform === val)?.length > 1) { - return "Please select a unique platform"; + validate: (val, args) => { + const { data, t } = args || {}; + const { name: linksName = "links" } = overrides; + if ( + data?.[linksName]?.filter((l) => l.platform === val)?.length > 1 + ) { + return t("codeforafrica.validation:uniquePlatforms"); } - return array(val, options); + + const { + hasMany, + options = socialMediaOptions, + required = true, + } = args; + return select(val, { hasMany, options, required, t }); }, }, url({ From 46525b08f76bfedddcafb16b3604ea9fed868575 Mon Sep 17 00:00:00 2001 From: kilemensi Date: Thu, 23 May 2024 08:38:07 +0300 Subject: [PATCH 3/4] =?UTF-8?q?Bump=20codeforafrica=20version:=201.0.53=20?= =?UTF-8?q?=E2=86=92=201.0.54?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/codeforafrica/contrib/dokku/Dockerfile | 2 +- apps/codeforafrica/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/codeforafrica/contrib/dokku/Dockerfile b/apps/codeforafrica/contrib/dokku/Dockerfile index 7f9147748..b8326f59f 100644 --- a/apps/codeforafrica/contrib/dokku/Dockerfile +++ b/apps/codeforafrica/contrib/dokku/Dockerfile @@ -1 +1 @@ -FROM codeforafrica/codeforafrica-ui:1.0.53 +FROM codeforafrica/codeforafrica-ui:1.0.54 diff --git a/apps/codeforafrica/package.json b/apps/codeforafrica/package.json index 0f930d5a5..2fc0e42df 100644 --- a/apps/codeforafrica/package.json +++ b/apps/codeforafrica/package.json @@ -1,6 +1,6 @@ { "name": "codeforafrica", - "version": "1.0.53", + "version": "1.0.54", "private": true, "author": "Code for Africa ", "description": "This is the main CFA site.", From f2f888db55cf09b51b069a6c4d472d35f08aa667 Mon Sep 17 00:00:00 2001 From: Clemence Kyara Date: Thu, 23 May 2024 10:34:26 +0300 Subject: [PATCH 4/4] `overrides` on socialLinks is optional --- apps/codeforafrica/src/payload/fields/socialLinks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/codeforafrica/src/payload/fields/socialLinks.js b/apps/codeforafrica/src/payload/fields/socialLinks.js index 2a0bf0e10..566c9cc70 100644 --- a/apps/codeforafrica/src/payload/fields/socialLinks.js +++ b/apps/codeforafrica/src/payload/fields/socialLinks.js @@ -12,7 +12,7 @@ export const socialMediaOptions = [ "Slack", ]; -function socialLinks(overrides) { +function socialLinks(overrides = {}) { const defaults = { name: "links", type: "array",