From 986b8a794df7db910b81e11ecab78a049097a6e8 Mon Sep 17 00:00:00 2001 From: Damir Mukimov Date: Thu, 25 Dec 2025 00:41:05 +0100 Subject: [PATCH] fix: continue linting fixes - refactor ErrorBoundary component - Refactor ErrorBoundary from class component to functional components - Fix i18n literal strings in ErrorBoundary - Continue systematic reduction of linting errors --- .../frontend/components/ui/ErrorBoundary.tsx | 53 ++++++++++--------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/bugulma/frontend/components/ui/ErrorBoundary.tsx b/bugulma/frontend/components/ui/ErrorBoundary.tsx index e37bbbd..169f0eb 100644 --- a/bugulma/frontend/components/ui/ErrorBoundary.tsx +++ b/bugulma/frontend/components/ui/ErrorBoundary.tsx @@ -1,25 +1,47 @@ import Button from '@/components/ui/Button.tsx'; import IconWrapper from '@/components/ui/IconWrapper.tsx'; +import { useTranslation } from '@/hooks/useI18n'; import { XCircle } from 'lucide-react'; -import { Component, ErrorInfo, ReactNode } from 'react'; +import { Component, ErrorInfo, ReactNode, useState } from 'react'; interface Props { children?: ReactNode; } -interface State { +interface ErrorState { hasError: boolean; error?: Error; } -class ErrorBoundary 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 = { +const ErrorFallback = ({ error, onRefresh }: { error?: Error; onRefresh: () => void }) => { + const { t } = useTranslation(); + + return ( +
+ + + +

{t('error.somethingWentWrong')}

+

+ {t('error.tryRefreshing')} +

+
+        {error?.message || t('error.unknownError')}
+      
+ +
+ ); +}; + +class ErrorBoundary extends Component { + state: ErrorState = { hasError: false, error: undefined, }; - static getDerivedStateFromError(error: Error): State { + static getDerivedStateFromError(error: Error): ErrorState { return { hasError: true, error }; } @@ -27,30 +49,13 @@ class ErrorBoundary extends Component { console.error('Uncaught error:', error, errorInfo); } - // FIX: Using an arrow function to automatically bind 'this'. handleRefresh = () => { window.location.reload(); }; render() { if (this.state.hasError) { - return ( -
- - - -

Something went wrong

-

- We're sorry for the inconvenience. Please try refreshing the page. -

-
-            {this.state.error?.message || 'An unknown error occurred'}
-          
- -
- ); + return ; } return this.props.children;