import { Component, ErrorInfo, ReactNode } from 'react'; import { classComponentT as t } from '@/lib/class-component-utils'; import { XCircle } from 'lucide-react'; import Button from '@/components/ui/Button.tsx'; interface Props { children?: ReactNode; moduleName?: string; } interface State { hasError: boolean; } class ModuleErrorBoundary extends Component { // FIX: Replaced constructor with a class property for state initialization. This is a more modern and robust approach in class components and resolves the reported errors regarding `this.state` and `this.props` not being available. state: State = { hasError: false }; static getDerivedStateFromError(): State { return { hasError: true }; } componentDidCatch(error: Error, errorInfo: ErrorInfo) { console.error(`Error in ${this.props.moduleName || 'component'}:`, error, errorInfo); } // FIX: Using an arrow function to automatically bind 'this'. handleReset = () => { this.setState({ hasError: false }); }; render() { if (this.state.hasError) { const moduleName = this.props.moduleName || 'this module'; return (

{t('moduleErrorBoundary.title', { moduleName })}

{t('moduleErrorBoundary.subtitle')}

); } return this.props.children; } } export default ModuleErrorBoundary;