Fix null safety issues

This commit is contained in:
gpt-engineer-app[bot]
2025-11-04 22:57:49 +00:00
parent c15efd7907
commit ae22a48ce2
4 changed files with 24 additions and 8 deletions

View File

@@ -56,12 +56,19 @@ export const SubmissionItemsList = memo(function SubmissionItemsList({
if (itemsError) throw itemsError; if (itemsError) throw itemsError;
// Transform to expected format // Transform to expected format with better null handling
const transformedItems = (itemsData || []).map((item: any) => ({ const transformedItems = (itemsData || []).map((item: any) => {
...item, // Ensure entity_data is at least an empty object, never null
item_data: item.entity_data || {}, const safeEntityData = item.entity_data && typeof item.entity_data === 'object'
entity_data: item.entity_data ? item.entity_data
})); : {};
return {
...item,
item_data: safeEntityData,
entity_data: item.entity_data // Keep original for debugging
};
});
// Check for photo submissions (using array query to avoid 406) // Check for photo submissions (using array query to avoid 406)
const { data: photoData, error: photoError } = await supabase const { data: photoData, error: photoError } = await supabase

View File

@@ -30,9 +30,12 @@ export function ValidationSummary({ item, onValidationChange, compact = false, v
// Helper to extract the correct entity ID based on entity type // Helper to extract the correct entity ID based on entity type
const getEntityId = ( const getEntityId = (
itemType: string, itemType: string,
itemData: SubmissionItemData, itemData: SubmissionItemData | null | undefined,
fallbackId?: string fallbackId?: string
): string | undefined => { ): string | undefined => {
// Guard against null/undefined itemData
if (!itemData) return fallbackId;
// Try entity-specific ID fields first // Try entity-specific ID fields first
const entityIdField = `${itemType}_id`; const entityIdField = `${itemType}_id`;
const typedData = itemData as unknown as Record<string, unknown>; const typedData = itemData as unknown as Record<string, unknown>;
@@ -84,7 +87,7 @@ export function ValidationSummary({ item, onValidationChange, compact = false, v
const result = await validateEntityData( const result = await validateEntityData(
item.item_type as ValidEntityType, item.item_type as ValidEntityType,
{ {
...item.item_data, ...(item.item_data || {}), // Add null coalescing
id: getEntityId(item.item_type, item.item_data, item.id) id: getEntityId(item.item_type, item.item_data, item.id)
} }
); );

View File

@@ -17,6 +17,9 @@ export function RichParkDisplay({ data, actionType, showAllFields = true }: Rich
const [propertyOwner, setPropertyOwner] = useState<string | null>(null); const [propertyOwner, setPropertyOwner] = useState<string | null>(null);
useEffect(() => { useEffect(() => {
// Guard against null/undefined data
if (!data) return;
const fetchRelatedData = async () => { const fetchRelatedData = async () => {
// Fetch location // Fetch location
if (data.location_id) { if (data.location_id) {

View File

@@ -22,6 +22,9 @@ export function RichRideDisplay({ data, actionType, showAllFields = true }: Rich
const [showTechnical, setShowTechnical] = useState(false); const [showTechnical, setShowTechnical] = useState(false);
useEffect(() => { useEffect(() => {
// Guard against null/undefined data
if (!data) return;
const fetchRelatedData = async () => { const fetchRelatedData = async () => {
if (data.park_id) { if (data.park_id) {
const { data: parkData } = await supabase const { data: parkData } = await supabase