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

Project List block #610

Merged
merged 27 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c51b3d0
Implement projects
koechkevin Sep 25, 2023
0673d02
Merge branch 'feature/cfa-team-members' into feature/cfa-projects-list
koechkevin Sep 25, 2023
62e19a5
projects
koechkevin Sep 25, 2023
299f565
Impleent feedback
koechkevin Sep 25, 2023
7afbbbd
fix tests
koechkevin Sep 25, 2023
85034be
Add default columns
koechkevin Sep 26, 2023
dea5c15
Merge branch 'develop' into feature/cfa-projects-list
koechkevin Sep 26, 2023
b842dbf
Tag projects
koechkevin Sep 26, 2023
63c3679
Add projects to SEO
koechkevin Sep 27, 2023
9135b71
Merge branch 'develop' into feature/cfa-projects-list
koechkevin Sep 27, 2023
4a97695
Merge branch 'develop' into feature/cfa-projects-list
koechkevin Sep 27, 2023
b46d3b3
implement feedback
koechkevin Sep 28, 2023
e618f4c
Rearrange
koechkevin Sep 28, 2023
193d145
Use date field
koechkevin Sep 28, 2023
7d3fd27
Add a label for external link
koechkevin Sep 28, 2023
deb3c39
Update Link
koechkevin Sep 28, 2023
39e7f3e
Update Page Header
koechkevin Sep 28, 2023
e7bc3d2
Make Tages unique to only projects
koechkevin Sep 28, 2023
356dba4
Fetch unique tags
koechkevin Sep 28, 2023
44dae1b
Add custom field
koechkevin Sep 29, 2023
10ab7f3
Add icons
koechkevin Sep 29, 2023
9e99a54
Fix icons
koechkevin Sep 29, 2023
6b6d2a4
Update config
koechkevin Sep 29, 2023
da7b8a1
Merge branch 'develop' into feature/cfa-projects-list
koechkevin Sep 29, 2023
7640918
Update Source link
koechkevin Sep 29, 2023
52b5328
Update date format & linkArray fields
kilemensi Sep 29, 2023
e32a1b8
Remove unnecessary labelFields
kilemensi Sep 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion apps/codeforafrica/payload.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import Partners from "./src/payload/collections/Partners";
import Posts from "./src/payload/collections/Posts";
import Settings from "./src/payload/globals/Settings";
import Tags from "./src/payload/collections/Tags";
import Projects from "./src/payload/collections/Projects";
import Donors from "./src/payload/collections/Donors";
import Teams from "./src/payload/collections/Teams";
import { CollectionConfig, GlobalConfig } from "payload/types";
import dotenv from "dotenv";
Expand Down Expand Up @@ -49,12 +51,14 @@ export default buildConfig({
serverURL: appURL,
collections: [
Authors,
Donors,
GuidingPrinciples,
Impact,
Media,
Members,
Pages,
Partners,
Projects,
Posts,
Tags,
Teams,
Expand Down Expand Up @@ -95,7 +99,7 @@ export default buildConfig({
doc?.slug?.value ? `${appURL}/${doc.slug.value}` : undefined,
} as any),
nestedDocs({
collections: ["pages"],
collections: ["pages", "projects"],
koechkevin marked this conversation as resolved.
Show resolved Hide resolved
generateLabel: (_, doc) => doc.title as string,
generateURL: (docs) =>
docs.reduce((url, doc) => `${url}/${doc.slug}`, ""),
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions apps/codeforafrica/src/components/ProjectCard/ProjectCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import React from "react";

import ProjectCardMedia from "@/codeforafrica/components/ProjectCardMedia";
import ProjectTile from "@/codeforafrica/components/ProjectTile";
import RichText from "@/codeforafrica/components/RichText";

const ProjectActionArea = styled(CardActionArea, {
slot: "Root",
Expand All @@ -31,7 +32,7 @@ const ProjectActionArea = styled(CardActionArea, {
const ProjectCard = React.forwardRef(function ProjectCard(props, ref) {
const {
externalHref,
href,
link: { href },
icon,
name,
subtitle,
Expand All @@ -47,7 +48,7 @@ const ProjectCard = React.forwardRef(function ProjectCard(props, ref) {
const tileProps = { icon, name, tagLine };

return (
<Card elevation={0} square ref={ref} ownerState={ownerState} {...other}>
<Card elevation={0} square ref={ref} ownerState={ownerState}>
<ProjectActionArea component={href ? Link : undefined} href={href}>
<ProjectCardMedia {...thumbnail} component="img" />
<Box
Expand All @@ -73,12 +74,11 @@ const ProjectCard = React.forwardRef(function ProjectCard(props, ref) {
>
{title}
</RichTypography>
<RichTypography
<RichText
variant="body1"
sx={{ mt: 2.5, typography: { md: "body2" } }}
>
{subtitle}
</RichTypography>
elements={subtitle}
/>
</CardContent>
<CardActions sx={{ mt: 2, p: 0 }}>
<Button component="div" variant="contained-reverse" sx={{ py: 1 }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import theme from "@/codeforafrica/theme";
// eslint-disable-next-line testing-library/render-result-naming-convention
const render = createRender({ theme });

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

describe("<ProjectCard />", () => {
it("renders unchanged", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ const ProjectCardMediaRoot = styled(CardMedia, {
},
}));

const ProjectCardMedia = React.forwardRef(
function ProjectCardMedia(props, ref) {
return <ProjectCardMediaRoot component="img" {...props} ref={ref} />;
},
);
const ProjectCardMedia = React.forwardRef(function ProjectCardMedia(
{ src, alt },
ref,
) {
return <ProjectCardMediaRoot component="img" src={src} alt={alt} ref={ref} />;
});

export default ProjectCardMedia;
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ exports[`<ProjectPageHeader /> renders unchanged 1`] = `
</ol>
</nav>
<img
class="MuiCardMedia-root MuiCardMedia-media MuiCardMedia-img css-vpxcaz-MuiCardMedia-root"
class="MuiCardMedia-root MuiCardMedia-media MuiCardMedia-img css-tm1rxb-MuiCardMedia-root"
/>
<div
class="MuiBox-root css-1ntmuzk"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const ProjectTile = React.forwardRef(function ProjectTile(props, ref) {
<>
{icon?.src?.length > 0 ? (
<Figure
ImageProps={{ alt: name, ...icon }}
ImageProps={{ alt: icon.alt, src: icon.src }}
sx={{ height: "70px", width: "70px" }}
/>
) : null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ exports[`<ProjectTile /> renders unchanged 1`] = `
class="MuiBox-root css-f1ltsh"
>
<img
alt="africanDRONE"
class="css-g98gbd"
data-nimg="fill"
decoding="async"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ exports[`<ProjectTileList /> renders unchanged 1`] = `
class="MuiBox-root css-f1ltsh"
>
<img
alt="africanDRONE"
class="css-g98gbd"
data-nimg="fill"
decoding="async"
Expand Down
12 changes: 6 additions & 6 deletions apps/codeforafrica/src/components/Projects/Projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ import equalsIgnoreCase from "@/codeforafrica/utils/equalsIgnoreCase";
const Projects = React.forwardRef(function Projects(
{
tags,
projects: {
pagination: { count: countProp, page: pageProp = 1 },
results: resultsProp,
},
pagination: { count: countProp, page: pageProp = 1 },
results: resultsProp,
sx,
},
ref,
Expand Down Expand Up @@ -57,7 +55,9 @@ const Projects = React.forwardRef(function Projects(
}, [data]);

useEffect(() => {
router.push(queryParams, undefined, {
const [pathname] = router.asPath.split("?");
koechkevin marked this conversation as resolved.
Show resolved Hide resolved
const url = pathname ? `${pathname}${queryParams}` : queryParams;
koechkevin marked this conversation as resolved.
Show resolved Hide resolved
router.push(url, undefined, {
scroll: true,
shallow: true,
});
Expand All @@ -84,7 +84,7 @@ const Projects = React.forwardRef(function Projects(
{projects?.length > 0 ? (
<Stack direction="column" spacing={{ xs: 5, md: 7.5 }}>
{projects.map((project) => (
<ProjectCard {...project} key={project.slug} />
<ProjectCard {...project} key={project.id} />
koechkevin marked this conversation as resolved.
Show resolved Hide resolved
))}
</Stack>
) : null}
Expand Down
3 changes: 2 additions & 1 deletion apps/codeforafrica/src/components/Projects/Projects.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 = {
projects: { pagination: {}, results: [] },
pagination: {},
results: [],
};

describe("<Projects />", () => {
Expand Down
2 changes: 1 addition & 1 deletion apps/codeforafrica/src/components/Projects/useProjects.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 useProjects(query) {
const queryParams = useFilterQuery(query);
const { data, error } = useSWR(`/api/projects${queryParams}`, fetcher);
const { data, error } = useSWR(`/api/v1/projects${queryParams}`, fetcher);

return {
data,
Expand Down
2 changes: 2 additions & 0 deletions apps/codeforafrica/src/lib/data/blockify/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import hero from "./hero";
import meetOurTeam from "./meetOurTeam";
import ourImpact from "./our-impact";
import ourTeam from "./ourTeam";
import ourWork from "./ourWork";
import stories from "./stories";

const propsifyBlockBySlug = {
Expand All @@ -12,6 +13,7 @@ const propsifyBlockBySlug = {
"our-impact": ourImpact,
stories,
"our-team": ourTeam,
"our-work": ourWork,
};

async function blockify(blocks, api, context) {
Expand Down
17 changes: 17 additions & 0 deletions apps/codeforafrica/src/lib/data/blockify/ourWork.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { getProjects } from "@/codeforafrica/lib/data/utils/projects";

async function ourWork(block, api, context) {
const { query } = context;
const data = await getProjects(api, query);
const { docs } = await api.getCollection("tag");
const tags = docs.map(({ name }) => name);

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

export default ourWork;
37 changes: 37 additions & 0 deletions apps/codeforafrica/src/lib/data/utils/projects.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
function getQuery(fields, query) {
const { q, tag } = query;
const whereQuery = {
or: q ? fields.map((field) => ({ [field]: { like: q } })) : [],
};
if (tag) {
whereQuery["tag.name"] = {
like: tag,
};
}
return whereQuery;
}

export async function getProjects(api, params) {
const { page: queryPage = 1 } = params;
const fields = ["name", "title", "tag.name", "tagLine"];
const options = {
limit: 6,
page: queryPage,
where: getQuery(fields, params),
};
const {
docs: results,
totalPages,
page,
} = await api.getCollection("projects", options);

return {
results,
pagination: {
count: totalPages,
page,
},
};
}

export default undefined;
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 @@ -17,6 +17,7 @@ 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 Projects from "@/codeforafrica/components/Projects";
import { getPageServerSideProps } from "@/codeforafrica/lib/data";

const componentsBySlugs = {
Expand All @@ -35,6 +36,7 @@ const componentsBySlugs = {
"our-partners": OurPartners,
"page-header": PageHeader,
"our-team": OurTeam,
"our-work": Projects,
projects: FeaturedProjects,
};

Expand Down
11 changes: 11 additions & 0 deletions apps/codeforafrica/src/pages/api/v1/projects.page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { getProjects } from "@/codeforafrica/lib/data/utils/projects";
import api from "@/codeforafrica/lib/payload";

export default async function handler(req, res) {
try {
const data = await getProjects(api, req.query);
return res.json(data);
} catch (error) {
return res.status(500).json(error);
}
}
24 changes: 24 additions & 0 deletions apps/codeforafrica/src/payload/blocks/OurWork.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const OurWork = {
slug: "our-work",
imageURL: "/images/cms/blocks/projects.png",
imageAltText: "Our Work",
labels: {
singular: {
en: "Our Work",
},
plural: {
en: "Our Work",
},
},
fields: [
{
name: "title",
label: {
en: "Title",
},
type: "text",
},
],
};

export default OurWork;
37 changes: 37 additions & 0 deletions apps/codeforafrica/src/payload/collections/Donors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import image from "../fields/image";
import slug from "../fields/slug";

const Donors = {
slug: "donors",
labels: {
singular: {
en: "Donor",
},
plural: {
en: "Donors",
},
},
admin: {
useAsTitle: "name",
defaultColumns: ["name", "logo"],
},
fields: [
{
name: "name",
label: {
en: "Name",
},
type: "text",
required: true,
},
slug({ fieldToUse: "name" }),
image({
overrides: {
name: "logo",
required: true,
},
}),
],
};

export default Donors;
2 changes: 2 additions & 0 deletions apps/codeforafrica/src/payload/collections/Pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import MeetOurTeam from "../blocks/MeetOurTeam";
import OurImpact from "../blocks/OurImpact";
import OurPartners from "../blocks/OurPartners";
import OurTeam from "../blocks/OurTeam";
import OurWork from "../blocks/OurWork";
import PageHeader from "../blocks/PageHeader";
import Stories from "../blocks/Stories";
import fullTitle from "../fields/fullTitle";
Expand Down Expand Up @@ -60,6 +61,7 @@ const Pages = {
OurImpact,
OurPartners,
OurTeam,
OurWork,
Stories,
],
admin: {
Expand Down
Loading