Fix photo submission approval

This commit is contained in:
gpt-engineer-app[bot]
2025-10-01 20:56:02 +00:00
parent 2324d276e4
commit ce225dc914

View File

@@ -499,6 +499,85 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
fetchItems(activeEntityFilter, activeStatusFilter);
return;
}
// Handle photo submissions - create photos records when approved
if (action === 'approved' && item.type === 'content_submission' && item.submission_type === 'photo') {
console.log('Processing photo submission approval:', item.content);
try {
// Extract photos array - handle both nested paths
const photosArray = item.content?.photos || item.content?.content?.photos;
const entityId = item.content?.entity_id || item.content?.park_id || item.content?.ride_id || item.content?.company_id;
const entityType = item.content?.context || item.content?.entity_type ||
(item.content?.park_id ? 'park' :
item.content?.ride_id ? 'ride' :
item.content?.company_id ? 'company' : null);
if (!photosArray || !Array.isArray(photosArray) || photosArray.length === 0) {
throw new Error('No photos found in submission');
}
if (!entityId || !entityType) {
throw new Error('Invalid entity information in photo submission');
}
console.log('Creating photo records:', { photosArray, entityId, entityType });
// Create photo records in the photos table
const photoRecords = photosArray.map((photo, index) => ({
entity_id: entityId,
entity_type: entityType,
cloudflare_image_id: photo.imageId || photo.cloudflare_image_id,
cloudflare_image_url: photo.url || photo.cloudflare_image_url,
title: photo.title,
caption: photo.caption,
date_taken: photo.date,
order_index: photo.order ?? index,
submission_id: item.id,
submitted_by: item.user_id,
approved_by: user?.id,
approved_at: new Date().toISOString(),
}));
const { data: createdPhotos, error: photoError } = await supabase
.from('photos')
.insert(photoRecords)
.select();
if (photoError) {
console.error('Failed to create photo records:', photoError);
throw new Error(`Failed to create photos: ${photoError.message}`);
}
console.log('Created photo records:', createdPhotos);
// Update submission status
const { error: updateError } = await supabase
.from('content_submissions')
.update({
status: 'approved',
reviewer_id: user?.id,
reviewed_at: new Date().toISOString(),
reviewer_notes: moderatorNotes
})
.eq('id', item.id);
if (updateError) throw updateError;
toast({
title: "Photos Approved",
description: `Successfully approved ${createdPhotos.length} photo(s)`,
});
// Refresh the queue
fetchItems(activeEntityFilter, activeStatusFilter);
return;
} catch (error: any) {
console.error('Error processing photo approval:', error);
throw error;
}
}
// Standard moderation flow for other items
const table = item.type === 'review' ? 'reviews' : 'content_submissions';