mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 10:31:13 -05:00
Fix null safety issues
This commit is contained in:
@@ -56,12 +56,19 @@ export const SubmissionItemsList = memo(function SubmissionItemsList({
|
||||
|
||||
if (itemsError) throw itemsError;
|
||||
|
||||
// Transform to expected format
|
||||
const transformedItems = (itemsData || []).map((item: any) => ({
|
||||
// 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: item.entity_data || {},
|
||||
entity_data: item.entity_data
|
||||
}));
|
||||
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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user