Skip to content

Commit

Permalink
add Testimonials FE components
Browse files Browse the repository at this point in the history
  • Loading branch information
radoslavzeman committed Mar 27, 2024
1 parent 2c6ea48 commit ebec9b4
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 2 deletions.
77 changes: 75 additions & 2 deletions next/backend/graphql/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9012,7 +9012,18 @@ export type PageBySlugQuery = {
text?: string | null
}
| { __typename: 'ComponentSectionsSpace' }
| { __typename: 'ComponentSectionsTestimonials' }
| {
__typename: 'ComponentSectionsTestimonials'
title?: string | null
text?: string | null
hasBackground?: boolean | null
testimonials: Array<{
__typename?: 'ComponentBlocksTestimonialItem'
id: string
name: string
quote: string
} | null>
}
| {
__typename: 'ComponentSectionsTextWithImage'
hasBackground?: boolean | null
Expand Down Expand Up @@ -10151,7 +10162,18 @@ export type PageEntityFragment = {
text?: string | null
}
| { __typename: 'ComponentSectionsSpace' }
| { __typename: 'ComponentSectionsTestimonials' }
| {
__typename: 'ComponentSectionsTestimonials'
title?: string | null
text?: string | null
hasBackground?: boolean | null
testimonials: Array<{
__typename?: 'ComponentBlocksTestimonialItem'
id: string
name: string
quote: string
} | null>
}
| {
__typename: 'ComponentSectionsTextWithImage'
hasBackground?: boolean | null
Expand Down Expand Up @@ -11363,6 +11385,26 @@ export type GalleryItemBlockFragment = {
} | null
}

export type TestimonialItemBlockFragment = {
__typename?: 'ComponentBlocksTestimonialItem'
id: string
name: string
quote: string
}

export type TestimonialsSectionFragment = {
__typename?: 'ComponentSectionsTestimonials'
title?: string | null
text?: string | null
hasBackground?: boolean | null
testimonials: Array<{
__typename?: 'ComponentBlocksTestimonialItem'
id: string
name: string
quote: string
} | null>
}

export type TimelineItemBlockFragment = {
__typename?: 'ComponentBlocksTimelineItem'
id: string
Expand Down Expand Up @@ -13227,6 +13269,15 @@ type Sections_ComponentSectionsSpace_Fragment = { __typename: 'ComponentSections

type Sections_ComponentSectionsTestimonials_Fragment = {
__typename: 'ComponentSectionsTestimonials'
title?: string | null
text?: string | null
hasBackground?: boolean | null
testimonials: Array<{
__typename?: 'ComponentBlocksTestimonialItem'
id: string
name: string
quote: string
} | null>
}

type Sections_ComponentSectionsTextWithImage_Fragment = {
Expand Down Expand Up @@ -14229,6 +14280,24 @@ export const RegulationsSectionFragmentDoc = gql`
}
${RegulationEntityFragmentDoc}
`
export const TestimonialItemBlockFragmentDoc = gql`
fragment TestimonialItemBlock on ComponentBlocksTestimonialItem {
id
name
quote
}
`
export const TestimonialsSectionFragmentDoc = gql`
fragment TestimonialsSection on ComponentSectionsTestimonials {
title
text
hasBackground
testimonials {
...TestimonialItemBlock
}
}
${TestimonialItemBlockFragmentDoc}
`
export const SectionsFragmentDoc = gql`
fragment Sections on PageSectionsDynamicZone {
__typename
Expand Down Expand Up @@ -14319,6 +14388,9 @@ export const SectionsFragmentDoc = gql`
... on ComponentSectionsRegulations {
...RegulationsSection
}
... on ComponentSectionsTestimonials {
...TestimonialsSection
}
}
${IconTitleDescSectionFragmentDoc}
${DocumentListSectionFragmentDoc}
Expand Down Expand Up @@ -14349,6 +14421,7 @@ export const SectionsFragmentDoc = gql`
${ContactsSectionFragmentDoc}
${RegulationsListSectionFragmentDoc}
${RegulationsSectionFragmentDoc}
${TestimonialsSectionFragmentDoc}
`
export const BlogPostEntityFragmentDoc = gql`
fragment BlogPostEntity on BlogPostEntity {
Expand Down
19 changes: 19 additions & 0 deletions next/backend/graphql/queries/Sections.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ fragment GalleryItemBlock on ComponentBlocksGalleryItem {
}
}

fragment TestimonialItemBlock on ComponentBlocksTestimonialItem {
id
name
quote
}

fragment TestimonialsSection on ComponentSectionsTestimonials {
title
text
hasBackground
testimonials {
...TestimonialItemBlock
}
}

fragment TimelineItemBlock on ComponentBlocksTimelineItem {
id
title
Expand Down Expand Up @@ -592,6 +607,10 @@ fragment Sections on PageSectionsDynamicZone {
... on ComponentSectionsRegulations {
...RegulationsSection
}

... on ComponentSectionsTestimonials {
...TestimonialsSection
}
}

fragment SubpageListPageHeaderSection on ComponentSectionsSubpageList {
Expand Down
4 changes: 4 additions & 0 deletions next/components/molecules/Sections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ContactsSection from '@components/molecules/sections/general/ContactsSect
import FeaturedBlogPostsSection from '@components/molecules/sections/general/FeaturedBlogPostsSection'
import InbaReleasesSection from '@components/molecules/sections/general/InbaReleasesSection'
import RegulationsSection from '@components/molecules/sections/general/RegulationsSection'
import TestimonialsSection from '@components/molecules/sections/general/TestimonialsSection'
import cx from 'classnames'
import * as React from 'react'

Expand Down Expand Up @@ -120,6 +121,9 @@ const SectionContent = ({ section }: { section: SectionsFragment }) => {
case 'ComponentSectionsRegulations':
return <RegulationsSection section={section} />

case 'ComponentSectionsTestimonials':
return <TestimonialsSection section={section} />

default:
return null
}
Expand Down
76 changes: 76 additions & 0 deletions next/components/molecules/sections/general/TestimonialsSection.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { TestimonialItemBlockFragment, TestimonialsSectionFragment } from '@backend/graphql'
import { Typography } from '@bratislava/component-library'
import Markdown from '@components/atoms/Markdown'
import { isDefined } from '@utils/isDefined'
import cx from 'classnames'
import React from 'react'
import { twMerge } from 'tailwind-merge'

type TestimonialsSectionProps = {
section: TestimonialsSectionFragment
}

const TestimonialCard = ({
testimonial,
hasBackground,
className,
}: {
testimonial: TestimonialItemBlockFragment
hasBackground?: boolean
className?: string
}) => {
return (
<div
className={twMerge(
'relative rounded-lg bg-white p-4',
hasBackground ? 'bg-white' : 'bg-category-100',
className,
)}
>
{/* TODO validate if this html syntax is ok */}
<blockquote className="flex flex-col gap-4">
<Typography type="p">{testimonial.quote}</Typography>
<footer>
{/* TODO there probably should not be p inside cite, but cite should be used directly */}
<cite>
<Typography type="p" fontWeight="semibold">
{testimonial.name}
</Typography>
</cite>
</footer>
</blockquote>
</div>
)
}

const Testimonials = ({ section }: TestimonialsSectionProps) => {
return (
<div className="grid grid-cols-1 gap-6 md:grid-cols-12 md:gap-8">
<div className={cx('col-span-1 flex flex-col gap-3', 'md:col-span-5')}>
{section.title ? <Typography type="h2">{section.title}</Typography> : null}
{section.text ? <Markdown content={section.text} variant="small-no-respo" /> : null}
</div>
<div className={cx('hidden md:block', 'col-span-1')} />
<div className={cx('col-span-1', 'md:col-span-6')}>
{/* TODO render as <ul> */}
<div className="grid grid-cols-1 gap-2 md:grid-cols-2 md:gap-3">
{section.testimonials.filter(isDefined).map((testimonial, index) => (
<TestimonialCard
// eslint-disable-next-line react/no-array-index-key
key={index}
className={cx('col-span-1', 'md:col-span-2')}
testimonial={testimonial}
hasBackground={section.hasBackground ?? false}
/>
))}
</div>
</div>
</div>
)
}

const TestimonialsSection = ({ section }: TestimonialsSectionProps) => {
return <Testimonials section={section} />
}

export default TestimonialsSection

0 comments on commit ebec9b4

Please sign in to comment.