Skip to content

Commit

Permalink
fix: page builder error
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan authored Oct 17, 2024
1 parent 9d4b4c6 commit 0ff15ee
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions apps/page-builder-demo/src/components/page/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,38 +38,42 @@ export function Page(props: {data: PageData}) {
path: 'sections',
}).toString()}
>
{sections?.map((section) => {
if (section._type === 'hero') {
{sections?.map((section: PageSection | null) => {
if (section?._type === 'hero') {
return <Hero page={data} key={section._key} section={section} />
}

if (section._type === 'intro') {
if (section?._type === 'intro') {
return <Intro page={data} key={section._key} section={section} />
}

if (section._type === 'featuredProducts') {
if (section?._type === 'featuredProducts') {
return <FeaturedProducts page={data} key={section._key} section={section} />
}

if (section._type === 'featureHighlight') {
if (section?._type === 'featureHighlight') {
return <FeatureHighlight page={data} key={section._key} section={section} />
}

if (section._type === 'section') {
if (section?._type === 'section') {
return <Section page={data} key={section._key} section={section} />
}

return (
<div
data-sanity={dataAttribute({
id: data._id,
type: data._type,
path: `sections[_key=="${(section as any)._key}"]`,
}).toString()}
data-sanity={
section
? dataAttribute({
id: data._id,
type: data._type,
path: `sections[_key=="${(section as any)._key}"]`,
}).toString()
: undefined
}
className="bg-red-50 p-5 font-mono text-sm text-red-600 dark:bg-red-950 dark:text-red-400"
key={(section as any)._key}
key={(section as any)?._key}
>
<div>Unknown section type: {(section as any)._type}</div>
<div>Unknown section type: {(section as any)?._type}</div>
<pre>{JSON.stringify(section, null, 2)}</pre>
</div>
)
Expand Down

0 comments on commit 0ff15ee

Please sign in to comment.