From bccaebc6d60174d418bf94617d77fd509e046531 Mon Sep 17 00:00:00 2001
From: "gpt-engineer-app[bot]"
<159125892+gpt-engineer-app[bot]@users.noreply.github.com>
Date: Sun, 2 Nov 2025 20:39:22 +0000
Subject: [PATCH] Fix: Block photo uploads on entity edits
---
src/components/admin/ParkForm.tsx | 13 ++
src/components/admin/RideForm.tsx | 13 ++
.../upload/EntityMultiImageUploader.tsx | 42 ++++-
src/components/upload/EntityPhotoGallery.tsx | 7 +-
src/lib/entitySubmissionHelpers.ts | 149 +++++-------------
5 files changed, 106 insertions(+), 118 deletions(-)
diff --git a/src/components/admin/ParkForm.tsx b/src/components/admin/ParkForm.tsx
index 7f98c1a4..052cfd5f 100644
--- a/src/components/admin/ParkForm.tsx
+++ b/src/components/admin/ParkForm.tsx
@@ -200,6 +200,19 @@ export function ParkForm({ onSubmit, onCancel, initialData, isEditing = false }:
const handleFormSubmit = async (data: ParkFormData) => {
try {
+ // CRITICAL: Block new photo uploads on edits
+ if (isEditing && data.images?.uploaded) {
+ const hasNewPhotos = data.images.uploaded.some(img => img.isLocal);
+ if (hasNewPhotos) {
+ toast({
+ variant: 'destructive',
+ title: 'Validation Error',
+ description: 'New photos cannot be added during edits. Please remove new photos or use the photo gallery.'
+ });
+ return;
+ }
+ }
+
// Build composite submission if new entities were created
const submissionContent: any = {
park: data,
diff --git a/src/components/admin/RideForm.tsx b/src/components/admin/RideForm.tsx
index 16daecf9..083792dc 100644
--- a/src/components/admin/RideForm.tsx
+++ b/src/components/admin/RideForm.tsx
@@ -264,6 +264,19 @@ export function RideForm({ onSubmit, onCancel, initialData, isEditing = false }:
const handleFormSubmit = async (data: RideFormData) => {
try {
+ // CRITICAL: Block new photo uploads on edits
+ if (isEditing && data.images?.uploaded) {
+ const hasNewPhotos = data.images.uploaded.some(img => img.isLocal);
+ if (hasNewPhotos) {
+ toast({
+ variant: 'destructive',
+ title: 'Validation Error',
+ description: 'New photos cannot be added during edits. Please remove new photos or use the photo gallery.'
+ });
+ return;
+ }
+ }
+
// Validate coaster stats
if (coasterStats && coasterStats.length > 0) {
const statsValidation = validateCoasterStats(coasterStats);
diff --git a/src/components/upload/EntityMultiImageUploader.tsx b/src/components/upload/EntityMultiImageUploader.tsx
index 120b8a75..ceee256e 100644
--- a/src/components/upload/EntityMultiImageUploader.tsx
+++ b/src/components/upload/EntityMultiImageUploader.tsx
@@ -13,6 +13,7 @@ import { DragDropZone } from './DragDropZone';
import { supabase } from '@/integrations/supabase/client';
import { toast } from '@/hooks/use-toast';
import { Skeleton } from '@/components/ui/skeleton';
+import { Alert, AlertDescription } from '@/components/ui/alert';
import { getErrorMessage } from '@/lib/errorHandler';
import { logger } from '@/lib/logger';
@@ -49,7 +50,8 @@ export function EntityMultiImageUploader({
currentBannerUrl,
currentCardUrl
}: EntityMultiImageUploaderProps) {
- const maxImages = mode === 'create' ? 5 : 3;
+ const maxImages = mode === 'create' ? 5 : 0; // No uploads allowed in edit mode
+ const canUpload = mode === 'create';
const [loadingPhotos, setLoadingPhotos] = useState(false);
// Fetch existing photos when in edit mode
@@ -119,6 +121,16 @@ export function EntityMultiImageUploader({
};
const handleFilesAdded = (files: File[]) => {
+ // Block uploads entirely in edit mode
+ if (!canUpload) {
+ toast({
+ title: 'Upload Not Allowed',
+ description: 'Photos cannot be added during edits. Use the photo gallery to submit additional photos.',
+ variant: 'destructive',
+ });
+ return;
+ }
+
const currentCount = value.uploaded.length;
const availableSlots = maxImages - currentCount;
@@ -331,8 +343,18 @@ export function EntityMultiImageUploader({
);
}
- // Empty state: show large drag & drop zone
+ // Empty state: show large drag & drop zone (create only) or message (edit)
if (value.uploaded.length === 0) {
+ if (mode === 'edit') {
+ return (
+
• Right-click images to set as banner or card
• Images will be uploaded when you submit the form
- {mode === 'edit' &&• No existing photos found for this entity
}Photos submitted here go through a separate review process
+