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

feat: turn FAQ answers RichText #253

Merged
merged 3 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "safe-homepage",
"homepage": "https://github.com/safe-global/safe-homepage",
"version": "1.3.4",
"version": "1.3.5",
"scripts": {
"build": "next build && next export",
"lint": "tsc && next lint",
Expand Down
5 changes: 3 additions & 2 deletions src/components/Campaign/Faq/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Image from 'next/image'
import { isEntryTypeFaqEntry } from '@/lib/typeGuards'
import { trackEvent } from '@/services/analytics/trackEvent'
import { SOCIAL_LOGIN_EVENTS } from '@/services/analytics/events/socialLogin'
import RichText from '@/components/Campaign/RichText'

type FaqEntry = Entry<TypeFaqSkeleton, undefined, string>

Expand Down Expand Up @@ -80,8 +81,8 @@ const Faq = (props: FaqEntry) => {
>
<Typography variant="h4">{item.question}</Typography>
</AccordionSummary>
<AccordionDetails>
<Typography>{item.answer}</Typography>
<AccordionDetails className={css.details}>
<RichText {...item.answer} />
</AccordionDetails>
</Accordion>
)
Expand Down
8 changes: 8 additions & 0 deletions src/components/Campaign/Faq/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@
padding: 0 0 32px;
}

.details p {
margin: 0;
}

.details a {
text-decoration: underline;
}

@media (min-width: 900px) {
.bg {
position: absolute;
Expand Down
6 changes: 5 additions & 1 deletion src/components/Campaign/Hero/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
.spot {
position: absolute;
right: -35px;
top: -110px;
top: 410px;
z-index: -1;
width: 800px;
height: 800px;
Expand Down Expand Up @@ -64,6 +64,10 @@
}

@media (min-width: 900px) {
.spot {
top: -110px;
}

.heroFooter {
margin-top: 100px;
flex-direction: row;
Expand Down
19 changes: 16 additions & 3 deletions src/components/Campaign/RichText/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
import { documentToReactComponents } from '@contentful/rich-text-react-renderer'
import type { Document as ContentfulDocument } from '@contentful/rich-text-types'
import { documentToReactComponents, type RenderNode, type Options } from '@contentful/rich-text-react-renderer'
import { INLINES, type Document as ContentfulDocument, type Hyperlink } from '@contentful/rich-text-types'

const options: Options = {
renderNode: {
[INLINES.HYPERLINK]: (node: Hyperlink) => {
const text = node.content.find((item) => item.nodeType === 'text')?.value
return (
<a href={node.data.uri} target="_blank" rel="noreferrer">
{text}
</a>
)
},
} as unknown as RenderNode,
}

const RichText = (props: ContentfulDocument) => {
return <>{documentToReactComponents(props)}</>
return <>{documentToReactComponents(props, options)}</>
}

export default RichText
2 changes: 1 addition & 1 deletion src/contentful/types/TypeFaqEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { ChainModifiers, Entry, EntryFieldTypes, EntrySkeletonType, LocaleC

export interface TypeFaqEntryFields {
question: EntryFieldTypes.Symbol
answer: EntryFieldTypes.Text
answer: EntryFieldTypes.RichText
slug?: EntryFieldTypes.Symbol
}

Expand Down
Loading