import React, { useState } from 'react'; import parse from 'html-react-parser'; import { PublicPageResponse, publicBffUrl } from '@tempi/core-renderer'; import { ScriptSection } from 'components/ScriptSection'; import { useGlobalData } from 'contexts'; import { usePagePublic, UsePagePublicInterface } from 'hooks/usePagePublic'; import ErrorBoundary from 'components/ErrorView/ErrorBoundary'; import dynamic from 'next/dynamic'; import { useScrollPage } from 'hooks/useScrollPage'; import { HeadSection, ErrorView, ProtectedView } from 'components'; const LoadingOverlay = dynamic(() => import('../LoadingOverlay/LoadingOverlay').then((mod) => mod.LoadingOverlay), ); const Content = dynamic(() => import('./Content').then((mod) => mod.Content)); const forbiddenErrorCode = '403000'; export interface LandingPropsV2 extends UsePagePublicInterface { page: PublicPageResponse; } export const LandingPageV2: React.FC = ({ page: serverPage, prefixLangUrl, ...rest }: LandingPropsV2) => { useScrollPage(); const { isMobile } = useGlobalData(); const [password, setPassword] = useState(); const { page = serverPage, error, isLoading, } = usePagePublic({ ...rest, password }); const envs = rest?.envs || {}; const showLoading = (envs['REVALIDATE_PAGE_FLAG'] && envs['SHOW_LOADING_FLAG']) || false; const EXTEND_LOADING_TIME = envs['EXTEND_LOADING_TIME'] || 0; const extraInfo = page?.extraInfo || {}; // debug mem peak if (typeof process !== 'undefined') { const used = process?.memoryUsage?.(); if (used) { const heapUsed = used.heapUsed / 1024 / 1024; if (heapUsed > 500) // eslint-disable-next-line no-console console.log( rest.hostname, rest.slug, `The script uses approximately ${ Math.round(heapUsed * 100) / 100 } MB`, ); } } if (error?.response?.code == 404001) { return ( ); } if ( (rest.errorCode === forbiddenErrorCode || error?.response?.code === forbiddenErrorCode) && !page ) { return ( <> ); } return ( <> {showLoading && ( )} {extraInfo.bodyContentHtml && parse(extraInfo.bodyContentHtml)} ); };