From 8798ff135b7f78f6dfe726f52d38107bd028c6a0 Mon Sep 17 00:00:00 2001 From: Kevin Koech Date: Tue, 26 Sep 2023 14:35:08 +0300 Subject: [PATCH 1/3] Add single Page View --- .../Partner.js => AboutPageEntity/Page.js} | 38 ++++++++++++------- .../Page.snap.js} | 0 .../Page.test.js} | 6 +-- .../src/components/AboutPageEntity/index.js | 3 ++ .../src/components/Partner/index.js | 3 -- .../src/lib/data/pagify/index.js | 7 +++- .../src/lib/data/pagify/members.js | 31 +++++++++++++++ .../src/lib/data/pagify/partners.js | 2 +- .../src/pages/[...slugs].page.js | 4 +- 9 files changed, 70 insertions(+), 24 deletions(-) rename apps/codeforafrica/src/components/{Partner/Partner.js => AboutPageEntity/Page.js} (75%) rename apps/codeforafrica/src/components/{Partner/Partner.snap.js => AboutPageEntity/Page.snap.js} (100%) rename apps/codeforafrica/src/components/{Partner/Partner.test.js => AboutPageEntity/Page.test.js} (90%) create mode 100644 apps/codeforafrica/src/components/AboutPageEntity/index.js delete mode 100644 apps/codeforafrica/src/components/Partner/index.js create mode 100644 apps/codeforafrica/src/lib/data/pagify/members.js diff --git a/apps/codeforafrica/src/components/Partner/Partner.js b/apps/codeforafrica/src/components/AboutPageEntity/Page.js similarity index 75% rename from apps/codeforafrica/src/components/Partner/Partner.js rename to apps/codeforafrica/src/components/AboutPageEntity/Page.js index 8e479d56d..de8d8d390 100644 --- a/apps/codeforafrica/src/components/Partner/Partner.js +++ b/apps/codeforafrica/src/components/AboutPageEntity/Page.js @@ -8,8 +8,17 @@ import RelatedProjects from "@/codeforafrica/components/RelatedProjects"; import RichText from "@/codeforafrica/components/RichText"; import SectionDivider from "@/codeforafrica/components/SectionDivider"; -const Partner = React.forwardRef(function Partner( - { description, connect, relatedProjects, relatedProjectsTitle, name, logo }, +const Page = React.forwardRef(function Page( + { + description, + connect, + relatedProjects, + relatedProjectsTitle, + name, + logo, + user, + title, + }, ref, ) { return ( @@ -17,17 +26,20 @@ const Partner = React.forwardRef(function Partner(
", () => { +describe("", () => { it("renders unchanged", () => { - const { container } = render(); + const { container } = render(); expect(container).toMatchSnapshot(); }); }); diff --git a/apps/codeforafrica/src/components/AboutPageEntity/index.js b/apps/codeforafrica/src/components/AboutPageEntity/index.js new file mode 100644 index 000000000..39d0be934 --- /dev/null +++ b/apps/codeforafrica/src/components/AboutPageEntity/index.js @@ -0,0 +1,3 @@ +import Page from "./Page"; + +export default Page; diff --git a/apps/codeforafrica/src/components/Partner/index.js b/apps/codeforafrica/src/components/Partner/index.js deleted file mode 100644 index e10539fb2..000000000 --- a/apps/codeforafrica/src/components/Partner/index.js +++ /dev/null @@ -1,3 +0,0 @@ -import Partner from "./Partner"; - -export default Partner; diff --git a/apps/codeforafrica/src/lib/data/pagify/index.js b/apps/codeforafrica/src/lib/data/pagify/index.js index 62f8f69dd..f67f7321b 100644 --- a/apps/codeforafrica/src/lib/data/pagify/index.js +++ b/apps/codeforafrica/src/lib/data/pagify/index.js @@ -1,13 +1,16 @@ +import members from "./members"; import partners from "./partners"; const COLLECTION_BY_SLUG = { partners, + members, }; async function pagify(parentPage, api, context) { - const { slug: collection } = parentPage; + const { slug: collection, meta = {} } = parentPage; const pageProps = COLLECTION_BY_SLUG[collection]; - return pageProps?.(api, context) ?? null; + const props = (await pageProps?.(api, context)) ?? null; + return { ...props, meta }; } export default pagify; diff --git a/apps/codeforafrica/src/lib/data/pagify/members.js b/apps/codeforafrica/src/lib/data/pagify/members.js new file mode 100644 index 000000000..4e7b841d1 --- /dev/null +++ b/apps/codeforafrica/src/lib/data/pagify/members.js @@ -0,0 +1,31 @@ +import { imageFromMedia } from "@/codeforafrica/lib/data/utils"; + +async function members(api, context) { + const { params, locale } = context; + const slug = params.slugs[2]; + const { docs } = await api.getCollection("members", { + locale, + where: { + slug: { + equals: slug, + }, + }, + }); + if (!docs?.length) { + return null; + } + const [member] = docs; + return { + blocks: [ + { + relatedProjects: [], + ...member, + user: true, + logo: imageFromMedia(member.image), + blockType: "about-page-entity", + }, + ], + }; +} + +export default members; diff --git a/apps/codeforafrica/src/lib/data/pagify/partners.js b/apps/codeforafrica/src/lib/data/pagify/partners.js index 9e6797b75..d625c7120 100644 --- a/apps/codeforafrica/src/lib/data/pagify/partners.js +++ b/apps/codeforafrica/src/lib/data/pagify/partners.js @@ -21,7 +21,7 @@ async function partners(api, context) { relatedProjects: [], // TODO(koechkevin) Related projects go here once projects implemented ...partner, logo: imageFromMedia(partner.logo), - blockType: "partner", + blockType: "about-page-entity", }, ], }; diff --git a/apps/codeforafrica/src/pages/[...slugs].page.js b/apps/codeforafrica/src/pages/[...slugs].page.js index 2455a0275..f5883d6cc 100644 --- a/apps/codeforafrica/src/pages/[...slugs].page.js +++ b/apps/codeforafrica/src/pages/[...slugs].page.js @@ -1,6 +1,7 @@ import React from "react"; import { SWRConfig } from "swr"; +import AboutPageEntity from "@/codeforafrica/components/AboutPageEntity"; import ContactForm from "@/codeforafrica/components/ContactForm"; import CustomPageHeader from "@/codeforafrica/components/CustomPageHeader"; import FeaturedProjects from "@/codeforafrica/components/FeaturedProjects"; @@ -15,10 +16,10 @@ import OurImpact from "@/codeforafrica/components/OurImpact"; import OurPartners from "@/codeforafrica/components/OurPartners"; import OurTeam from "@/codeforafrica/components/OurTeam"; import PageHeader from "@/codeforafrica/components/PageHeader"; -import Partner from "@/codeforafrica/components/Partner"; import { getPageServerSideProps } from "@/codeforafrica/lib/data"; const componentsBySlugs = { + "about-page-entity": AboutPageEntity, "contact-form": ContactForm, "custom-page-header": CustomPageHeader, "get-involved": GetInvolved, @@ -33,7 +34,6 @@ const componentsBySlugs = { "page-header": PageHeader, "our-team": OurTeam, projects: FeaturedProjects, - partner: Partner, }; function Index({ blocks, fallback }) { From 0ac3af1998209add52de0998b4a813c7dada102d Mon Sep 17 00:00:00 2001 From: Kevin Koech Date: Tue, 26 Sep 2023 14:45:18 +0300 Subject: [PATCH 2/3] Fix failing tests --- .../AboutPageEntity/{Page.js => AboutPageEntity.js} | 0 .../{Page.snap.js => AboutPageEntity.snap.js} | 2 +- .../{Page.test.js => AboutPageEntity.test.js} | 6 +++--- apps/codeforafrica/src/components/AboutPageEntity/index.js | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) rename apps/codeforafrica/src/components/AboutPageEntity/{Page.js => AboutPageEntity.js} (100%) rename apps/codeforafrica/src/components/AboutPageEntity/{Page.snap.js => AboutPageEntity.snap.js} (95%) rename apps/codeforafrica/src/components/AboutPageEntity/{Page.test.js => AboutPageEntity.test.js} (88%) diff --git a/apps/codeforafrica/src/components/AboutPageEntity/Page.js b/apps/codeforafrica/src/components/AboutPageEntity/AboutPageEntity.js similarity index 100% rename from apps/codeforafrica/src/components/AboutPageEntity/Page.js rename to apps/codeforafrica/src/components/AboutPageEntity/AboutPageEntity.js diff --git a/apps/codeforafrica/src/components/AboutPageEntity/Page.snap.js b/apps/codeforafrica/src/components/AboutPageEntity/AboutPageEntity.snap.js similarity index 95% rename from apps/codeforafrica/src/components/AboutPageEntity/Page.snap.js rename to apps/codeforafrica/src/components/AboutPageEntity/AboutPageEntity.snap.js index 86026b06a..51ed4fcae 100644 --- a/apps/codeforafrica/src/components/AboutPageEntity/Page.snap.js +++ b/apps/codeforafrica/src/components/AboutPageEntity/AboutPageEntity.snap.js @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[` renders unchanged 1`] = ` +exports[` renders unchanged 1`] = `
", () => { +describe("", () => { it("renders unchanged", () => { - const { container } = render(); + const { container } = render(); expect(container).toMatchSnapshot(); }); }); diff --git a/apps/codeforafrica/src/components/AboutPageEntity/index.js b/apps/codeforafrica/src/components/AboutPageEntity/index.js index 39d0be934..1e4246770 100644 --- a/apps/codeforafrica/src/components/AboutPageEntity/index.js +++ b/apps/codeforafrica/src/components/AboutPageEntity/index.js @@ -1,3 +1,3 @@ -import Page from "./Page"; +import AboutPageEntity from "./AboutPageEntity"; -export default Page; +export default AboutPageEntity; From 3217d236569cbc3349a6c4219c202c8762226733 Mon Sep 17 00:00:00 2001 From: Kevin Koech Date: Wed, 27 Sep 2023 11:29:37 +0300 Subject: [PATCH 3/3] implement feedback --- apps/codeforafrica/src/lib/data/pagify/index.js | 5 ++--- apps/codeforafrica/src/lib/data/pagify/members.js | 6 ++++++ apps/codeforafrica/src/lib/data/pagify/partners.js | 6 ++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/apps/codeforafrica/src/lib/data/pagify/index.js b/apps/codeforafrica/src/lib/data/pagify/index.js index f67f7321b..074c84300 100644 --- a/apps/codeforafrica/src/lib/data/pagify/index.js +++ b/apps/codeforafrica/src/lib/data/pagify/index.js @@ -7,10 +7,9 @@ const COLLECTION_BY_SLUG = { }; async function pagify(parentPage, api, context) { - const { slug: collection, meta = {} } = parentPage; + const { slug: collection } = parentPage; const pageProps = COLLECTION_BY_SLUG[collection]; - const props = (await pageProps?.(api, context)) ?? null; - return { ...props, meta }; + return pageProps?.(api, context) ?? null; } export default pagify; diff --git a/apps/codeforafrica/src/lib/data/pagify/members.js b/apps/codeforafrica/src/lib/data/pagify/members.js index 4e7b841d1..e2bd7ea9f 100644 --- a/apps/codeforafrica/src/lib/data/pagify/members.js +++ b/apps/codeforafrica/src/lib/data/pagify/members.js @@ -15,6 +15,11 @@ async function members(api, context) { return null; } const [member] = docs; + const meta = { + title: member.name, + description: member.decription, + image: member.image, + }; return { blocks: [ { @@ -25,6 +30,7 @@ async function members(api, context) { blockType: "about-page-entity", }, ], + meta, }; } diff --git a/apps/codeforafrica/src/lib/data/pagify/partners.js b/apps/codeforafrica/src/lib/data/pagify/partners.js index d625c7120..1d7109311 100644 --- a/apps/codeforafrica/src/lib/data/pagify/partners.js +++ b/apps/codeforafrica/src/lib/data/pagify/partners.js @@ -15,6 +15,11 @@ async function partners(api, context) { return null; } const [partner] = docs; + const meta = { + title: partner.name, + description: partner.decription, + image: partner.image, + }; return { blocks: [ { @@ -24,6 +29,7 @@ async function partners(api, context) { blockType: "about-page-entity", }, ], + meta, }; }