Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/cfa single partners cms #585

Merged
merged 14 commits into from
Sep 21, 2023
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 5 additions & 9 deletions apps/codeforafrica/src/components/ConnectBar/ConnectBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@ import SocialMediaButton from "@/codeforafrica/components/SocialMediaButton";
const ConnectBar = React.forwardRef(function ConnectBar(props, ref) {
const { sx, title, links } = props;

if (!links || !Object.entries(links)?.length) {
if (!links?.length) {
return null;
}

const socialConnections = [
"twitter",
"slack",
"linkedin",
"facebook",
"instagram",
"github",
].flatMap((name) => (links[name] ? [{ name, url: links[name] }] : []));
const socialConnections = links.map(({ platform, url }) => ({
name: platform?.toLowerCase(),
url,
}));

return (
<SocialMediaBar
Expand Down
28 changes: 1 addition & 27 deletions apps/codeforafrica/src/components/ConnectBar/ConnectBar.snap.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<ConnectBar /> renders unchanged 1`] = `
<div>
<div
class="MuiStack-root css-150zc89-MuiStack-root"
>
<div
class="MuiStack-root css-1mbd5au-MuiStack-root"
>
<a
aria-label="facebook"
class="MuiTypography-root MuiTypography-inherit MuiLink-root MuiLink-underlineAlways MuiBox-root active css-tmo8yp-MuiTypography-root-MuiLink-root"
data-mui-internal-clone-element="true"
href="https://www.facebook.com/"
rel="noreferrer noopener"
target="_blank"
>
<div
aria-hidden="true"
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-1dz6c5u-MuiSvgIcon-root"
focusable="false"
viewbox="0 0 24 24"
/>
</a>
</div>
</div>
</div>
`;
exports[`<ConnectBar /> renders unchanged 1`] = `<div />`;
89 changes: 89 additions & 0 deletions apps/codeforafrica/src/components/Partner/Partner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { Section } from "@commons-ui/core";
import { Box } from "@mui/material";
import React from "react";

import AboutChildPageHeader from "@/codeforafrica/components/AboutChildPageHeader";
import ConnectBar from "@/codeforafrica/components/ConnectBar";
import RelatedProjects from "@/codeforafrica/components/RelatedProjects";
import RichText from "@/codeforafrica/components/RichText";
import SectionDivider from "@/codeforafrica/components/SectionDivider";

const SinglePartner = React.forwardRef(function SinglePartner(
koechkevin marked this conversation as resolved.
Show resolved Hide resolved
{ description, connect, relatedProjects, relatedProjectsTitle, name, logo },
ref,
) {
return (
<Box ref={ref} sx={{ pb: { xs: 10, md: 7 } }}>
<AboutChildPageHeader
name={name}
image={logo}
FigureProps={{
sx: {
backgroundPositionY: "center",
backgroundRepeat: "no-repeat",
backgroundSize: "contain",
bgcolor: "background.default",
borderRadius: 0,
filter: "drop-shadow(0px 8.7px 17.4px rgba(0, 0, 0, 0.1))",
height: { xs: 116 },
width: { xs: 247 },
},
}}
/>
<Section
sx={{
px: { xs: 2.5, sm: 0 },
pt: { xs: 2.5, md: 7 },
maxWidth: {
sm: "648px",
md: "912px",
},
}}
>
<RichText
variant="subheading"
component="p"
sx={{
mb: 5,
typography: "subheading",
"& > p": {
mb: 5,
},
}}
elements={description}
/>

<ConnectBar title="Connect" links={connect} />
</Section>
{relatedProjects?.length ? (
<>
<SectionDivider
sx={{
maxWidth: {
sm: "648px",
md: "912px",
},
px: { xs: 2.5, sm: 0 },
py: { xs: "30px", md: 5 },
}}
/>
<RelatedProjects
sx={{
maxWidth: {
sm: "648px",
md: "912px",
},
pt: 0,
}}
tileListProps={{ fixed: true }}
titleProps={{ sx: { mb: { xs: "30px", md: 5 } } }}
title={relatedProjectsTitle}
projects={relatedProjects}
/>
</>
) : null}
</Box>
);
});

export default SinglePartner;
koechkevin marked this conversation as resolved.
Show resolved Hide resolved
21 changes: 21 additions & 0 deletions apps/codeforafrica/src/components/Partner/Partner.snap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<Partners /> renders unchanged 1`] = `
<div>
<div
class="MuiBox-root css-1gghq2r"
>
<div
class="MuiContainer-root MuiContainer-maxWidthLg MuiContainer-fixed MuiContainer-disableGutters css-1ilq66o-MuiContainer-root"
>
<div
class="MuiBox-root css-15sqwg8"
>
Lorem ipsum dolor sit amet consectetur adipiscing, elit ac primis praesent
tempor luctus libero, curae condimentum ultricies proin leo. Arcu ornare dis fermentum nisi consequat imperdiet porta viverra placerat nullam, dapibus molestie faucibus id mi lacinia orci magnis. Ridiculus aptent phasellus mus nisi porta rutrum tellus, ut venenatis feugiat massa volutpat.
Duis maecenas per erat odio quisque accumsan, donec tempus class euismod vulputate fermentum imperdiet, suspendisse blandit lacinia semper cursus. Neque tristique posuere a feugiat convallis tempor cras nunc, leo faucibus cum aptent placerat aenean lobortis, nibh iaculis ac nascetur praesent mus quisque. Nullam leo rutrum augue urna cubilia morbi enim, arcu risus mus mauris elementum pulvinar, laoreet bibendum convallis senectus ullamcorper malesuada.
</div>
</div>
</div>
</div>
`;
30 changes: 30 additions & 0 deletions apps/codeforafrica/src/components/Partner/Partner.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { createRender } from "@commons-ui/testing-library";
import React from "react";

import Partner from "./Partner";

import theme from "@/codeforafrica/theme";

// eslint-disable-next-line testing-library/render-result-naming-convention
const render = createRender({ theme });

const defaultProps = {
description: [
{
text: "Lorem ipsum dolor sit amet consectetur adipiscing, elit ac primis praesent",
},
{
text: "tempor luctus libero, curae condimentum ultricies proin leo. Arcu ornare dis fermentum nisi consequat imperdiet porta viverra placerat nullam, dapibus molestie faucibus id mi lacinia orci magnis. Ridiculus aptent phasellus mus nisi porta rutrum tellus, ut venenatis feugiat massa volutpat. ",
},
{
text: "Duis maecenas per erat odio quisque accumsan, donec tempus class euismod vulputate fermentum imperdiet, suspendisse blandit lacinia semper cursus. Neque tristique posuere a feugiat convallis tempor cras nunc, leo faucibus cum aptent placerat aenean lobortis, nibh iaculis ac nascetur praesent mus quisque. Nullam leo rutrum augue urna cubilia morbi enim, arcu risus mus mauris elementum pulvinar, laoreet bibendum convallis senectus ullamcorper malesuada.",
},
],
};

describe("<Partners />", () => {
it("renders unchanged", () => {
const { container } = render(<Partner {...defaultProps} />);
expect(container).toMatchSnapshot();
});
});
3 changes: 3 additions & 0 deletions apps/codeforafrica/src/components/Partner/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Partner from "./Partner";

export default Partner;
10 changes: 7 additions & 3 deletions apps/codeforafrica/src/lib/data/common/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import blockify from "@/codeforafrica/lib/data/blockify";
import pagify from "@/codeforafrica/lib/data/pagify";
import { imageFromMedia } from "@/codeforafrica/lib/data/utils";

function getNavBar(settings) {
Expand Down Expand Up @@ -45,18 +46,21 @@ function getPageSlug({ params }) {
}

export async function getPageProps(api, context) {
const { params } = context;
const slug = getPageSlug(context);
const {
let {
docs: [page],
} = await api.findPage(slug);
if (!page) {
return null;
}

if (params?.slugs?.length > 2) {
page = await pagify(page, api, context);
}
const blocks = await blockify(page?.blocks);
const settings = await api.findGlobal("settings");
const navbar = getNavBar(settings);
const footer = getFooter(settings);
const blocks = await blockify(page.blocks);

return {
blocks,
Expand Down
13 changes: 13 additions & 0 deletions apps/codeforafrica/src/lib/data/pagify/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import partners from "./partners";

const COLLECTION_BY_SLUG = {
partners,
};

async function pagify(parentPage, api, context) {
const { slug: collection } = parentPage;
const pageProps = COLLECTION_BY_SLUG[collection];
koechkevin marked this conversation as resolved.
Show resolved Hide resolved
return pageProps?.(api, context) ?? null;
}

export default pagify;
30 changes: 30 additions & 0 deletions apps/codeforafrica/src/lib/data/pagify/partners.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { imageFromMedia } from "@/codeforafrica/lib/data/utils";

async function partners(api, context) {
const { params, locale } = context;
const slug = params.slugs[2];
const { docs } = await api.getCollection("partners", {
locale,
where: {
slug: {
equals: slug,
},
},
});
if (!docs?.length) {
return null;
}
const [partner] = docs;
return {
blocks: [
{
relatedProjects: [], // TODO(koechkevin) Related projects go here once projects implemented
...partner,
logo: imageFromMedia(partner.logo),
blockType: "partner",
},
],
};
}

export default partners;
2 changes: 2 additions & 0 deletions apps/codeforafrica/src/pages/[...slugs].page.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import MeetOurTeam from "@/codeforafrica/components/MeetOurTeam";
import NewsAndStories from "@/codeforafrica/components/NewsAndStories";
import OurPartners from "@/codeforafrica/components/OurPartners";
import PageHeader from "@/codeforafrica/components/PageHeader";
import Partner from "@/codeforafrica/components/Partner";
import { getPageServerSideProps } from "@/codeforafrica/lib/data";

const componentsBySlugs = {
Expand All @@ -20,6 +21,7 @@ const componentsBySlugs = {
"our-impact": GetInvolved,
"our-partners": OurPartners,
projects: FeaturedProjects,
partner: Partner,
};

function Index({ blocks, fallback }) {
Expand Down
2 changes: 2 additions & 0 deletions apps/codeforafrica/src/payload/blocks/OurPartners.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const Partners = {
slug: "our-partners",
imageURL: "/images/cms/blocks/partners.png",
imageAltText: "Our Partners",
labels: {
singular: {
en: "Partners",
Expand Down