generated from notum-cz/strapi-next-monorepo-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComponentsRenderer.tsx
72 lines (64 loc) · 2.36 KB
/
ComponentsRenderer.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { Attribute, Types } from "@repo/strapi"
import { removeThisWhenYouNeedMe } from "@/lib/general-helpers"
import { ErrorBoundary } from "../elementary/ErrorBoundary"
import { AnimatedLogoRow } from "./components/AnimatedLogoRow"
import { CarouselGrid } from "./components/CarouselGrid"
import { ContactFormSection } from "./components/ContactFormSection"
import { Faq } from "./components/Faq"
import { FeatureGrid } from "./components/FeatureGrid"
import { HeadingWithCTAButton } from "./components/HeadingWithCTAButton"
import { Hero } from "./components/Hero"
import { HorizontalImages } from "./components/HorizontalImagesSlider"
import { ImageWithCTAButton } from "./components/ImageWithCTAButton"
import { Newsletter } from "./components/Newsletter"
// Define page-level components supported by this switch
const printableComps: {
// eslint-disable-next-line no-unused-vars
[K in Types.Common.UID.Component]?: React.ComponentType<any>
} = {
"sections.faq": Faq,
"sections.hero": Hero,
"sections.feature-grid": FeatureGrid,
"sections.carousel": CarouselGrid,
"sections.heading-with-cta-button": HeadingWithCTAButton,
"sections.image-with-cta-button": ImageWithCTAButton,
"sections.animated-logo-row": AnimatedLogoRow,
"sections.horizontal-images": HorizontalImages,
"sections.newsletter": Newsletter,
"sections.contact-form": ContactFormSection,
// Add more components here
}
export function ComponentsRenderer({
pageComponents,
}: {
readonly pageComponents: Attribute.GetDynamicZoneValue<
Attribute.DynamicZone<Types.Common.UID.Component[]>
>
}) {
removeThisWhenYouNeedMe("ComponentsRenderer")
return (
<section>
{pageComponents
.filter((comp) => comp != null)
.map((comp) => {
const name = comp.__component
const id = comp.id
const key = `${name}-${id}`
const Component = printableComps[name]
if (Component == null) {
console.warn(`Unknown component "${name}" with id "${id}".`)
return (
<div key={key} className="font-medium text-red-500">
Component "{key}" is not implemented on the frontend.
</div>
)
}
return (
<ErrorBoundary key={key}>
<Component component={comp} />
</ErrorBoundary>
)
})}
</section>
)
}