import React, { type ElementType, type HTMLAttributes } from 'react' import { FormattedMessage, useIntl } from '@cultureamp/i18n-react-intl' import classNames from 'classnames' import { BrandMoment } from '~components/BrandMoment' import { Icon } from '~components/Icon' import { BrandMomentError } from '~components/Illustration' import { Text } from '~components/Text' import { type OverrideClassName } from '~components/types/OverrideClassName' import { useErrorMessages, type ErrorStatuses } from './hooks' import styles from './ErrorPage.module.css' const getMailToHref = (code: ErrorStatuses): string => { const supportEmail = 'support@cultureamp.com' const subject = 'Houston we have a problem' const body = `Hi there,\n\nI received a ${code} error page while I was trying to...` return encodeURI(`mailto:${supportEmail}?subject=${subject}&body=${body}`) } const HOME_HREF = '/app/home' export type ErrorPageProps = { code: ErrorStatuses title?: string message?: React.ReactNode | string callToAction?: { onContactSupport: () => void homeHref?: string } tag?: ElementType } & OverrideClassName> export const ErrorPage = ({ code, title, message, callToAction, tag, classNameOverride, }: ErrorPageProps): JSX.Element => { const { formatMessage } = useIntl() const content = useErrorMessages(code) const actions = { primary: { href: callToAction?.homeHref ?? HOME_HREF }, secondary: callToAction?.onContactSupport ? { onClick: callToAction.onContactSupport } : { href: getMailToHref(code) }, } return (
} body={ <>
{message ?? content.message}
} illustration={} variant="warning" primaryAction={{ ...actions.primary, icon: , iconPosition: 'end', label: formatMessage({ id: 'kzErrorPage.goToHome', defaultMessage: 'Go to Home', description: 'Home button label', }), }} secondaryAction={{ ...actions.secondary, icon: , label: formatMessage({ id: 'kzErrorPage', defaultMessage: 'Contact support', description: 'Label for contact button', }), }} text={{ title: title ?? content.title, }} />
) } ErrorPage.displayName = 'ErrorPage'