Skip to content

Commit

Permalink
add generic cta component
Browse files Browse the repository at this point in the history
  • Loading branch information
saml33 committed Feb 2, 2024
1 parent f9ced7f commit e11f509
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 5 deletions.
57 changes: 57 additions & 0 deletions app/components/rich-text/CallToAction.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import Image from 'next/image'
import ButtonLink from '../shared/ButtonLink'

type Image = {
fields: {
title?: string
file: {
url: string
}
}
}

type CtaData = {
title: string
description?: string
linkPath: string
linkText: string
image?: Image | null
}

const CallToAction = ({ data }: { data: CtaData }) => {
const { linkPath, linkText, description, image, title } = data
const imageSrc = image?.fields?.file?.url
const imageAlt = image?.fields?.title || 'CTA Image'
const isExtenalLink = linkPath.includes('http')
return (
<span className="bg-th-bkg-1 border border-th-bkg-4 p-4 md:px-6 rounded-lg flex flex-col md:flex-row md:items-center md:justify-between my-4">
<span className="flex items-center space-x-3">
{imageSrc ? (
<Image
className="flex-shrink-0"
src={`https:${imageSrc}`}
alt={imageAlt}
height={56}
width={56}
/>
) : null}
<span>
<span className="text-th-fgd-2 text-base block font-display">
{title}
</span>
<span className="text-sm block text-th-fgd-2">{description}</span>
</span>
</span>
<span className="flex space-x-2 md:pl-4 pt-4 md:pt-0">
<ButtonLink
linkText={linkText}
path={linkPath}
size="small"
target={isExtenalLink ? '_blank' : undefined}
/>
</span>
</span>
)
}

export default CallToAction
4 changes: 4 additions & 0 deletions app/components/rich-text/RichText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { documentToReactComponents } from '@contentful/rich-text-react-renderer'
import Link from 'next/link'
import TokenCallToAction from './TokenCallToAction'
import { formatNumericValue } from '../../utils/numbers'
import CallToAction from './CallToAction'

type RichTextProps = {
document: RichTextDocument | undefined
Expand Down Expand Up @@ -94,6 +95,9 @@ function RichText({ document, currentPrice }: RichTextProps) {
if (node.data.target.sys.contentType.sys.id === 'tokenCallToAction') {
return <TokenCallToAction data={node.data.target.fields} />
}
if (node.data.target.sys.contentType.sys.id === 'callToAction') {
return <CallToAction data={node.data.target.fields} />
}
if (node.data.target.sys.contentType.sys.id === 'inlineTextPrice') {
const priceType = node.data.target.fields.priceType
if (priceType === 'Current price') {
Expand Down
2 changes: 1 addition & 1 deletion contentful/types/TypeBlogPost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface TypeBlogPostFields {
postTitle: EntryFieldTypes.Symbol
slug: EntryFieldTypes.Symbol
author?: EntryFieldTypes.Symbol
category: EntryFieldTypes.Symbol<'Meme Coins' | 'Repost'>
category: EntryFieldTypes.Symbol<'Markets' | 'Meme Coins' | 'Repost'>
authorProfileImage?: EntryFieldTypes.AssetLink
postDescription: EntryFieldTypes.Text
postContent: EntryFieldTypes.RichText
Expand Down
24 changes: 24 additions & 0 deletions contentful/types/TypeCallToAction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type {
ChainModifiers,
Entry,
EntryFieldTypes,
EntrySkeletonType,
LocaleCode,
} from 'contentful'

export interface TypeCallToActionFields {
title: EntryFieldTypes.Symbol
description?: EntryFieldTypes.Symbol
linkPath: EntryFieldTypes.Symbol
linkText: EntryFieldTypes.Symbol
image?: EntryFieldTypes.AssetLink
}

export type TypeCallToActionSkeleton = EntrySkeletonType<
TypeCallToActionFields,
'callToAction'
>
export type TypeCallToAction<
Modifiers extends ChainModifiers,
Locales extends LocaleCode,
> = Entry<TypeCallToActionSkeleton, Modifiers, Locales>
2 changes: 1 addition & 1 deletion contentful/types/TypeLearnPost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface TypeLearnPostFields {
postTitle: EntryFieldTypes.Symbol
slug: EntryFieldTypes.Symbol
author?: EntryFieldTypes.Symbol
category: EntryFieldTypes.Symbol<'Repost'>
category: EntryFieldTypes.Symbol<'Repost' | 'Spot Trading'>
authorProfileImage?: EntryFieldTypes.AssetLink
postDescription: EntryFieldTypes.Text
postContent: EntryFieldTypes.RichText
Expand Down
7 changes: 5 additions & 2 deletions contentful/types/TypeNewsArticle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,26 @@ export interface TypeNewsArticleFields {
| 'DeFi'
| 'DePIN'
| 'Derivatives'
| 'Domains'
| 'ELON'
| 'ETH (Portal)'
| 'EURC'
| 'Exchange'
| 'GECKO'
| 'GUAC'
| 'Gaming'
| 'Governance'
| 'HNT'
| 'Infrastructure'
| 'JLP'
| 'JTO'
| 'JUP'
| 'JitoSOL'
| 'KIN'
| 'LDO'
| 'Layer 1'
| 'Liquid Staking'
| 'MNGO'
| 'MOUTAI'
| 'Meme'
| 'NEON'
| 'NOS'
Expand All @@ -55,7 +59,6 @@ export interface TypeNewsArticleFields {
| 'SAMO'
| 'SLCL'
| 'SOL'
| 'Social'
| 'Stablecoin'
| 'TBTC'
| 'USDC'
Expand Down
1 change: 1 addition & 0 deletions contentful/types/TypeToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface TypeTokenFields {
| 'Exchange'
| 'Gaming'
| 'Governance'
| 'Infrastructure'
| 'Layer 1'
| 'Liquid Staking'
| 'Meme'
Expand Down
5 changes: 5 additions & 0 deletions contentful/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ export type {
TypeBlogPostFields,
TypeBlogPostSkeleton,
} from './TypeBlogPost'
export type {
TypeCallToAction,
TypeCallToActionFields,
TypeCallToActionSkeleton,
} from './TypeCallToAction'
export type {
TypeInlineTextPrice,
TypeInlineTextPriceFields,
Expand Down
4 changes: 4 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ const nextConfig = {
protocol: 'https',
hostname: 'img.fotofolio.xyz/**',
},
{
protocol: 'https',
hostname: 'images.ctfassets.net/**',
},
],
},
reactStrictMode: true,
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.tsbuildinfo

Large diffs are not rendered by default.

0 comments on commit e11f509

Please sign in to comment.