From 65c3e92c70c7d9aa95206f5542e90a2744cca163 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Wed, 1 Oct 2025 20:28:34 +0000 Subject: [PATCH] Fix image upload and moderation display --- src/components/moderation/ModerationQueue.tsx | 128 +++++++++++++++++- src/lib/companyHelpers.ts | 25 +++- 2 files changed, 149 insertions(+), 4 deletions(-) diff --git a/src/components/moderation/ModerationQueue.tsx b/src/components/moderation/ModerationQueue.tsx index 660c3a5d..4a9e4019 100644 --- a/src/components/moderation/ModerationQueue.tsx +++ b/src/components/moderation/ModerationQueue.tsx @@ -1210,13 +1210,137 @@ export const ModerationQueue = forwardRef((props, ref) => { + ) : (item.submission_type === 'manufacturer' || + item.submission_type === 'designer' || + item.submission_type === 'operator' || + item.submission_type === 'property_owner') ? ( +
+
+ + {item.submission_type} + + + {item.content.action === 'create' ? 'New' : 'Edit'} + +
+ +
+ {/* Basic Information */} +
+
+ Name: + {item.content.name} +
+
+ Slug: + {item.content.slug} +
+ {item.content.person_type && ( +
+ Type: + {item.content.person_type} +
+ )} + {item.content.description && ( +
+ Description: +

{item.content.description}

+
+ )} + {item.content.website_url && ( +
+ Website: + + {item.content.website_url} + +
+ )} + {item.content.founded_year && ( +
+ Founded: + {item.content.founded_year} +
+ )} + {item.content.headquarters_location && ( +
+ Headquarters: + {item.content.headquarters_location} +
+ )} +
+ + {/* Images */} + {item.content.images?.uploaded && item.content.images.uploaded.length > 0 && ( +
+
Images ({item.content.images.uploaded.length}):
+
+ {item.content.images.uploaded.map((image: any, index: number) => ( +
+
{ + setSelectedPhotos(item.content.images.uploaded.map((img: any, i: number) => ({ + id: `${item.id}-${i}`, + url: img.url, + filename: `Image ${i + 1}`, + caption: img.caption + }))); + setSelectedPhotoIndex(index); + setPhotoModalOpen(true); + }}> + {image.caption { + console.error('Failed to load company image:', image.url); + (e.target as HTMLImageElement).style.display = 'none'; + }} + /> +
+ +
+
+ {image.caption && ( +

{image.caption}

+ )} +
+ ))} +
+ + {/* Image Role Assignments */} + {(item.content.images.banner || item.content.images.card) && ( +
+
Image Assignments:
+ {item.content.images.banner !== undefined && ( +
+ Banner: + + {item.content.images.banner === null ? 'None' : `Image ${item.content.images.banner + 1}`} + +
+ )} + {item.content.images.card !== undefined && ( +
+ Card: + + {item.content.images.card === null ? 'None' : `Image ${item.content.images.card + 1}`} + +
+ )} +
+ )} +
+ )} +
+
) : (
- Type: {item.content.submission_type} + Type: {item.submission_type}
-                          {JSON.stringify(item.content.content, null, 2)}
+                          {JSON.stringify(item.content, null, 2)}
                         
)} diff --git a/src/lib/companyHelpers.ts b/src/lib/companyHelpers.ts index bee6e59c..77871e32 100644 --- a/src/lib/companyHelpers.ts +++ b/src/lib/companyHelpers.ts @@ -1,5 +1,6 @@ import { supabase } from '@/integrations/supabase/client'; import { ImageAssignments } from '@/components/upload/EntityMultiImageUploader'; +import { uploadPendingImages } from './imageUploadHelper'; export interface CompanyFormData { name: string; @@ -17,6 +18,16 @@ export async function submitCompanyCreation( companyType: 'manufacturer' | 'designer' | 'operator' | 'property_owner', userId: string ) { + // Upload any pending local images first + let processedImages = data.images; + if (data.images?.uploaded && data.images.uploaded.length > 0) { + const uploadedImages = await uploadPendingImages(data.images.uploaded); + processedImages = { + ...data.images, + uploaded: uploadedImages + }; + } + // All users submit for moderation const { error } = await supabase .from('content_submissions') @@ -33,7 +44,7 @@ export async function submitCompanyCreation( founded_year: data.founded_year, headquarters_location: data.headquarters_location, company_type: companyType, - images: data.images as any // Include image assignments in submission + images: processedImages as any // Include uploaded image assignments in submission } as any, status: 'pending' }]); @@ -57,6 +68,16 @@ export async function submitCompanyUpdate( if (fetchError) throw fetchError; if (!existingCompany) throw new Error('Company not found'); + // Upload any pending local images first + let processedImages = data.images; + if (data.images?.uploaded && data.images.uploaded.length > 0) { + const uploadedImages = await uploadPendingImages(data.images.uploaded); + processedImages = { + ...data.images, + uploaded: uploadedImages + }; + } + // All users submit for moderation const { error } = await supabase .from('content_submissions') @@ -73,7 +94,7 @@ export async function submitCompanyUpdate( website_url: data.website_url, founded_year: data.founded_year, headquarters_location: data.headquarters_location, - images: data.images as any // Include image role assignments in submission + images: processedImages as any // Include uploaded image role assignments in submission } as any, status: 'pending' }]);