Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | 1x 1x 1x 1x 1x 1x 19x 20x 20x 20x 19x 18x 18x 19x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 19x 1x 1x 19x 47x 27x 3x 3x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 27x 3x 3x 3x 3x 3x 3x 3x 3x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 27x 20x 47x 19x | 'use client';
import { Link } from '@tanstack/react-router';
import { Button } from '@web/components/ui/button';
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from '@web/components/ui/card';
import { AlertCircleIcon, RefreshCwIcon, SettingsIcon } from 'lucide-react';
import { Component, type ErrorInfo, type ReactNode } from 'react';
interface Props {
children: ReactNode;
fallback?: (error: Error, resetError: () => void) => ReactNode;
}
interface State {
hasError: boolean;
error: Error | null;
errorInfo: ErrorInfo | null;
}
export class SettingsErrorBoundary extends Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = { hasError: false, error: null, errorInfo: null };
}
static getDerivedStateFromError(error: Error): Partial<State> {
return { hasError: true, error };
}
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
console.error('Settings error:', {
error: error.toString(),
stack: errorInfo.componentStack,
timestamp: new Date().toISOString(),
});
if (window?.performance) {
performance.mark('settings-error');
}
this.setState({ errorInfo });
}
resetError = () => {
this.setState({ hasError: false, error: null, errorInfo: null });
};
render() {
if (this.state.hasError) {
if (this.props.fallback) {
return this.props.fallback(this.state.error!, this.resetError);
}
return (
<div className="p-6">
<Card className="border-destructive">
<CardHeader>
<CardTitle className="flex items-center gap-2 text-destructive">
<AlertCircleIcon className="h-5 w-5" aria-hidden="true" />
Failed to Load Settings
</CardTitle>
<CardDescription>
We encountered an error while loading the system settings. This
could be due to a network issue or a configuration problem.
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<div className="space-y-2">
<p className="text-sm text-muted-foreground">
You can try the following:
</p>
<ul className="list-disc list-inside text-sm text-muted-foreground space-y-1">
<li>Refresh the page to try loading again</li>
<li>Check your network connection</li>
<li>Verify the database is accessible</li>
</ul>
</div>
{process.env.NODE_ENV === 'development' && this.state.error && (
<details className="text-xs">
<summary className="cursor-pointer text-muted-foreground hover:text-foreground">
Error Details (Development Only)
</summary>
<pre className="mt-2 p-2 bg-muted rounded overflow-auto max-h-48">
{this.state.error.toString()}
{this.state.errorInfo?.componentStack}
</pre>
</details>
)}
<div className="flex gap-2">
<Button
onClick={this.resetError}
variant="outline"
className="gap-2"
>
<RefreshCwIcon className="h-4 w-4" aria-hidden="true" />
Try Again
</Button>
<Button asChild variant="ghost" className="gap-2">
<Link to="/">
<SettingsIcon className="h-4 w-4" aria-hidden="true" />
Go to Dashboard
</Link>
</Button>
</div>
</CardContent>
</Card>
</div>
);
}
return this.props.children;
}
}
|