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;