Fix: Block photo uploads on entity edits

This commit is contained in:
gpt-engineer-app[bot]
2025-11-02 20:39:22 +00:00
parent bb951e637f
commit bccaebc6d6
5 changed files with 106 additions and 118 deletions

View File

@@ -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 (
<Alert>
<AlertDescription>
No existing photos found. Photos can only be added during entity creation. Use the photo gallery to submit additional photos after creation.
</AlertDescription>
</Alert>
);
}
return (
<div className="space-y-4">
<DragDropZone
@@ -344,22 +366,30 @@ export function EntityMultiImageUploader({
<div className="text-sm text-muted-foreground space-y-1">
<p> Right-click images to set as banner or card</p>
<p> Images will be uploaded when you submit the form</p>
{mode === 'edit' && <p> No existing photos found for this entity</p>}
</div>
</div>
);
}
// With images: show grid + compact upload area
// With images: show grid + compact upload area (create only) or read-only (edit)
return (
<div className="space-y-4">
{/* Edit mode notice */}
{mode === 'edit' && (
<Alert>
<AlertDescription>
Photos cannot be added during edits. You can reassign banner/card roles below. Use the photo gallery to submit additional photos.
</AlertDescription>
</Alert>
)}
{/* Image Grid */}
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
{value.uploaded.map((image, index) => renderImageCard(image, index))}
</div>
{/* Compact Upload Area */}
{value.uploaded.length < maxImages && (
{/* Compact Upload Area - Create mode only */}
{canUpload && value.uploaded.length < maxImages && (
<DragDropZone
onFilesAdded={handleFilesAdded}
maxFiles={maxImages - value.uploaded.length}