diff --git a/src/components/reviews/ReviewForm.tsx b/src/components/reviews/ReviewForm.tsx index e68ff437..39fa1e90 100644 --- a/src/components/reviews/ReviewForm.tsx +++ b/src/components/reviews/ReviewForm.tsx @@ -13,7 +13,6 @@ import { supabase } from '@/integrations/supabase/client'; import { toast } from '@/hooks/use-toast'; import { PhotoUpload } from '@/components/upload/PhotoUpload'; import { StarRating } from './StarRating'; - const reviewSchema = z.object({ rating: z.number().min(0.5).max(5).multipleOf(0.5), title: z.string().optional(), @@ -22,37 +21,40 @@ const reviewSchema = z.object({ wait_time_minutes: z.number().optional(), photos: z.array(z.string()).optional() }); - type ReviewFormData = z.infer; - interface ReviewFormProps { entityType: 'park' | 'ride'; entityId: string; entityName: string; onReviewSubmitted: () => void; } - -export function ReviewForm({ entityType, entityId, entityName, onReviewSubmitted }: ReviewFormProps) { - const { user } = useAuth(); +export function ReviewForm({ + entityType, + entityId, + entityName, + onReviewSubmitted +}: ReviewFormProps) { + const { + user + } = useAuth(); const [rating, setRating] = useState(0); const [submitting, setSubmitting] = useState(false); const [photos, setPhotos] = useState([]); - const { register, handleSubmit, reset, setValue, - formState: { errors } + formState: { + errors + } } = useForm({ resolver: zodResolver(reviewSchema) }); - const handleRatingChange = (selectedRating: number) => { setRating(selectedRating); setValue('rating', selectedRating); }; - const onSubmit = async (data: ReviewFormData) => { if (!user) { toast({ @@ -62,7 +64,6 @@ export function ReviewForm({ entityType, entityId, entityName, onReviewSubmitted }); return; } - setSubmitting(true); try { const reviewData = { @@ -74,20 +75,20 @@ export function ReviewForm({ entityType, entityId, entityName, onReviewSubmitted wait_time_minutes: data.wait_time_minutes || null, photos: photos.length > 0 ? photos : null, moderation_status: 'pending' as const, - ...(entityType === 'park' ? { park_id: entityId } : { ride_id: entityId }) + ...(entityType === 'park' ? { + park_id: entityId + } : { + ride_id: entityId + }) }; - - const { error } = await supabase - .from('reviews') - .insert([reviewData]); - + const { + error + } = await supabase.from('reviews').insert([reviewData]); if (error) throw error; - toast({ title: "Review Submitted!", description: "Thank you for your review. It will be published after moderation." }); - reset(); setRating(0); setPhotos([]); @@ -103,10 +104,8 @@ export function ReviewForm({ entityType, entityId, entityName, onReviewSubmitted setSubmitting(false); } }; - if (!user) { - return ( - + return

Share Your Experience

@@ -117,12 +116,9 @@ export function ReviewForm({ entityType, entityId, entityName, onReviewSubmitted Sign In to Review
-
- ); +
; } - - return ( - + return Write a Review for {entityName} @@ -131,86 +127,39 @@ export function ReviewForm({ entityType, entityId, entityName, onReviewSubmitted {/* Rating */}
- - {errors.rating && ( -

Please select a rating

- )} + + {errors.rating &&

Please select a rating

}
{/* Title */}
- +
{/* Content */}
-