import { Component, ErrorInfo, ReactNode } from 'react'; import { withTranslation, type WithTranslation } from 'react-i18next'; import { AlertCircle, RefreshCw } from 'lucide-react'; import { Button } from '@/components/ui/button'; interface Props extends WithTranslation { children: ReactNode; resetKey?: string | number; } interface State { hasError: boolean; error: Error | null; } class PageErrorBoundaryBase extends Component { state: State = { hasError: false, error: null, }; static getDerivedStateFromError(error: Error): State { return { hasError: true, error }; } componentDidCatch(error: Error, errorInfo: ErrorInfo) { console.error('Uncaught error in page:', error, errorInfo); } componentDidUpdate(prevProps: Props) { if (this.state.hasError && prevProps.resetKey !== this.props.resetKey) { this.setState({ hasError: false, error: null }); } } private handleRetry = () => { this.setState({ hasError: false, error: null }); }; render() { const { t } = this.props; if (this.state.hasError) { return (

{t('pageErrorBoundary.title')}

{t('pageErrorBoundary.description')}

{this.state.error && (
                  {this.state.error.stack || this.state.error.toString()}
                
)}
); } return this.props.children; } } export const PageErrorBoundary = withTranslation('common')(PageErrorBoundaryBase); export default PageErrorBoundary;