Skip to content

Commit

Permalink
Merge branch 'feature/cfa-team-members' into feature/cfa-projects-list
Browse files Browse the repository at this point in the history
  • Loading branch information
koechkevin committed Sep 25, 2023
2 parents c51b3d0 + 6790779 commit 0673d02
Show file tree
Hide file tree
Showing 18 changed files with 2,223 additions and 15 deletions.
14 changes: 14 additions & 0 deletions apps/codeforafrica/payload.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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";
Expand All @@ -23,6 +24,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 @@ -41,6 +52,7 @@ export default buildConfig({
Donors,
GuidingPrinciples,
Impact,
Members,
Pages,
Media,
Partners,
Expand All @@ -63,6 +75,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 },
} = props;

return (
<TeamMemberCardRoot elevation={0} square ref={ref}>
<CardActionArea component={href ? Link : undefined} href={href}>
<>
<TeamMemberCardMedia {...thumbnail} component="img" />
<TeamMemberCardMedia 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.id}>
<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
24 changes: 24 additions & 0 deletions apps/codeforafrica/src/lib/data/blockify/ourTeam.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { getMembers } from "@/codeforafrica/lib/data/utils/members";

async function ourTeam(block, api, context) {
const { query } = context;
const data = await getMembers(api, query);
const { docs = [] } = await api.getCollection("members");
const tags = block?.fields.map((field) => {
const uniqueTags =
[...new Set(docs.map((item) => item[field]).filter(Boolean))] ?? [];
return {
field: `${field.charAt(0).toUpperCase()}${field.slice(1)}`,
tags: uniqueTags,
};
});

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 0673d02

Please sign in to comment.