Skip to content

Commit

Permalink
[B2BP-1059] [B2BP-1060] Add Press Releases (#509)
Browse files Browse the repository at this point in the history
* Add Press Releases

* Make PressRelease body required

* Update obsolete comments

---------

Co-authored-by: Simone Salsi <[email protected]>
  • Loading branch information
simosalsi and Simone Salsi authored Nov 29, 2024
1 parent b27b5de commit eece8ca
Show file tree
Hide file tree
Showing 27 changed files with 806 additions and 37 deletions.
5 changes: 5 additions & 0 deletions .changeset/mighty-feet-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"strapi-cms": minor
---

Add PressRelease CollectionType and Section
5 changes: 5 additions & 0 deletions .changeset/red-nails-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"nextjs-website": minor
---

Add PressRelease component and fetch related Strapi CollectionType as pages
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ const PreFooter = (props: PreFooterProps) => {
excludeSlugs,
} = props;
const pathname = usePathname();
// Don't show PreFooter for any press release
if (pathname.includes('press-releases')) {
return null;
}

// Compare excluded slugs with current page slug (removing initial '/')
if (excludeSlugs && excludeSlugs.includes(pathname.slice(1))) {
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import React from 'react';
import { Box, Typography, Container, useTheme } from '@mui/material';
import {
TextColor,
BackgroundColor,
ExtraTextColor,
} from '../common/Common.helpers';
import { PressReleaseProps } from '@react-components/types';

const PressRelease = (props: PressReleaseProps) => {
const { date, title, subtitle, body, sectionID } = props;
const textColor = TextColor('light');
const eyeletColor = ExtraTextColor('light');
const backgroundColor = BackgroundColor('light');
const { palette } = useTheme();

return (
<Box
component="section"
{...(sectionID && { id: sectionID })}
sx={{
width: '100%',
bgcolor: backgroundColor,
color: textColor,
py: 10,
px: 2,
}}
>
<Container
sx={{
width: { xs: '100%', md: '60%' },
mx: 'auto',
ml: { xs: 'auto', md: 16 },
mr: { xs: 'auto' },
}}
>
<Typography
variant="overline"
component="div"
sx={{
color: eyeletColor,
fontSize: { xs: '16px', md: '16px' },
fontWeight: 400,
}}
>
{date}
</Typography>
<Typography
variant="h4"
component="h2"
sx={{ fontSize: { xs: '32px', md: '38px' }, color: textColor }}
>
{title}
</Typography>
{subtitle && (
<Typography
variant="h6"
component="h3"
sx={{
fontSize: { xs: '22px', md: '24px' },
mt: 2,
color: textColor,
}}
>
{subtitle}
</Typography>
)}
<Typography
component="div"
variant="body1"
sx={{
fontSize: { xs: '14px', md: '16px' },
mt: 1,
color: textColor,
'& a': {
color: palette.primary.main,
textDecoration: 'underline',
'&:hover': {
color: palette.primary.main,
textDecoration: 'underline',
},
},
}}
>
{body}
</Typography>
</Container>
</Box>
);
};

export default PressRelease;
2 changes: 2 additions & 0 deletions apps/nextjs-website/react-components/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import RowText from './RowText/RowText';
import TextSection from './TextSection/TextSection';
import PageSwitch from './Page-Switch/Page-Switch';
import FramedVideo from './FramedVideo/FramedVideo';
import PressRelease from './PressRelease/PressRelease';

export {
Hero,
Expand Down Expand Up @@ -52,4 +53,5 @@ export {
TextSection,
PageSwitch,
FramedVideo,
PressRelease,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface PressReleaseProps {
title: string;
subtitle?: string;
body: JSX.Element;
sectionID: string | null;
date: string;
}
2 changes: 2 additions & 0 deletions apps/nextjs-website/react-components/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { RowTextProps } from './RowText/RowText.types';
import { TextSectionProps } from './TextSection/TextSection.types';
import { PageSwitchProps } from './Page-Switch/Page-Switch.types';
import { FramedVideoProps } from './FramedVideo/FramedVideo.types';
import { PressReleaseProps } from './PressRelease/PressRelease.types';

export type {
HeroProps,
Expand Down Expand Up @@ -52,4 +53,5 @@ export type {
TextSectionProps,
PageSwitchProps,
FramedVideoProps,
PressReleaseProps,
};
4 changes: 2 additions & 2 deletions apps/nextjs-website/src/app/[[...slug]]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ export const generateStaticParams = async (): Promise<
const pages_it: Array<LayoutProps['params']> = locales.it
? (await getAllPages('it')).map((page) => ({
// Prepend locale as the first level slug (unless it's the default locale)
slug: defaultLocale === 'it' ? [page.slug] : ['it', page.slug],
slug: defaultLocale === 'it' ? [...page.slug] : ['it', ...page.slug],
}))
: [];
const pages_en: Array<LayoutProps['params']> = locales.en
? (await getAllPages('en')).map((page) => ({
// Prepend locale as the first level slug (unless it's the default locale)
slug: defaultLocale === 'en' ? [page.slug] : ['en', page.slug],
slug: defaultLocale === 'en' ? [...page.slug] : ['en', ...page.slug],
}))
: [];

Expand Down
16 changes: 10 additions & 6 deletions apps/nextjs-website/src/app/[[...slug]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ export const generateStaticParams = async (): Promise<
const pages_it: Array<PageParams['params']> = locales.it
? (await getAllPages('it')).map((page) => ({
// Prepend locale as the first level slug (unless it's the default locale)
slug: defaultLocale === 'it' ? [page.slug] : ['it', page.slug],
slug: defaultLocale === 'it' ? [...page.slug] : ['it', ...page.slug],
}))
: [];
const pages_en: Array<PageParams['params']> = locales.en
? (await getAllPages('en')).map((page) => ({
// Prepend locale as the first level slug (unless it's the default locale)
slug: defaultLocale === 'en' ? [page.slug] : ['en', page.slug],
slug: defaultLocale === 'en' ? [...page.slug] : ['en', ...page.slug],
}))
: [];

Expand All @@ -58,11 +58,13 @@ export async function generateMetadata({
// Check if slug is undefined, which happens for the default locale's homepage due to generateStaticParams' internal logic
// If it is, set the slug back to '' and locale to the default locale

// The slug will be found in slug[0] for the default locale and slug[1] for all others
// Remove locale from slug (if present) and convert to string
const slugString =
slug === undefined
? ''
: (slug[0] === 'it' || slug[0] === 'en' ? slug[1] : slug[0]) ?? '';
: slug[0] === 'it' || slug[0] === 'en'
? slug.slice(1).toString()
: slug.toString();

// The locale will NOT be found for the default locale and will be in slug[0] for all others
const locale =
Expand Down Expand Up @@ -113,11 +115,13 @@ const Page = async ({ params }: PageParams) => {
// Check if slug is undefined, which happens for the default locale's homepage due to generateStaticParams' internal logic
// If it is, set the slug back to '' and locale to the default locale

// The slug will be found in slug[0] for the default locale and slug[1] for all others
// Remove locale from slug (if present) and convert to string
const slugString =
slug === undefined
? ''
: (slug[0] === 'it' || slug[0] === 'en' ? slug[1] : slug[0]) ?? '';
: slug[0] === 'it' || slug[0] === 'en'
? slug.slice(1).toString()
: slug.toString();

// The locale will NOT be found for the default locale and will be in slug[0] for all others
const locale =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import RowText from '../RowText';
import TextSection from '../TextSection';
import PageSwitch from '../PageSwitch';
import FramedVideo from '../FramedVideo';
import PressRelease from '../PressRelease';
import { PageSection as PageSectionData } from '@/lib/fetch/types/PageSection';
import { SiteWidePageData } from '@/lib/fetch/siteWideSEO';

Expand Down Expand Up @@ -72,6 +73,8 @@ const PageSection = (props: PageSectionData & SiteWidePageData) => {
return <PageSwitch {...props} />;
case 'sections.framed-video':
return <FramedVideo {...props} />;
case 'sections.press-release':
return <PressRelease {...props} />;
default:
return null;
}
Expand Down
25 changes: 25 additions & 0 deletions apps/nextjs-website/src/components/PressRelease.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use client';
import MarkdownRenderer from './MarkdownRenderer';
import { SiteWidePageData } from '@/lib/fetch/siteWideSEO';
import { PressReleaseSection } from '@/lib/fetch/types/PageSection';
import { PressRelease as PressReleaseRC } from '@react-components/components';
import { PressReleaseProps } from '@react-components/types';

const makeTextSectionProps = ({
locale,
defaultLocale,
subtitle,
body,
...rest
}: PressReleaseSection &
Omit<SiteWidePageData, 'themeVariant'>): PressReleaseProps => ({
...(subtitle && { subtitle }),
body: MarkdownRenderer({ markdown: body, locale, defaultLocale }),
...rest,
});

const PressRelease = (
props: PressReleaseSection & Omit<SiteWidePageData, 'themeVariant'>
) => <PressReleaseRC {...makeTextSectionProps(props)} />;

export default PressRelease;
89 changes: 89 additions & 0 deletions apps/nextjs-website/src/lib/__tests__/navigation.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { describe, it, expect } from 'vitest';
import { navigationToPageDataArray, PageData } from '../navigation';
import { Navigation } from '../fetch/navigation';

const navigation: Navigation = {
data: [
{
id: 1,
attributes: {
slug: 'homepage',
seo: {
metaTitle: 'title',
metaDescription: 'description',
keywords: null,
canonicalURL: null,
ogTitle: null,
ogDescription: null,
structuredData: null,
},
sections: [
{
__component: 'sections.stripe-link',
theme: 'dark',
subtitle: 'subtitle',
icon: {
data: null,
},
link: {
label: 'link',
href: '/',
},
sectionID: null,
},
],
},
},
{
id: 2,
attributes: {
slug: 'other-page',
seo: {
metaTitle: 'title',
metaDescription: 'description',
keywords: null,
canonicalURL: null,
ogTitle: null,
ogDescription: null,
structuredData: null,
},
sections: [
{
__component: 'sections.stripe-link',
theme: 'dark',
subtitle: 'subtitle',
icon: {
data: null,
},
link: {
label: 'link',
href: '/',
},
sectionID: null,
},
],
},
},
],
};

describe('navigationToPageDataArray', () => {
it('should replace homepage slug with an empty string', () => {
const actual = navigationToPageDataArray(navigation);
const expected: ReadonlyArray<PageData> = [
{
seo: navigation.data[0]!.attributes.seo,
sections: navigation.data[0]!.attributes.sections,
slug: [''],
},
{
seo: navigation.data[1]!.attributes.seo,
sections: navigation.data[1]!.attributes.sections,
slug: ['other-page'],
},
];

expect(actual).toStrictEqual(expected);
});
});
Loading

0 comments on commit eece8ca

Please sign in to comment.