From b7055e160d627f8dd96bccfa29eb18519c6a722c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9za=20Kalfane?= Date: Wed, 15 May 2024 09:30:41 +0200 Subject: [PATCH] feat: cta, blog snippet and blog components --- .../amplience/blog-snippet/blog-snippet.tsx | 95 +++++++++++++++++++ components/amplience/blog/blog.tsx | 36 +++++++ .../call-to-action/call-to-action.tsx | 37 ++++++++ .../amplience/wrapper/amplience-content.tsx | 4 + 4 files changed, 172 insertions(+) create mode 100644 components/amplience/blog-snippet/blog-snippet.tsx create mode 100644 components/amplience/blog/blog.tsx create mode 100644 components/amplience/call-to-action/call-to-action.tsx diff --git a/components/amplience/blog-snippet/blog-snippet.tsx b/components/amplience/blog-snippet/blog-snippet.tsx new file mode 100644 index 0000000..80318d1 --- /dev/null +++ b/components/amplience/blog-snippet/blog-snippet.tsx @@ -0,0 +1,95 @@ +import React from 'react'; +import { AmplienceContentItem } from '~/amplience-client'; +import AmplienceContent from '../wrapper/amplience-content'; +import CallToAction from '../call-to-action/call-to-action'; +import NextHead from 'next/head'; +import { AmplienceImage } from '../image/image.types'; +import { getImageURL } from '../image/image.utils'; + +export type BlogSnippetProps = { + image: AmplienceContentItem; + title: string; + blogdate: string; + author: string; + category: string[]; + description: string; + cta: any; + tags: any[]; + keywords: string; +}; + +const buildCTAUrl = (cta: any) => { + switch (cta.type) { + case 'URL': + return cta.value; + case 'Category ID': + return `/category/${cta.value}`; + case 'Product SKU': + return `/product/${cta.value}`; + case 'Page ID': + return `/${cta.value}`; + default: + return '#'; + } +}; + +const BlogSnippet = ({ + image, + title, + blogdate, + author, + category, + description, + cta, + keywords, +}: BlogSnippetProps) => { + return ( + <> + + {title || 'Amplience Retail Storefront Website'} + + + + + + + + + + + + +
+
+
+ +
+
+
+ +
+ {category?.length ? {category.join(', ')} : null} + {title ?

{title}

: null} +
+ {author ?

{author}

: null} + {blogdate ?

{blogdate}

: null} +
+ + {description ?

{description}

: null} + + {cta ? ( + + {cta?.label} + + ) : null} +
+ + ); +}; + +export default BlogSnippet; diff --git a/components/amplience/blog/blog.tsx b/components/amplience/blog/blog.tsx new file mode 100644 index 0000000..54007fc --- /dev/null +++ b/components/amplience/blog/blog.tsx @@ -0,0 +1,36 @@ +import React from 'react'; +import { AmplienceContentItem } from '~/amplience-client'; +import AmplienceContent from '../wrapper/amplience-content'; + +export interface BlogProps { + snippet: AmplienceContentItem; + contentTypes?: AmplienceContentItem[]; + content: AmplienceContentItem; +} + +const Blog = ({ snippet, content, contentTypes = [] }: BlogProps) => { + const Blog = ( +
+
+ +
+
+ + {contentTypes.map((item: any, index: number) => ( +
+ +
+ ))} +
+
+ ); + + return Blog; +}; + +export default Blog; diff --git a/components/amplience/call-to-action/call-to-action.tsx b/components/amplience/call-to-action/call-to-action.tsx new file mode 100644 index 0000000..6e90059 --- /dev/null +++ b/components/amplience/call-to-action/call-to-action.tsx @@ -0,0 +1,37 @@ +import React, { PropsWithChildren } from 'react'; +import clsx from 'clsx'; +import Link from 'next/link'; + +interface CallToActionProps extends PropsWithChildren { + href: string; + className?: string; + style?: React.CSSProperties; + variant?: 'outlined' | 'contained'; +} + +const CallToAction = ({ + children, + href, + className, + variant = 'outlined', + ...other +}: CallToActionProps) => { + return href ? ( + + {children} + + ) : null; +}; + +export default CallToAction; diff --git a/components/amplience/wrapper/amplience-content.tsx b/components/amplience/wrapper/amplience-content.tsx index be49169..e55b308 100644 --- a/components/amplience/wrapper/amplience-content.tsx +++ b/components/amplience/wrapper/amplience-content.tsx @@ -9,6 +9,8 @@ import Text from '../text/text'; import Card from '../card/card'; import CardList from '../card-list/card-list'; import RichText from '../rich-text/rich-text'; +import Blog from '../blog/blog'; +import BlogSnippet from '../blog-snippet/blog-snippet'; interface ComponentMapType { // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -26,6 +28,8 @@ const COMPONENT_MAPPING: ComponentMapType = { 'https://demostore.amplience.com/content/card': Card, 'https://demostore.amplience.com/content/card-list': CardList, 'https://demostore.amplience.com/content/rich-text': RichText, + 'https://demostore.amplience.com/content/blog': Blog, + 'https://demostore.amplience.com/content/blog-snippet': BlogSnippet, }; const MappingNotFound = (content: AmplienceContentItem) => {