mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 14:11:13 -05:00
Fix image upload and moderation display
This commit is contained in:
@@ -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'
|
||||
}]);
|
||||
|
||||
Reference in New Issue
Block a user