import React, { Component, ErrorInfo, ReactNode } from 'react'; import { AlertTriangle, RefreshCw } from 'lucide-react'; import * as Sentry from '@sentry/react'; interface Props { children?: ReactNode; } interface State { hasError: boolean; error: Error | null; } export class ErrorBoundary extends Component { public state: State = { hasError: false, error: null }; public static getDerivedStateFromError(error: Error): State { return { hasError: true, error }; } public componentDidCatch(error: Error, errorInfo: ErrorInfo) { console.error('Nieobsłużony błąd interfejsu złapany przez ErrorBoundary:', error, errorInfo); try { Sentry.captureException(error, { extra: { componentStack: errorInfo.componentStack }, }); } catch { // no-op when Sentry is not initialized (missing VITE_SENTRY_DSN) } } private handleReload = () => { window.location.reload(); }; public render() { if (this.state.hasError) { return (

Ups! Coś poszło nie tak.

Wystąpił nieoczekiwany błąd w interfejsie użytkownika. Spróbuj odświeżyć stronę.

{this.state.error?.message || "Unknown error"}

); } return this.props.children; } }