mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-24 13:31:13 -05:00
Refactor: Complete Photo System Refactor
This commit is contained in:
@@ -68,6 +68,7 @@ export function ReviewForm({
|
||||
}
|
||||
setSubmitting(true);
|
||||
try {
|
||||
// Insert review first
|
||||
const reviewData = {
|
||||
user_id: user.id,
|
||||
rating: data.rating,
|
||||
@@ -75,7 +76,6 @@ export function ReviewForm({
|
||||
content: data.content,
|
||||
visit_date: data.visit_date || null,
|
||||
wait_time_minutes: data.wait_time_minutes || null,
|
||||
photos: photos.length > 0 ? photos : null,
|
||||
moderation_status: 'pending' as const,
|
||||
...(entityType === 'park' ? {
|
||||
park_id: entityId
|
||||
@@ -83,10 +83,34 @@ export function ReviewForm({
|
||||
ride_id: entityId
|
||||
})
|
||||
};
|
||||
const {
|
||||
error
|
||||
} = await supabase.from('reviews').insert([reviewData]);
|
||||
if (error) throw error;
|
||||
|
||||
const { data: review, error: reviewError } = await supabase
|
||||
.from('reviews')
|
||||
.insert([reviewData])
|
||||
.select()
|
||||
.single();
|
||||
|
||||
if (reviewError) throw reviewError;
|
||||
|
||||
// Insert photos into review_photos table if any
|
||||
if (photos.length > 0 && review) {
|
||||
const photoRecords = photos.map((url, index) => ({
|
||||
review_id: review.id,
|
||||
cloudflare_image_id: url.split('/').slice(-2, -1)[0] || '', // Extract ID from URL
|
||||
cloudflare_image_url: url,
|
||||
order_index: index,
|
||||
}));
|
||||
|
||||
const { error: photosError } = await supabase
|
||||
.from('review_photos')
|
||||
.insert(photoRecords);
|
||||
|
||||
if (photosError) {
|
||||
console.error('Error inserting review photos:', photosError);
|
||||
// Don't throw - review is already created
|
||||
}
|
||||
}
|
||||
|
||||
toast({
|
||||
title: "Review Submitted!",
|
||||
description: "Thank you for your review. It will be published after moderation."
|
||||
|
||||
Reference in New Issue
Block a user