Skip to content

Commit

Permalink
feat: turn FAQ answers RichText (#253)
Browse files Browse the repository at this point in the history
* feat: turn FAQ answers in RichText

* fix: add target="_blank" to RichText links

* bump version
  • Loading branch information
DiogoSoaress authored Nov 23, 2023
1 parent b855a97 commit 6d5cf81
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 8 deletions.
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

0 comments on commit 6d5cf81

Please sign in to comment.