diff --git a/packages/core/app/layout.tsx b/packages/core/app/layout.tsx index 23c41eab51..c5428197ca 100644 --- a/packages/core/app/layout.tsx +++ b/packages/core/app/layout.tsx @@ -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({ + 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({ + contentType: GLOBAL_SECTIONS_CONTENT_TYPE, + }) + + return { sections } +} + export default async function RootLayout({ children, }: { children: React.ReactNode }) { - const globalSections = { sections: [] } + const globalSections = await getGlobalSectionsData() + return ( {/* TODO: we should use metadata api from Next 13 */}