Skip to content

Commit

Permalink
Merge pull request #607 from CodeForAfrica/feature/cfa-team-members
Browse files Browse the repository at this point in the history
Members Collection and our team block
  • Loading branch information
koechkevin authored Sep 26, 2023
2 parents ae67064 + 879f35d commit 55bfcfc
Show file tree
Hide file tree
Showing 19 changed files with 2,262 additions and 15 deletions.
16 changes: 16 additions & 0 deletions apps/codeforafrica/payload.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import Authors from "./src/payload/collections/Authors";
import GuidingPrinciples from "./src/payload/collections/GuidingPrinciples";
import Impact from "./src/payload/collections/Impact";
import Media from "./src/payload/collections/Media";
import Members from "./src/payload/collections/Members";
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 Teams from "./src/payload/collections/Teams";
import { CollectionConfig, GlobalConfig } from "payload/types";
import dotenv from "dotenv";
import seo from "@payloadcms/plugin-seo";
Expand All @@ -21,6 +23,16 @@ dotenv.config({ path: "./.env.local" });

const appURL = process?.env?.PAYLOAD_PUBLIC_APP_URL;

const cors =
process?.env?.PAYLOAD_CORS?.split(",")
?.map((d) => d.trim())
?.filter(Boolean) ?? [];

const csrf =
process?.env?.PAYLOAD_CSRF?.split(",")
?.map((d) => d.trim())
?.filter(Boolean) ?? [];

const adapter = s3Adapter({
config: {
region: process?.env?.S3_REGION,
Expand All @@ -38,10 +50,12 @@ export default buildConfig({
Authors,
GuidingPrinciples,
Impact,
Members,
Pages,
Media,
Partners,
Tags,
Teams,
] as CollectionConfig[],
globals: [Settings] as GlobalConfig[],
admin: {
Expand All @@ -59,6 +73,8 @@ export default buildConfig({
},
}),
},
cors,
csrf,
plugins: [
cloudStorage({
collections: {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 4 additions & 6 deletions apps/codeforafrica/src/components/OurTeam/OurTeam.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@ function getTags(tagsByFields, field) {

const OurTeam = React.forwardRef(function OurTeam(
{
pathname,
sx,
tags: tagsByFields = [],
team: {
pagination: { count: countProp, page: pageProp },
results: resultsProp,
},
pagination: { count: countProp, page: pageProp },
results: resultsProp,
title,
},
ref,
Expand Down Expand Up @@ -79,12 +76,13 @@ const OurTeam = React.forwardRef(function OurTeam(
useEffect(() => {
if (data) {
const { results, pagination } = data;
setCount(pagination.count);
setCount(pagination?.count);
setMembers([...results]);
}
}, [data]);

useEffect(() => {
const [pathname] = router.asPath.split("?");
const url = pathname ? `${pathname}${queryParams}` : queryParams;
router.push(url, undefined, {
shallow: true,
Expand Down
3 changes: 2 additions & 1 deletion apps/codeforafrica/src/components/OurTeam/OurTeam.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import theme from "@/codeforafrica/theme";
const render = createRender({ theme });

const defaultProps = {
team: { pagination: {}, results: [] },
pagination: {},
results: [],
title: "Our team",
};

Expand Down
2 changes: 1 addition & 1 deletion apps/codeforafrica/src/components/OurTeam/useMembers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const fetcher = (url) => fetch(url).then((res) => res.json());

function useMembers(query) {
const queryParams = useFilterQuery(query);
const { data, error } = useSWR(`/api/members${queryParams}`, fetcher);
const { data, error } = useSWR(`/api/v1/members${queryParams}`, fetcher);

return {
data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@ const TeamMemberCardMedia = styled(CardMedia, {
});

const TeamMemberCard = React.forwardRef(function TeamMemberCard(props, ref) {
const { href, name, title, thumbnail } = props;
const {
link: { href },
name,
title,
image: { src, alt },
} = props;

return (
<TeamMemberCardRoot elevation={0} square ref={ref}>
<CardActionArea component={href ? Link : undefined} href={href}>
<>
<TeamMemberCardMedia {...thumbnail} component="img" />
<TeamMemberCardMedia alt={alt} src={src} component="img" />
<CardContent
sx={{
p: "10px",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import theme from "@/codeforafrica/theme";
// eslint-disable-next-line testing-library/render-result-naming-convention
const render = createRender({ theme });

const defaultProps = {};
const defaultProps = {
link: {},
image: {},
};

describe("<TeamMemberCard />", () => {
it("renders unchanged", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const TeamMemberCardList = React.forwardRef(
}}
>
{team?.map((member) => (
<Grid item key={member.href}>
<Grid item key={member.slug}>
<TeamMemberCard {...member} />
</Grid>
))}
Expand Down
6 changes: 4 additions & 2 deletions apps/codeforafrica/src/lib/data/blockify/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@ import getInvolved from "./get-involved";
import hero from "./hero";
import meetOurTeam from "./meetOurTeam";
import ourImpact from "./our-impact";
import ourTeam from "./ourTeam";

const propsifyBlockBySlug = {
hero,
"meet-our-team": meetOurTeam,
"our-impact": ourImpact,
"get-involved": getInvolved,
"our-team": ourTeam,
};

async function blockify(blocks) {
async function blockify(blocks, api, context) {
const promises = blocks?.map(async (block) => {
const slug = block.blockType;
const propsifyBlock = propsifyBlockBySlug[slug];

if (propsifyBlock) {
return propsifyBlock(block);
return propsifyBlock(block, api, context);
}
return {
...block,
Expand Down
39 changes: 39 additions & 0 deletions apps/codeforafrica/src/lib/data/blockify/ourTeam.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { getMembers } from "@/codeforafrica/lib/data/utils/members";

async function getTags(fields, docs) {
return fields.map((field) => {
if (field === "team") {
return {
field: "Team",
tags:
[
"All",
...new Set(docs.map((item) => item[field].name).filter(Boolean)),
] ?? [],
};
}
const uniqueTags =
["All", ...new Set(docs.map((item) => item[field]).filter(Boolean))] ??
[];
return {
field: `${field.charAt(0).toUpperCase()}${field.slice(1)}`,
tags: uniqueTags,
};
});
}

async function ourTeam(block, api, context) {
const { query } = context;
const data = await getMembers(api, query);
const { docs = [] } = await api.getCollection("members");
const tags = await getTags(block?.fields, docs);

return {
...block,
...data,
slug: block.blockType,
tags,
};
}

export default ourTeam;
2 changes: 1 addition & 1 deletion apps/codeforafrica/src/lib/data/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export async function getPageProps(api, context) {
if (params?.slugs?.length > 2) {
page = await pagify(page, api, context);
}
const blocks = await blockify(page?.blocks);
const blocks = await blockify(page?.blocks, api, context);
const settings = await api.findGlobal("settings");
const navbar = getNavBar(settings);
const footer = getFooter(settings);
Expand Down
Loading

0 comments on commit 55bfcfc

Please sign in to comment.