import type { MessageDescriptor } from '@lingui/core'; import { msg } from '@lingui/core/macro'; import { useLingui } from '@lingui/react'; import { Trans } from '@lingui/react/macro'; import { motion } from 'framer-motion'; import { ChevronLeft } from 'lucide-react'; import { Link, useNavigate } from 'react-router'; import backgroundPattern from '@documenso/assets/images/background-pattern.png'; import { Button } from '@documenso/ui/primitives/button'; type ErrorCodeMap = Record< number, { subHeading: MessageDescriptor; heading: MessageDescriptor; message: MessageDescriptor } >; export type GenericErrorLayoutProps = { children?: React.ReactNode; errorCode?: number; errorCodeMap?: ErrorCodeMap; /** * The primary button to display. If left as undefined, the default home link will be displayed. * * Set to null if you want no button. */ primaryButton?: React.ReactNode | null; /** * The secondary button to display. If left as undefined, the default back button will be displayed. * * Set to null if you want no button. */ secondaryButton?: React.ReactNode | null; }; export const defaultErrorCodeMap: ErrorCodeMap = { 404: { subHeading: msg`404 not found`, heading: msg`Oops! Something went wrong.`, message: msg`The page you are looking for was moved, removed, renamed or might never have existed.`, }, 500: { subHeading: msg`500 Internal Server Error`, heading: msg`Oops! Something went wrong.`, message: msg`An unexpected error occurred.`, }, }; export const GenericErrorLayout = ({ children, errorCode, errorCodeMap = defaultErrorCodeMap, primaryButton, secondaryButton, }: GenericErrorLayoutProps) => { const navigate = useNavigate(); const { _ } = useLingui(); const { subHeading, heading, message } = errorCodeMap[errorCode || 500] ?? defaultErrorCodeMap[500]; return (
background pattern

{_(subHeading)}

{_(heading)}

{_(message)}

{secondaryButton || (secondaryButton !== null && ( ))} {primaryButton || (primaryButton !== null && ( ))} {children}
); };