Skip to content

Commit

Permalink
Merge pull request #698 from CodeForAfrica/fix/codeforafrica_validati…
Browse files Browse the repository at this point in the history
…on_sociallinks

Fix @CodeForAfrica socialLinks
  • Loading branch information
kilemensi authored May 23, 2024
2 parents 8c70bf5 + f2f888d commit fd78167
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion apps/codeforafrica/contrib/dokku/Dockerfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
FROM codeforafrica/codeforafrica-ui:1.0.53
FROM codeforafrica/codeforafrica-ui:1.0.54
2 changes: 1 addition & 1 deletion apps/codeforafrica/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codeforafrica",
"version": "1.0.53",
"version": "1.0.54",
"private": true,
"author": "Code for Africa <[email protected]>",
"description": "This is the main CFA site.",
Expand Down
7 changes: 7 additions & 0 deletions apps/codeforafrica/payload.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
23 changes: 16 additions & 7 deletions apps/codeforafrica/src/payload/fields/socialLinks.js
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -12,7 +12,7 @@ export const socialMediaOptions = [
"Slack",
];

function socialLinks(overrides) {
function socialLinks(overrides = {}) {
const defaults = {
name: "links",
type: "array",
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit fd78167

Please sign in to comment.