import { Blog, Page } from '@/payload-types' import { Container } from '@/components/Container/Container' import { HTMLText } from '@/components/Text/HTMLText' import { Section } from '@/components/Section/Section' import { Button } from '@/components/Button/Button' import { ContactSection } from '@/compositions/ContactSection/ContactSection' import { Gallery } from '@/components/Gallery/Gallery' import { transformGallery } from '@/utils/dto/gallery' import { DonationForm } from '@/components/DonationForm/DonationForm' import { YoutubePlayer } from '@/components/YoutubePlayer/YoutubePlayer' import { PageHeader } from '@/compositions/PageHeader/PageHeader' import { Title } from '@/components/Title/Title' import { Banner } from '@/components/Banner/Banner' import { MainText } from '@/components/MainText/MainText' import { HR } from '@/components/HorizontalRule/HorizontalRule' import { CollapsibleImageWithText } from '@/compositions/CollapsibleImageWithText/CollapsibleImageWithText' import { PublicationAndNewsletter } from '@/compositions/PublicationAndNewsletter/PublicationAndNewsletter' import { ContactPersonCard } from '@/components/ContactPersonCard/ContactPersonCard' import { getPhoto } from '@/utils/dto/gallery' import { BlogSliderBlock } from '@/compositions/Blocks/BlogSliderBlock' import { MassTimesBlock } from '@/compositions/Blocks/MassTimesBlock' import { EventsBlock } from '@/compositions/Blocks/EventsBlock' type BlocksProps = { content: Blog['content']['content'] | NonNullable } export function Blocks({ content }: BlocksProps) { // determine if some margin at the bottom should be added const length = content.length; const shouldAddMargin = content[length - 1].blockType === 'text' return ( <>
{content.map(item => { if (item.blockType === 'text') { return ( ); } if (item.blockType === 'document' && typeof item.file === 'object') { return (
) } if (item.blockType === 'contactform') { return ( ) } if (item.blockType === 'gallery') { return (
) } if (item.blockType === 'donation') { return
} if (item.blockType === 'youtube') { return
} if (item.blockType === 'button') { return
} if (item.blockType === 'pageHeader') { const imageUrl = typeof item.image === 'object' && item.image?.url ? item.image.url : undefined return ( ) } if (item.blockType === 'section') { const bg = item.backgroundColor === 'none' ? undefined : item.backgroundColor as 'soft' | 'off-white' | undefined return (
) } if (item.blockType === 'title') { return ( </Container> ) } if (item.blockType === 'banner') { const bannerImageUrl = typeof item.backgroundImage === 'object' && item.backgroundImage?.url ? item.backgroundImage.url : undefined return ( <Banner key={item.id} textLine1={item.textLine1} textLine2={item.textLine2} textLine3={item.textLine3} backgroundColor={item.backgroundColor} backgroundImage={bannerImageUrl} backgroundPosition={item.backgroundPosition} backgroundSize={item.backgroundSize} /> ) } if (item.blockType === 'mainText') { return ( <Container key={item.id}> <Section> <MainText text={item.text} /> </Section> </Container> ) } if (item.blockType === 'horizontalRule') { return <HR key={item.id} color={item.color} /> } if (item.blockType === 'blogSlider') { return ( <BlogSliderBlock key={item.id} title={item.title} /> ) } if (item.blockType === 'massTimes') { return ( <MassTimesBlock key={item.id} title={item.title} subtitle={item.subtitle} /> ) } if (item.blockType === 'collapsibleImageWithText') { const imageUrl = typeof item.image === 'object' && item.image?.url ? item.image.url : '' const colorStyle = item.colorStyle || 'default' const bg = colorStyle === 'soft' || colorStyle === 'off-white' ? colorStyle as 'soft' | 'off-white' : undefined const schema = colorStyle === 'contrast' ? 'contrast' as const : 'base' as const return ( <CollapsibleImageWithText key={item.id} title={item.title} text={item.text} image={imageUrl} backgroundColor={bg} schema={schema} content={ item.content ? <HTMLText width={'3/4'} data={item.content} /> : <></> } /> ) } if (item.blockType === 'events') { return ( <EventsBlock key={item.id} title={item.title} itemsPerPage={item.itemsPerPage} /> ) } if (item.blockType === 'contactPersonBlock') { const contact = typeof item.contact === 'object' ? item.contact : undefined const photo = contact ? getPhoto('thumbnail', contact.photo) : undefined return ( <Section key={item.id} padding={'small'}> <Container> <ContactPersonCard contact={contact} photo={photo} /> </Container> </Section> ) } // if (item.blockType === 'publicationAndNewsletter') { // return <PublicationAndNewsletter key={item.id} /> // } })} </div> { shouldAddMargin && <Section></Section> } </> ) }