'use client' import React from 'react' import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card' import { Button } from '@/components/ui/button' import { AlertTriangle, RefreshCw } from 'lucide-react' interface ErrorBoundaryState { hasError: boolean error?: Error errorInfo?: React.ErrorInfo } interface ErrorBoundaryProps { children: React.ReactNode fallback?: React.ComponentType<{ error: Error; retry: () => void }> } export class ErrorBoundary extends React.Component { constructor(props: ErrorBoundaryProps) { super(props) this.state = { hasError: false } } static getDerivedStateFromError(error: Error): ErrorBoundaryState { return { hasError: true, error, } } componentDidCatch(error: Error, errorInfo: React.ErrorInfo) { console.error('Error caught by boundary:', error, errorInfo) // Log error to monitoring service in production if (process.env.NODE_ENV === 'production') { // You can integrate with services like Sentry here console.error('Production error:', { error: error.message, stack: error.stack, componentStack: errorInfo.componentStack, }) } this.setState({ hasError: true, error, errorInfo, }) } handleRetry = () => { this.setState({ hasError: false, error: undefined, errorInfo: undefined }) } render() { if (this.state.hasError) { const { fallback: Fallback } = this.props if (Fallback && this.state.error) { return } return ( Something went wrong

An unexpected error occurred. Please try refreshing the page or contact support if the problem persists.

{process.env.NODE_ENV === 'development' && this.state.error && (
Error Details
                  {this.state.error.message}
                  {'\n\n'}
                  {this.state.error.stack}
                
)}
) } return this.props.children } } // Hook version for functional components export function useErrorHandler() { const [error, setError] = React.useState(null) const resetError = React.useCallback(() => { setError(null) }, []) const captureError = React.useCallback((error: Error) => { console.error('Error captured:', error) setError(error) }, []) React.useEffect(() => { if (error) { // Log to monitoring service console.error('Error in component:', error) } }, [error]) return { error, resetError, captureError } } // Specific error fallback components export function AdminErrorFallback({ error, retry }: { error: Error; retry: () => void }) { return (
Admin Panel Error

There was an error loading the admin panel. This might be due to a network issue or server problem.

) } export function CalendarErrorFallback({ error, retry }: { error: Error; retry: () => void }) { return ( Calendar Loading Error

Unable to load the appointment calendar. Please check your connection and try again.

) }