mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 19:51:12 -05:00
Refactor: Make photo upload reusable
This commit is contained in:
@@ -13,18 +13,21 @@ import { supabase } from '@/integrations/supabase/client';
|
||||
import { useAuth } from '@/hooks/useAuth';
|
||||
import { useToast } from '@/hooks/use-toast';
|
||||
import { Camera, CheckCircle, AlertCircle, Info } from 'lucide-react';
|
||||
|
||||
interface UppyPhotoSubmissionUploadProps {
|
||||
onSubmissionComplete?: () => void;
|
||||
parkId?: string;
|
||||
rideId?: string;
|
||||
}
|
||||
import { UppyPhotoSubmissionUploadProps } from '@/types/submissions';
|
||||
|
||||
export function UppyPhotoSubmissionUpload({
|
||||
onSubmissionComplete,
|
||||
entityId,
|
||||
entityType,
|
||||
parentId,
|
||||
// Legacy props (deprecated)
|
||||
parkId,
|
||||
rideId,
|
||||
}: UppyPhotoSubmissionUploadProps) {
|
||||
// Support legacy props
|
||||
const finalEntityId = entityId || rideId || parkId || '';
|
||||
const finalEntityType = entityType || (rideId ? 'ride' : parkId ? 'park' : 'ride');
|
||||
const finalParentId = parentId || (rideId ? parkId : undefined);
|
||||
const [title, setTitle] = useState('');
|
||||
const [photos, setPhotos] = useState<PhotoWithCaption[]>([]);
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
@@ -193,10 +196,14 @@ export function UppyPhotoSubmissionUpload({
|
||||
date: photo.date?.toISOString(),
|
||||
order: index,
|
||||
})),
|
||||
// NEW STRUCTURE: context as string, IDs at top level
|
||||
context: rideId ? 'ride' : parkId ? 'park' : undefined,
|
||||
ride_id: rideId,
|
||||
park_id: parkId,
|
||||
// NEW STRUCTURE: Generic entity references
|
||||
context: finalEntityType,
|
||||
entity_id: finalEntityId,
|
||||
// Legacy structure for backwards compatibility
|
||||
...(finalEntityType === 'ride' && { ride_id: finalEntityId }),
|
||||
...(finalEntityType === 'park' && { park_id: finalEntityId }),
|
||||
...(finalParentId && finalEntityType === 'ride' && { park_id: finalParentId }),
|
||||
...(['manufacturer', 'operator', 'designer', 'property_owner'].includes(finalEntityType) && { company_id: finalEntityId }),
|
||||
},
|
||||
};
|
||||
|
||||
@@ -249,8 +256,12 @@ export function UppyPhotoSubmissionUpload({
|
||||
|
||||
const metadata = {
|
||||
submissionType: 'photo',
|
||||
parkId,
|
||||
rideId,
|
||||
entityId: finalEntityId,
|
||||
entityType: finalEntityType,
|
||||
parentId: finalParentId,
|
||||
// Legacy support
|
||||
parkId: finalEntityType === 'park' ? finalEntityId : finalParentId,
|
||||
rideId: finalEntityType === 'ride' ? finalEntityId : undefined,
|
||||
userId: user?.id,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user