feat: Add error boundaries to submission queries

This commit is contained in:
gpt-engineer-app[bot]
2025-11-05 20:05:01 +00:00
parent 5513f532ee
commit 5e4ed810c0
5 changed files with 90 additions and 23 deletions

View File

@@ -4,7 +4,9 @@ import { Card, CardContent } from '@/components/ui/card';
import { supabase } from '@/lib/supabaseClient';
import { Image as ImageIcon } from 'lucide-react';
import { PhotoModal } from './PhotoModal';
import { handleError } from '@/lib/errorHandler';
import { handleError, getErrorMessage } from '@/lib/errorHandler';
import { Alert, AlertDescription } from '@/components/ui/alert';
import { AlertCircle } from 'lucide-react';
interface EntityEditPreviewProps {
submissionId: string;
@@ -68,6 +70,7 @@ interface SubmissionItemData {
export const EntityEditPreview = ({ submissionId, entityType, entityName }: EntityEditPreviewProps) => {
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const [itemData, setItemData] = useState<Record<string, unknown> | null>(null);
const [originalData, setOriginalData] = useState<Record<string, unknown> | null>(null);
const [changedFields, setChangedFields] = useState<string[]>([]);
@@ -196,10 +199,12 @@ export const EntityEditPreview = ({ submissionId, entityType, entityName }: Enti
setChangedFields(changed);
}
} catch (error: unknown) {
const errorMsg = getErrorMessage(error);
handleError(error, {
action: 'Load Submission Preview',
metadata: { submissionId, entityType }
});
setError(errorMsg);
} finally {
setLoading(false);
}
@@ -213,6 +218,17 @@ export const EntityEditPreview = ({ submissionId, entityType, entityName }: Enti
);
}
if (error) {
return (
<Alert variant="destructive">
<AlertCircle className="h-4 w-4" />
<AlertDescription>
{error}
</AlertDescription>
</Alert>
);
}
if (!itemData) {
return (
<div className="text-sm text-muted-foreground">