layout.js 1.3 KB

123456789101112131415161718192021222324252627282930
  1. import { View } from 'app/design/view'
  2. import { appStatic } from 'app/lib/app-static'
  3. import { useCurrentUser } from 'app/context/user'
  4. import { PageHeader } from 'app/ui/molecules/header/page-header';
  5. import { HeaderOptionsProvider } from 'app/ui/molecules/header/options';
  6. import { AnalyticsErrorBoundary } from 'app/lib/analytics/error-boundary';
  7. import { ScreenReadyMarker } from 'app/lib/analytics/screen-ready-marker';
  8. /** A page failed to render: the header and the tab bar stay, so the app can go elsewhere. */
  9. const renderPageError = (error, reset) => appStatic('page_error', { error, reset });
  10. export default function Layout({ data, children, layout }) {
  11. const { currentUser } = useCurrentUser()
  12. if (data?.page_status == 503 || currentUser?.page_status == 503) {
  13. return appStatic('maintenance_mode');
  14. }
  15. return (
  16. <HeaderOptionsProvider>
  17. <View className={`text-popover-foreground w-full h-full flex-1 bg-background`}>
  18. <PageHeader layoutName={layout.layoutName} pageData={data}/>
  19. <AnalyticsErrorBoundary fallback={renderPageError} resetKey={data?.url}>
  20. {children}
  21. </AnalyticsErrorBoundary>
  22. <ScreenReadyMarker key={data?.url || ''} />
  23. </View>
  24. </HeaderOptionsProvider>
  25. );
  26. }