Skip to content

Commit

Permalink
chore: adds fata-fetching from root layout
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoformiga committed May 3, 2024
1 parent e07d785 commit abb99ba
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion packages/core/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,46 @@ import { WebFonts } from 'src/customizations/src/GlobalOverrides'
export const GLOBAL_SECTIONS_CONTENT_TYPE = 'globalSections'

import { Section } from '@vtex/client-cms'
import storeConfig from 'faststore.config'
import { PageContentType, getPage } from 'src/server/cms'

export type GlobalSectionsData = {
sections: Section[]
}

async function getGlobalSectionsData() {
if (storeConfig.cms.data) {
const cmsData = JSON.parse(storeConfig.cms.data)
const page = cmsData[GLOBAL_SECTIONS_CONTENT_TYPE][0]

if (page) {
const pageData = await getPage<PageContentType>({
contentType: GLOBAL_SECTIONS_CONTENT_TYPE,
documentId: page.documentId,
versionId: page.versionId,
})

return pageData
}
}

{
/* TODO: we should use DraftMode instead of preview mode in Next 13 */
}
const { sections } = await getPage<PageContentType>({
contentType: GLOBAL_SECTIONS_CONTENT_TYPE,
})

return { sections }
}

export default async function RootLayout({
children,
}: {
children: React.ReactNode
}) {
const globalSections = { sections: [] }
const globalSections = await getGlobalSectionsData()

return (
<ErrorBoundary>
{/* TODO: we should use metadata api from Next 13 */}
Expand Down

0 comments on commit abb99ba

Please sign in to comment.