import type { ErrorInfo } from "react"; import { Component, Suspense } from "react"; import type { BlitzLayout } from "blitz"; import { Head, withRouter, AuthenticationError, AuthorizationError, CSRFTokenMismatchError, NotFoundError, RedirectError, Routes, } from "blitz"; import type { WithRouterProps } from "next/dist/client/with-router"; import appLogger from "integrations/logger"; import Footer from "./footer"; import Loader from "./loader"; type Props = { title: string; pageTitle?: string; hideFooter?: true; }; const logger = appLogger.child({ module: "Layout" }); const AppLayout: BlitzLayout = ({ children, title, pageTitle = title, hideFooter = false }) => { return ( <> {pageTitle ? ( {pageTitle} | Shellphone ) : null} }>
{children}
{!hideFooter ?
: null}
); }; AppLayout.authenticate = { redirectTo: Routes.SignIn() }; type ErrorBoundaryState = | { isError: false; } | { isError: true; errorMessage: string; }; const blitzErrors = [RedirectError, AuthenticationError, AuthorizationError, CSRFTokenMismatchError, NotFoundError]; const ErrorBoundary = withRouter( class ErrorBoundary extends Component { public readonly state = { isError: false, } as const; static getDerivedStateFromError(error: Error): ErrorBoundaryState { return { isError: true, errorMessage: error.message, }; } public componentDidCatch(error: Error, errorInfo: ErrorInfo) { console.trace("ddd"); logger.error(error, errorInfo.componentStack); if (blitzErrors.some((blitzError) => error instanceof blitzError)) { // let Blitz ErrorBoundary handle this one throw error; } // if network error and connection lost, display the auto-reload page with countdown } public render() { if (this.state.isError) { return ( <>

Oops, something went wrong.

Would you like to{" "} {" "} ?

); } return this.props.children; } }, ); export default AppLayout;