99 lines
3.2 KiB
TypeScript
99 lines
3.2 KiB
TypeScript
import CardsGrid from "@/components/Blocks/CardsGrid"
|
|
import DynamicContent from "@/components/Blocks/DynamicContent"
|
|
import ShortcutsList from "@/components/Blocks/ShortcutsList"
|
|
import TextCols from "@/components/Blocks/TextCols"
|
|
import UspGrid from "@/components/Blocks/UspGrid"
|
|
import JsonToHtml from "@/components/JsonToHtml"
|
|
|
|
import AccordionSection from "./Accordion"
|
|
import HotelListing from "./HotelListing"
|
|
import Table from "./Table"
|
|
|
|
import type { BlocksProps } from "@/types/components/blocks"
|
|
import { BlocksEnums } from "@/types/enums/blocks"
|
|
|
|
export default function Blocks({ blocks }: BlocksProps) {
|
|
return blocks.map(async (block, idx) => {
|
|
const firstItem = idx === 0
|
|
switch (block.typename) {
|
|
case BlocksEnums.block.Accordion:
|
|
return (
|
|
<AccordionSection
|
|
accordion={block.accordion.accordions}
|
|
title={block.accordion.title}
|
|
key={`${block.typename}-${idx}`}
|
|
/>
|
|
)
|
|
case BlocksEnums.block.CardsGrid:
|
|
return (
|
|
<CardsGrid
|
|
cards_grid={block.cards_grid}
|
|
key={`${block.cards_grid.title}-${idx}`}
|
|
firstItem={firstItem}
|
|
/>
|
|
)
|
|
case BlocksEnums.block.Content:
|
|
return (
|
|
<section key={`${block.typename}-${idx}`}>
|
|
<JsonToHtml
|
|
nodes={block.content.json.children}
|
|
embeds={block.content.embedded_itemsConnection.edges}
|
|
/>
|
|
</section>
|
|
)
|
|
case BlocksEnums.block.DynamicContent:
|
|
return (
|
|
<DynamicContent
|
|
dynamic_content={block.dynamic_content}
|
|
firstItem={firstItem}
|
|
key={`${block.dynamic_content.title}-${idx}`}
|
|
/>
|
|
)
|
|
case BlocksEnums.block.HotelListing:
|
|
const { heading, contentType, locationFilter, hotelsToInclude } =
|
|
block.hotel_listing
|
|
if (!locationFilter && !hotelsToInclude.length) {
|
|
return null
|
|
}
|
|
|
|
return (
|
|
<HotelListing
|
|
heading={heading}
|
|
locationFilter={locationFilter}
|
|
hotelsToInclude={hotelsToInclude}
|
|
contentType={contentType}
|
|
/>
|
|
)
|
|
case BlocksEnums.block.Shortcuts:
|
|
return (
|
|
<ShortcutsList
|
|
firstItem={firstItem}
|
|
key={`${block.shortcuts.title}-${idx}`}
|
|
shortcuts={block.shortcuts.shortcuts}
|
|
subtitle={block.shortcuts.subtitle}
|
|
title={block.shortcuts.title}
|
|
hasTwoColumns={block.shortcuts.hasTwoColumns}
|
|
/>
|
|
)
|
|
case BlocksEnums.block.Table:
|
|
return <Table data={block.table} />
|
|
case BlocksEnums.block.TextCols:
|
|
return <TextCols text_cols={block.text_cols} />
|
|
case BlocksEnums.block.TextContent:
|
|
return (
|
|
<section key={`${block.typename}-${idx}`}>
|
|
<JsonToHtml
|
|
embeds={block.text_content.content.embedded_itemsConnection.edges}
|
|
nodes={block.text_content.content.json.children}
|
|
/>
|
|
</section>
|
|
)
|
|
case BlocksEnums.block.UspGrid:
|
|
return <UspGrid usp_grid={block.usp_grid} />
|
|
|
|
default:
|
|
return null
|
|
}
|
|
})
|
|
}
|