Refactor: Implement system activity log fixes

This commit is contained in:
gpt-engineer-app[bot]
2025-10-11 16:04:28 +00:00
parent f37b99a5f9
commit 120f68c926
3 changed files with 89 additions and 3 deletions

View File

@@ -1,4 +1,4 @@
import { useEffect } from 'react';
import { useEffect, Component, ReactNode } from 'react';
import { useNavigate } from 'react-router-dom';
import { useAuth } from '@/hooks/useAuth';
import { useUserRole } from '@/hooks/useUserRole';
@@ -6,6 +6,48 @@ import { AdminLayout } from '@/components/layout/AdminLayout';
import { SystemActivityLog } from '@/components/admin/SystemActivityLog';
import { Skeleton } from '@/components/ui/skeleton';
import { Card, CardContent } from '@/components/ui/card';
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert';
import { AlertCircle } from 'lucide-react';
interface ErrorBoundaryProps {
children: ReactNode;
}
interface ErrorBoundaryState {
hasError: boolean;
error: Error | null;
}
class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
constructor(props: ErrorBoundaryProps) {
super(props);
this.state = { hasError: false, error: null };
}
static getDerivedStateFromError(error: Error) {
return { hasError: true, error };
}
componentDidCatch(error: Error, errorInfo: any) {
console.error('System Activity Log Error:', error, errorInfo);
}
render() {
if (this.state.hasError) {
return (
<Alert variant="destructive">
<AlertCircle className="h-4 w-4" />
<AlertTitle>Error loading system activity log</AlertTitle>
<AlertDescription>
{this.state.error?.message || 'An unexpected error occurred'}
</AlertDescription>
</Alert>
);
}
return this.props.children;
}
}
export default function AdminSystemLog() {
const { user, loading: authLoading } = useAuth();
@@ -69,7 +111,9 @@ export default function AdminSystemLog() {
</p>
</div>
<SystemActivityLog limit={100} showFilters={true} />
<ErrorBoundary>
<SystemActivityLog limit={100} showFilters={true} />
</ErrorBoundary>
</div>
</AdminLayout>
);