diff --git a/src/components/moderation/ModerationQueue.tsx b/src/components/moderation/ModerationQueue.tsx index 00167d3e..46e2f2a9 100644 --- a/src/components/moderation/ModerationQueue.tsx +++ b/src/components/moderation/ModerationQueue.tsx @@ -288,6 +288,35 @@ export function ModerationQueue() { setActionLoading(item.id); try { + // Step 1: Extract photo IDs from the submission content + const photoIds: string[] = []; + if (item.content?.photos && Array.isArray(item.content.photos)) { + for (const photo of item.content.photos) { + if (photo.imageId) { + photoIds.push(photo.imageId); + } + } + } + + // Step 2: Delete photos from Cloudflare Images (if any) + if (photoIds.length > 0) { + const deletePromises = photoIds.map(async (imageId) => { + try { + await supabase.functions.invoke('upload-image', { + method: 'DELETE', + body: { imageId } + }); + } catch (deleteError) { + console.warn(`Failed to delete photo ${imageId} from Cloudflare:`, deleteError); + // Continue with other deletions - don't fail the entire operation + } + }); + + // Execute all photo deletions in parallel + await Promise.allSettled(deletePromises); + } + + // Step 3: Delete the submission from the database const { error } = await supabase .from('content_submissions') .delete() @@ -297,7 +326,7 @@ export function ModerationQueue() { toast({ title: "Submission deleted", - description: "The submission has been permanently deleted", + description: `The submission and ${photoIds.length > 0 ? `${photoIds.length} associated photo(s) have` : 'has'} been permanently deleted`, }); // Remove item from the current view