Samad14's picture
refactor(icons): migrate lucide-react to @phosphor-icons/react, remove dep
349f22c
Raw History Blame Contribute Delete
1.43 kB
'use client';
import { Component } from 'react';
import { WarningCircle as AlertCircle } from '@phosphor-icons/react';
interface Props {
children: React.ReactNode;
}
interface State {
hasError: boolean;
error: Error | null;
}
export class ErrorBoundary extends Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = { hasError: false, error: null };
}
static getDerivedStateFromError(error: Error): State {
return { hasError: true, error };
}
componentDidCatch(error: Error, info: React.ErrorInfo) {
console.error('[ErrorBoundary]', error, info.componentStack);
}
render() {
if (this.state.hasError) {
return (
<div className="flex items-center justify-center py-20 px-4">
<div className="glass-card p-12 text-center max-w-md">
<AlertCircle className="w-12 h-12 text-error mx-auto mb-4" />
<h2 className="text-lg font-semibold text-text-primary mb-2">Something went wrong</h2>
<p className="text-sm text-text-secondary mb-6">
{this.state.error?.message || 'An unexpected error occurred'}
</p>
<button
onClick={() => window.location.reload()}
className="btn-primary px-6 py-2.5 text-sm"
>
Reload page
</button>
</div>
</div>
);
}
return this.props.children;
}
}