diff --git a/apps/codeforafrica/public/images/cms/blocks/featured_stories.jpg b/apps/codeforafrica/public/images/cms/blocks/featured_stories.jpg new file mode 100644 index 000000000..33cc3e2a5 Binary files /dev/null and b/apps/codeforafrica/public/images/cms/blocks/featured_stories.jpg differ diff --git a/apps/codeforafrica/src/components/NewsAndStories/NewsAndStories.js b/apps/codeforafrica/src/components/NewsAndStories/NewsAndStories.js index d7d2523a2..075f9d6ac 100644 --- a/apps/codeforafrica/src/components/NewsAndStories/NewsAndStories.js +++ b/apps/codeforafrica/src/components/NewsAndStories/NewsAndStories.js @@ -8,10 +8,13 @@ import FeaturedArticle from "@/codeforafrica/components/FeaturedArticle"; // TODO(kilemensi): Remove hard-coded strings const NewsAndStories = React.forwardRef(function NewsAndStories(props, ref) { - const { articles, title } = props; - if (!articles?.length) { - return null; - } + const { + action: { label, href }, + featured, + featuredStoryActionLabel, + stories, + title, + } = props; return (
diff --git a/apps/codeforafrica/src/components/NewsAndStories/NewsAndStories.snap.js b/apps/codeforafrica/src/components/NewsAndStories/NewsAndStories.snap.js index 362fdf885..79b7eda90 100644 --- a/apps/codeforafrica/src/components/NewsAndStories/NewsAndStories.snap.js +++ b/apps/codeforafrica/src/components/NewsAndStories/NewsAndStories.snap.js @@ -1,3 +1,106 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[` renders unchanged 1`] = `
`; +exports[` renders unchanged 1`] = ` +
+ +
+`; diff --git a/apps/codeforafrica/src/components/NewsAndStories/NewsAndStories.test.js b/apps/codeforafrica/src/components/NewsAndStories/NewsAndStories.test.js index 40ce044b9..2129d1aca 100644 --- a/apps/codeforafrica/src/components/NewsAndStories/NewsAndStories.test.js +++ b/apps/codeforafrica/src/components/NewsAndStories/NewsAndStories.test.js @@ -10,6 +10,49 @@ const render = createRender({ theme }); const defaultProps = { title: "News and Stories", + action: { + label: "Read Stories", + href: "/stories", + }, + featured: { + title: "Battle for gender equality in African media continues", + excerpt: + "Lorem ipsum dolor sit amet consectetur adipiscing elit mattis, vestibulum potenti rhoncus eget lacus fermentum taciti quam, quis curae accumsan viverra semper dapibus sed.", + publishedOn: "Jan 6, 2022", + image: { + src: "https://res.cloudinary.com/code-for-africa/image/upload/v1650885664/codeforafrica/unsplash_L6hr1BptcNc_of23p3.png", + alt: "Featured Article Image", + }, + readMoreLabel: "Read Story", + href: "/stories/article-1", + }, + posts: [ + { + title: "Battle for gender equality in African media continues", + excerpt: + "Lorem ipsum dolor sit amet consectetur adipiscing elit mattis, vestibulum potenti rhoncus eget lacus fermentum taciti quam, quis curae accumsan viverra semper dapibus sed.", + publishedOn: "Jan 6, 2022", + image: { + src: "https://res.cloudinary.com/code-for-africa/image/upload/v1650885664/codeforafrica/unsplash_L6hr1BptcNc_of23p3.png", + alt: "Featured Article Image", + }, + readMoreLabel: "Read Story", + href: "/stories/article-1", + }, + { + title: "Battle for gender equality in African media continues", + excerpt: + "Lorem ipsum dolor sit amet consectetur adipiscing elit mattis, vestibulum potenti rhoncus eget lacus fermentum taciti quam, quis curae accumsan viverra semper dapibus sed.", + publishedOn: "Jan 6, 2022", + image: { + src: "https://res.cloudinary.com/code-for-africa/image/upload/v1650885664/codeforafrica/unsplash_L6hr1BptcNc_of23p3.png", + alt: "Featured Article Image", + }, + readMoreLabel: "Read Story", + href: "/stories/article-1", + }, + ], + featuredStoryActionLabel: "Read Story", }; describe("", () => { diff --git a/apps/codeforafrica/src/lib/data/blockify/featuredStories.js b/apps/codeforafrica/src/lib/data/blockify/featuredStories.js new file mode 100644 index 000000000..29edd633d --- /dev/null +++ b/apps/codeforafrica/src/lib/data/blockify/featuredStories.js @@ -0,0 +1,20 @@ +import { formatPost } from "@/codeforafrica/lib/data/utils/posts"; + +async function featuredStories(block) { + const { + primaryTag, + featured: { story: featuredStory, action: featuredStoryActionLabel }, + stories: { items, action }, + ...other + } = block; + return { + ...other, + action, + featured: formatPost(featuredStory, primaryTag), + featuredStoryActionLabel, + stories: items.map((item) => formatPost(item, primaryTag)), + slug: "featured-stories", + }; +} + +export default featuredStories; diff --git a/apps/codeforafrica/src/lib/data/blockify/index.js b/apps/codeforafrica/src/lib/data/blockify/index.js index 1bcef3254..9d6b42038 100644 --- a/apps/codeforafrica/src/lib/data/blockify/index.js +++ b/apps/codeforafrica/src/lib/data/blockify/index.js @@ -1,3 +1,4 @@ +import featuredStories from "./featuredStories"; import getInvolved from "./get-involved"; import hero from "./hero"; import meetOurTeam from "./meetOurTeam"; @@ -7,6 +8,7 @@ import ourWork from "./ourWork"; import posts from "./posts"; const propsifyBlockBySlug = { + "featured-stories": featuredStories, "get-involved": getInvolved, hero, "meet-our-team": meetOurTeam, diff --git a/apps/codeforafrica/src/pages/[...slugs].page.js b/apps/codeforafrica/src/pages/[...slugs].page.js index 153d857c7..b434ad77b 100644 --- a/apps/codeforafrica/src/pages/[...slugs].page.js +++ b/apps/codeforafrica/src/pages/[...slugs].page.js @@ -29,12 +29,12 @@ const componentsBySlugs = { article: ArticlePage, "contact-form": ContactForm, "custom-page-header": CustomPageHeader, + "featured-stories": NewsAndStories, "get-involved": GetInvolved, "get-in-touch": GetInTouch, hero: Hero, "join-our-slack": JoinOurSlack, "meet-our-team": MeetOurTeam, - "news-stories": NewsAndStories, opportunities: Opportunities, "our-guiding-principles": GuidingPrinciplesCardList, "our-impact": OurImpact, diff --git a/apps/codeforafrica/src/payload/blocks/FeaturedStories.js b/apps/codeforafrica/src/payload/blocks/FeaturedStories.js new file mode 100644 index 000000000..3c01c52c0 --- /dev/null +++ b/apps/codeforafrica/src/payload/blocks/FeaturedStories.js @@ -0,0 +1,76 @@ +import linkGroup from "../fields/links/linkGroup"; + +const FeaturedStories = { + slug: "featured-stories", + imageURL: "/images/cms/blocks/featured_stories.jpg", + imageAltText: "Featured Stories", + labels: { + singular: { + en: "Featured Stories", + }, + plural: { + en: "Featured Stories", + }, + }, + fields: [ + { + name: "title", + type: "text", + required: true, + }, + { + name: "primaryTag", + label: "Post Type", + type: "text", + defaultValue: "stories", + admin: { + hidden: true, + }, + }, + { + name: "featured", + label: "Featured Story", + type: "group", + fields: [ + { + name: "story", + type: "relationship", + relationTo: "posts", + hasMany: false, + required: true, + }, + { + name: "action", + label: "Action Label", + type: "text", + defaultValue: "Read Story", + }, + ], + }, + { + name: "stories", + label: "Stories", + type: "group", + fields: [ + { + name: "items", + label: "Stories", + type: "relationship", + relationTo: "posts", + hasMany: true, + minRows: 1, + maxRows: 3, + required: true, + }, + linkGroup({ + overrides: { + name: "action", + label: "Browse More Action", + }, + }), + ], + }, + ], +}; + +export default FeaturedStories; diff --git a/apps/codeforafrica/src/payload/collections/Pages.js b/apps/codeforafrica/src/payload/collections/Pages.js index 3b3a25c3f..e26b96933 100644 --- a/apps/codeforafrica/src/payload/collections/Pages.js +++ b/apps/codeforafrica/src/payload/collections/Pages.js @@ -1,6 +1,7 @@ import ContactForm from "../blocks/ContactForm"; import CustomPageHeader from "../blocks/CustomPageHeader"; import Error from "../blocks/Error"; +import FeaturedStories from "../blocks/FeaturedStories"; import GetInTouch from "../blocks/GetInTouch"; import GetInvolved from "../blocks/GetInvolved"; import GuidingPrinciples from "../blocks/GuidingPrinciples"; @@ -51,6 +52,7 @@ const Pages = { blocks: [ ContactForm, Error, + FeaturedStories, GetInTouch, GetInvolved, GuidingPrinciples,