From 916cb6e409ae049cb5af7000efef37cbeff198d1 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Tue, 19 Sep 2023 11:43:33 +0300 Subject: [PATCH 01/11] Add global tags --- apps/codeforafrica/payload.config.ts | 3 +- .../src/payload/collections/Tags.js | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 apps/codeforafrica/src/payload/collections/Tags.js diff --git a/apps/codeforafrica/payload.config.ts b/apps/codeforafrica/payload.config.ts index f152e0df2..c291fe7cf 100644 --- a/apps/codeforafrica/payload.config.ts +++ b/apps/codeforafrica/payload.config.ts @@ -5,6 +5,7 @@ import Media from "./src/payload/collections/Media"; import Pages from "./src/payload/collections/Pages"; import Partners from "./src/payload/collections/Partners"; import Settings from "./src/payload/globals/Settings"; +import Tags from "./src/payload/collections/Tags"; import { CollectionConfig, GlobalConfig } from "payload/types"; import dotenv from "dotenv"; import seo from "@payloadcms/plugin-seo"; @@ -30,7 +31,7 @@ const adapter = s3Adapter({ export default buildConfig({ serverURL: appURL, - collections: [Pages, Media, Partners] as CollectionConfig[], + collections: [Pages, Media, Partners, Tags] as CollectionConfig[], globals: [Settings] as GlobalConfig[], admin: { css: path.resolve(__dirname, "./src/payload/admin/scss/custom.scss"), diff --git a/apps/codeforafrica/src/payload/collections/Tags.js b/apps/codeforafrica/src/payload/collections/Tags.js new file mode 100644 index 000000000..933a042eb --- /dev/null +++ b/apps/codeforafrica/src/payload/collections/Tags.js @@ -0,0 +1,28 @@ +import slug from "../fields/slug"; + +const Tags = { + slug: "tag", + admin: { + useAsTitle: "name", + }, + access: { + read: () => true, // Everyone can read Pages + }, + fields: [ + { + name: "name", + label: { + en: "Name", + fr: "Nom", + pt: "Nome", + }, + type: "text", + localized: true, + required: true, + unique: true, + }, + slug({ fieldToUse: "name" }), + ], +}; + +export default Tags; From 8ba56382ab2f4bdc9bf4aafb15e6b908b70172c2 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Tue, 19 Sep 2023 11:53:45 +0300 Subject: [PATCH 02/11] Add Author collection --- apps/codeforafrica/payload.config.ts | 3 ++- .../src/payload/collections/Authors.js | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 apps/codeforafrica/src/payload/collections/Authors.js diff --git a/apps/codeforafrica/payload.config.ts b/apps/codeforafrica/payload.config.ts index c291fe7cf..ef0f88e77 100644 --- a/apps/codeforafrica/payload.config.ts +++ b/apps/codeforafrica/payload.config.ts @@ -1,6 +1,7 @@ import path from "path"; import { buildConfig } from "payload/config"; +import Authors from "./src/payload/collections/Authors"; import Media from "./src/payload/collections/Media"; import Pages from "./src/payload/collections/Pages"; import Partners from "./src/payload/collections/Partners"; @@ -31,7 +32,7 @@ const adapter = s3Adapter({ export default buildConfig({ serverURL: appURL, - collections: [Pages, Media, Partners, Tags] as CollectionConfig[], + collections: [Authors,Pages, Media, Partners, Tags] as CollectionConfig[], globals: [Settings] as GlobalConfig[], admin: { css: path.resolve(__dirname, "./src/payload/admin/scss/custom.scss"), diff --git a/apps/codeforafrica/src/payload/collections/Authors.js b/apps/codeforafrica/src/payload/collections/Authors.js new file mode 100644 index 000000000..7b6d41c5b --- /dev/null +++ b/apps/codeforafrica/src/payload/collections/Authors.js @@ -0,0 +1,25 @@ +const Authors = { + slug: "author", + access: { + read: () => true, + }, + admin: { + useAsTitle: "fullName", + }, + fields: [ + { + name: "fullName", + type: "text", + label: { + en: "Full Name", + fr: "Nom et prénom", + pt: "Nome completo", + }, + localized: false, + required: true, + }, + // If more author information needed e.g contact details go here + ], +}; + +export default Authors; From 3976618cabd6e420c159dd1a87f11f667847daa2 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Tue, 19 Sep 2023 11:55:30 +0300 Subject: [PATCH 03/11] Add tags and authors relationships --- .../codeforafrica/src/payload/fields/authors.js | 17 +++++++++++++++++ apps/codeforafrica/src/payload/fields/tags.js | 14 ++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 apps/codeforafrica/src/payload/fields/authors.js create mode 100644 apps/codeforafrica/src/payload/fields/tags.js diff --git a/apps/codeforafrica/src/payload/fields/authors.js b/apps/codeforafrica/src/payload/fields/authors.js new file mode 100644 index 000000000..7d29076b3 --- /dev/null +++ b/apps/codeforafrica/src/payload/fields/authors.js @@ -0,0 +1,17 @@ +import { deepmerge } from "@mui/utils"; + +const authors = (overrides) => + deepmerge( + { + name: "authors", + type: "relationship", + relationTo: "author", + hasMany: true, + admin: { + position: "sidebar", + }, + }, + overrides, + ); + +export default authors; diff --git a/apps/codeforafrica/src/payload/fields/tags.js b/apps/codeforafrica/src/payload/fields/tags.js new file mode 100644 index 000000000..d38440d6f --- /dev/null +++ b/apps/codeforafrica/src/payload/fields/tags.js @@ -0,0 +1,14 @@ +import { deepmerge } from "@mui/utils"; + +const tags = (overrides) => { + const field = { + name: "tags", + required: true, + type: "relationship", + relationTo: "tag", + hasMany: true, + }; + return deepmerge(field, overrides); +}; + +export default tags; From b1d24de3ee4a2ea729ca4238f624b96b83e2974a Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Tue, 19 Sep 2023 12:46:17 +0300 Subject: [PATCH 04/11] Add published on field --- .../src/payload/fields/publishedOn.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 apps/codeforafrica/src/payload/fields/publishedOn.js diff --git a/apps/codeforafrica/src/payload/fields/publishedOn.js b/apps/codeforafrica/src/payload/fields/publishedOn.js new file mode 100644 index 000000000..f735543a8 --- /dev/null +++ b/apps/codeforafrica/src/payload/fields/publishedOn.js @@ -0,0 +1,22 @@ +import { deepmerge } from "@mui/utils"; + +const publishedOn = (overrides) => + deepmerge( + { + name: "publishedOn", + type: "date", + required: true, + hooks: { + beforeValidate: [({ value }) => (value ? new Date(value) : new Date())], + }, + admin: { + date: { + pickerAppearance: "dayAndTime", + }, + position: "sidebar", + }, + }, + overrides, + ); + +export default publishedOn; From ee1c6bdeaa9aaaf4524dd78c7dc7083891910ff6 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Tue, 19 Sep 2023 12:55:59 +0300 Subject: [PATCH 05/11] Add contents building blocks --- .../src/payload/blocks/ExternalEmbed.js | 81 +++++++++++++++++++ .../src/payload/blocks/MediaBlock.js | 23 ++++++ .../src/payload/blocks/RichText.js | 32 ++++++++ .../src/payload/fields/blockFields.js | 21 +++++ .../src/payload/fields/content.js | 18 +++++ 5 files changed, 175 insertions(+) create mode 100644 apps/codeforafrica/src/payload/blocks/ExternalEmbed.js create mode 100644 apps/codeforafrica/src/payload/blocks/MediaBlock.js create mode 100644 apps/codeforafrica/src/payload/blocks/RichText.js create mode 100644 apps/codeforafrica/src/payload/fields/blockFields.js create mode 100644 apps/codeforafrica/src/payload/fields/content.js diff --git a/apps/codeforafrica/src/payload/blocks/ExternalEmbed.js b/apps/codeforafrica/src/payload/blocks/ExternalEmbed.js new file mode 100644 index 000000000..d12c71f85 --- /dev/null +++ b/apps/codeforafrica/src/payload/blocks/ExternalEmbed.js @@ -0,0 +1,81 @@ +import blockFields from "../fields/blockFields"; + +const ExternalEmbed = { + slug: "external-embed", + fields: [ + blockFields({ + name: "embedBlockFields", + fields: [ + { + type: "row", + fields: [ + { + name: "embedType", + type: "radio", + defaultValue: "url", + options: [ + { + label: { + en: "URL", + fr: "URL", + pt: "URL", + }, + value: "url", + }, + { + label: { + en: "Code", + fr: "Code", + pt: "Código", + }, + value: "code", + }, + ], + }, + ], + }, + { + name: "url", + label: { + en: "URL", + fr: "URL", + pt: "URL", + }, + type: "text", + required: true, + admin: { + condition: (_, siblingData) => siblingData?.embedType === "url", + }, + }, + { + name: "caption", + label: { + en: "Caption", + fr: "Légende", + pt: "Rubrica", + }, + type: "text", + localized: true, + admin: { + condition: (_, siblingData) => siblingData?.embedType === "url", + }, + }, + { + name: "code", + label: { + en: "Code", + fr: "Code", + pt: "Código", + }, + type: "code", + required: true, + admin: { + condition: (_, siblingData) => siblingData?.embedType === "code", + }, + }, + ], + }), + ], +}; + +export default ExternalEmbed; diff --git a/apps/codeforafrica/src/payload/blocks/MediaBlock.js b/apps/codeforafrica/src/payload/blocks/MediaBlock.js new file mode 100644 index 000000000..08b2530a6 --- /dev/null +++ b/apps/codeforafrica/src/payload/blocks/MediaBlock.js @@ -0,0 +1,23 @@ +import blockFields from "../fields/blockFields"; + +const MediaBlock = { + slug: "mediaBlock", + fields: [ + blockFields({ + name: "mediaBlockFields", + fields: [ + { + name: "image", + type: "upload", + relationTo: "media", + required: true, + filterOptions: { + mimeType: { contains: "image" }, + }, + }, + ], + }), + ], +}; + +export default MediaBlock; diff --git a/apps/codeforafrica/src/payload/blocks/RichText.js b/apps/codeforafrica/src/payload/blocks/RichText.js new file mode 100644 index 000000000..ae19f33fc --- /dev/null +++ b/apps/codeforafrica/src/payload/blocks/RichText.js @@ -0,0 +1,32 @@ +import blockFields from "../fields/blockFields"; +import richText from "../fields/richText"; + +const RichText = { + slug: "richText", + fields: [ + blockFields({ + name: "richTextBlockFields", + fields: [ + richText({ + name: "content", + admin: { + elements: [ + "h1", + "h2", + "h3", + "h4", + "h5", + "h6", + "link", + "ol", + "ul", + "indent", + ], + }, + }), + ], + }), + ], +}; + +export default RichText; diff --git a/apps/codeforafrica/src/payload/fields/blockFields.js b/apps/codeforafrica/src/payload/fields/blockFields.js new file mode 100644 index 000000000..55188a7c5 --- /dev/null +++ b/apps/codeforafrica/src/payload/fields/blockFields.js @@ -0,0 +1,21 @@ +import { deepmerge } from "@mui/utils"; + +const blockFields = ({ name, fields, overrides }) => + deepmerge( + { + name, + label: false, + type: "group", + admin: { + hideGutter: true, + style: { + margin: 0, + padding: 0, + }, + }, + fields, + }, + overrides, + ); + +export default blockFields; diff --git a/apps/codeforafrica/src/payload/fields/content.js b/apps/codeforafrica/src/payload/fields/content.js new file mode 100644 index 000000000..893bfaf00 --- /dev/null +++ b/apps/codeforafrica/src/payload/fields/content.js @@ -0,0 +1,18 @@ +import { deepmerge } from "@mui/utils"; + +import ExternalEmbed from "../blocks/ExternalEmbed"; +import MediaBlock from "../blocks/MediaBlock"; +import RichText from "../blocks/RichText"; + +const content = (overrides) => + deepmerge( + { + name: "content", + type: "blocks", + blocks: [RichText, MediaBlock, ExternalEmbed], + localized: true, + }, + overrides, + ); + +export default content; From e684b994fb0c5632abdb05d5a54f41d2b082e459 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Tue, 19 Sep 2023 13:05:46 +0300 Subject: [PATCH 06/11] Format code --- apps/codeforafrica/payload.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/codeforafrica/payload.config.ts b/apps/codeforafrica/payload.config.ts index ef0f88e77..94f3541f1 100644 --- a/apps/codeforafrica/payload.config.ts +++ b/apps/codeforafrica/payload.config.ts @@ -32,7 +32,7 @@ const adapter = s3Adapter({ export default buildConfig({ serverURL: appURL, - collections: [Authors,Pages, Media, Partners, Tags] as CollectionConfig[], + collections: [Authors, Pages, Media, Partners, Tags] as CollectionConfig[], globals: [Settings] as GlobalConfig[], admin: { css: path.resolve(__dirname, "./src/payload/admin/scss/custom.scss"), From 9957e133a72a18535550d0ca4bd07ffe12256e7a Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Tue, 19 Sep 2023 13:46:40 +0300 Subject: [PATCH 07/11] Fix not found pages --- apps/codeforafrica/src/lib/data/rest/index.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/apps/codeforafrica/src/lib/data/rest/index.js b/apps/codeforafrica/src/lib/data/rest/index.js index 80c11bb13..63517ea4b 100644 --- a/apps/codeforafrica/src/lib/data/rest/index.js +++ b/apps/codeforafrica/src/lib/data/rest/index.js @@ -36,6 +36,13 @@ export const api = { export async function getPageStaticProps(context) { const props = await getPageProps(api, context); + if (!props) { + return { + props: { + title: "Page not found", + }, + }; + } return { props, }; From 1dac236e40b55eb9a85f9f3b8bbbfcad17ebad25 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Wed, 20 Sep 2023 12:46:45 +0300 Subject: [PATCH 08/11] Update get posts cms --- apps/codeforafrica/src/lib/data/rest/index.js | 7 ----- .../src/payload/blocks/ExternalEmbed.js | 30 ++++--------------- .../src/payload/collections/Authors.js | 7 +---- .../src/payload/collections/Tags.js | 6 +--- 4 files changed, 7 insertions(+), 43 deletions(-) diff --git a/apps/codeforafrica/src/lib/data/rest/index.js b/apps/codeforafrica/src/lib/data/rest/index.js index 63517ea4b..80c11bb13 100644 --- a/apps/codeforafrica/src/lib/data/rest/index.js +++ b/apps/codeforafrica/src/lib/data/rest/index.js @@ -36,13 +36,6 @@ export const api = { export async function getPageStaticProps(context) { const props = await getPageProps(api, context); - if (!props) { - return { - props: { - title: "Page not found", - }, - }; - } return { props, }; diff --git a/apps/codeforafrica/src/payload/blocks/ExternalEmbed.js b/apps/codeforafrica/src/payload/blocks/ExternalEmbed.js index d12c71f85..fd89a9b68 100644 --- a/apps/codeforafrica/src/payload/blocks/ExternalEmbed.js +++ b/apps/codeforafrica/src/payload/blocks/ExternalEmbed.js @@ -15,19 +15,11 @@ const ExternalEmbed = { defaultValue: "url", options: [ { - label: { - en: "URL", - fr: "URL", - pt: "URL", - }, + label: "URL", value: "url", }, { - label: { - en: "Code", - fr: "Code", - pt: "Código", - }, + label: "Code", value: "code", }, ], @@ -36,11 +28,7 @@ const ExternalEmbed = { }, { name: "url", - label: { - en: "URL", - fr: "URL", - pt: "URL", - }, + label: "URL", type: "text", required: true, admin: { @@ -49,11 +37,7 @@ const ExternalEmbed = { }, { name: "caption", - label: { - en: "Caption", - fr: "Légende", - pt: "Rubrica", - }, + label: "Caption", type: "text", localized: true, admin: { @@ -62,11 +46,7 @@ const ExternalEmbed = { }, { name: "code", - label: { - en: "Code", - fr: "Code", - pt: "Código", - }, + label: "Code", type: "code", required: true, admin: { diff --git a/apps/codeforafrica/src/payload/collections/Authors.js b/apps/codeforafrica/src/payload/collections/Authors.js index 7b6d41c5b..5967d4152 100644 --- a/apps/codeforafrica/src/payload/collections/Authors.js +++ b/apps/codeforafrica/src/payload/collections/Authors.js @@ -10,15 +10,10 @@ const Authors = { { name: "fullName", type: "text", - label: { - en: "Full Name", - fr: "Nom et prénom", - pt: "Nome completo", - }, + label: "Full Name", localized: false, required: true, }, - // If more author information needed e.g contact details go here ], }; diff --git a/apps/codeforafrica/src/payload/collections/Tags.js b/apps/codeforafrica/src/payload/collections/Tags.js index 933a042eb..4cecf8e07 100644 --- a/apps/codeforafrica/src/payload/collections/Tags.js +++ b/apps/codeforafrica/src/payload/collections/Tags.js @@ -11,11 +11,7 @@ const Tags = { fields: [ { name: "name", - label: { - en: "Name", - fr: "Nom", - pt: "Nome", - }, + label: "Name", type: "text", localized: true, required: true, From 8101c7e9b82044648e7ea3c57cd4c43c420ca541 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Wed, 20 Sep 2023 14:43:29 +0300 Subject: [PATCH 09/11] Fix formating --- apps/codeforafrica/payload.config.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/codeforafrica/payload.config.ts b/apps/codeforafrica/payload.config.ts index b6de2adad..3022d93ff 100644 --- a/apps/codeforafrica/payload.config.ts +++ b/apps/codeforafrica/payload.config.ts @@ -33,7 +33,14 @@ const adapter = s3Adapter({ export default buildConfig({ serverURL: appURL, - collections: [Authors, Impact, Pages, Media, Partners, Tags] as CollectionConfig[], + collections: [ + Authors, + Impact, + Pages, + Media, + Partners, + Tags, + ] as CollectionConfig[], globals: [Settings] as GlobalConfig[], admin: { css: path.resolve(__dirname, "./src/payload/admin/scss/custom.scss"), From 338535753e4f77e6707e49f5168769f0538d745a Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Fri, 22 Sep 2023 10:45:37 +0300 Subject: [PATCH 10/11] Remove unnecessary comment --- apps/codeforafrica/src/payload/collections/Tags.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/codeforafrica/src/payload/collections/Tags.js b/apps/codeforafrica/src/payload/collections/Tags.js index 4cecf8e07..0f3cf7fe2 100644 --- a/apps/codeforafrica/src/payload/collections/Tags.js +++ b/apps/codeforafrica/src/payload/collections/Tags.js @@ -6,7 +6,7 @@ const Tags = { useAsTitle: "name", }, access: { - read: () => true, // Everyone can read Pages + read: () => true, }, fields: [ { From 126ac08b36c97b73ea001cf0dd95e5c37d7d3de1 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Fri, 22 Sep 2023 12:19:25 +0300 Subject: [PATCH 11/11] Fix formating --- apps/codeforafrica/payload.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/codeforafrica/payload.config.ts b/apps/codeforafrica/payload.config.ts index 14e693014..2b825d735 100644 --- a/apps/codeforafrica/payload.config.ts +++ b/apps/codeforafrica/payload.config.ts @@ -41,7 +41,7 @@ export default buildConfig({ Pages, Media, Partners, - Tags + Tags, ] as CollectionConfig[], globals: [Settings] as GlobalConfig[], admin: {