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

add Testimonials FE components #1240

Merged
merged 1 commit into from
Mar 27, 2024
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
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
78 changes: 78 additions & 0 deletions next/components/molecules/sections/general/TestimonialsSection.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
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'

// TODO split to separate component files

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
Loading