Skip to content

Commit

Permalink
Update field to use validateUniqueArrayFieldSelect
Browse files Browse the repository at this point in the history
  • Loading branch information
koechkevin committed Sep 11, 2024
1 parent a0a7b28 commit 5015187
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 25 deletions.
22 changes: 8 additions & 14 deletions apps/charterafrica/src/payload/globals/Footer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { slateEditor } from "@payloadcms/richtext-slate";
import { text, select } from "payload/dist/fields/validations";
import { text } from "payload/dist/fields/validations";

import linkArray from "../fields/linkArray";
import richText from "../fields/richText";
import validateUniqueArrayFieldSelect from "../utils/validateUniqueArrayFieldSelect";

const socialMediaOptions = [
{
Expand Down Expand Up @@ -154,19 +155,12 @@ const Footer = {
isClearable: false,
isSortable: true,
},
validate: (val, options) => {
const { data, t } = options || {};
if (
data?.connect?.links?.filter((l) => l.media === val)?.length >
1
) {
return t("charterafrica.site:uniqueMedia");
}
return select(val, {
...options,
options: socialMediaOptions,
});
},
validate: validateUniqueArrayFieldSelect(
"links",
"media",
socialMediaOptions,
"charterafrica.site:uniqueMedia",
),
},
{
name: "url",
Expand Down
18 changes: 7 additions & 11 deletions apps/charterafrica/src/payload/globals/Settings.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { select } from "payload/dist/fields/validations";

import { locales } from "../utils/locales";
import validateUniqueArrayFieldSelect from "../utils/validateUniqueArrayFieldSelect";

const Settings = {
slug: "settings",
Expand Down Expand Up @@ -78,15 +77,12 @@ const Settings = {
isClearable: false,
isSortable: true,
},
validate: (val, options) => {
const { data, t } = options || {};
if (
data?.languages?.filter((l) => l.locale === val)?.length > 1
) {
return t("charterafrica.site:uniqueLocales");
}
return select(val, { ...options, options: locales });
},
validate: validateUniqueArrayFieldSelect(
"languages",
"locale",
locales,
"charterafrica.site:uniqueLocales",
),
},
{
name: "label",
Expand Down

0 comments on commit 5015187

Please sign in to comment.