"use client"; import { useEffect, Suspense, Component, ReactNode } from "react"; import { useRouter } from "next/navigation"; import Dashboard from "@/components/dashboard/dashboard"; import { MessageCircle, AlertCircle, RefreshCw } from "lucide-react"; import dynamic from "next/dynamic"; import { Skeleton } from "@/components/ui/skeleton"; import { Card, CardContent, CardHeader } from "@/components/ui/card"; import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; import { Button } from "@/components/ui/button"; // Error Boundary Component interface ErrorBoundaryState { hasError: boolean; error: Error | null; } interface ErrorBoundaryProps { children: ReactNode; componentName?: string; } class ErrorBoundary extends Component { private retryCount = 0; private maxRetries = 2; constructor(props: ErrorBoundaryProps) { super(props); this.state = { hasError: false, error: null }; } static getDerivedStateFromError(error: Error): ErrorBoundaryState { return { hasError: true, error }; } componentDidCatch(error: Error, errorInfo: React.ErrorInfo) { console.error(`Error loading ${this.props.componentName || 'component'}:`, error, errorInfo); } handleRetry = () => { if (this.retryCount < this.maxRetries) { this.retryCount++; this.setState({ hasError: false, error: null }); } else { window.location.reload(); } }; render() { if (this.state.hasError) { return ( Failed to load {this.props.componentName || 'component'}

{this.state.error?.message || 'An unexpected error occurred while loading this component.'}

{this.retryCount < this.maxRetries && (

Retry attempt {this.retryCount + 1} of {this.maxRetries + 1}

)}
); } return this.props.children; } } // Lazy load the ChatTable component with error handling const ChatTable = dynamic(() => import("@/components/dashboard/ChatTable").catch((err) => { console.error("Failed to load ChatTable:", err); throw err; }), { loading: () => }); // Loading skeleton for the chat table function ChatTableSkeleton() { return ( {/* Subtle loading indicator */}
{['Customer', 'Last Message', 'Date', 'Status', 'Actions'].map((header, i) => ( ))}
{[...Array(6)].map((_, i) => (
))}
); } export default function ChatsPage() { const router = useRouter(); useEffect(() => { const authToken = document.cookie .split("; ") .find((row) => row.startsWith("Authorization=")) ?.split("=")[1]; if (!authToken) { router.push("/login"); } }, [router]); return (

Customer Chats

}>
); }