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;
// Transform to expected format
const transformedItems = (itemsData || []).map((item: any) => ({
...item,
item_data: item.entity_data || {},
entity_data: item.entity_data
}));
// Transform to expected format with better null handling
const transformedItems = (itemsData || []).map((item: any) => {
// Ensure entity_data is at least an empty object, never null
const safeEntityData = item.entity_data && typeof item.entity_data === 'object'
? 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)
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
const getEntityId = (
itemType: string,
itemData: SubmissionItemData,
itemData: SubmissionItemData | null | undefined,
fallbackId?: string
): string | undefined => {
// Guard against null/undefined itemData
if (!itemData) return fallbackId;
// Try entity-specific ID fields first
const entityIdField = `${itemType}_id`;
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(
item.item_type as ValidEntityType,
{
...item.item_data,
...(item.item_data || {}), // Add null coalescing
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);
useEffect(() => {
// Guard against null/undefined data
if (!data) return;
const fetchRelatedData = async () => {
// Fetch location
if (data.location_id) {

View File

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