mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 08:11:13 -05:00
Visual edit in Lovable
This commit is contained in:
@@ -13,7 +13,6 @@ import { supabase } from '@/integrations/supabase/client';
|
|||||||
import { toast } from '@/hooks/use-toast';
|
import { toast } from '@/hooks/use-toast';
|
||||||
import { PhotoUpload } from '@/components/upload/PhotoUpload';
|
import { PhotoUpload } from '@/components/upload/PhotoUpload';
|
||||||
import { StarRating } from './StarRating';
|
import { StarRating } from './StarRating';
|
||||||
|
|
||||||
const reviewSchema = z.object({
|
const reviewSchema = z.object({
|
||||||
rating: z.number().min(0.5).max(5).multipleOf(0.5),
|
rating: z.number().min(0.5).max(5).multipleOf(0.5),
|
||||||
title: z.string().optional(),
|
title: z.string().optional(),
|
||||||
@@ -22,37 +21,40 @@ const reviewSchema = z.object({
|
|||||||
wait_time_minutes: z.number().optional(),
|
wait_time_minutes: z.number().optional(),
|
||||||
photos: z.array(z.string()).optional()
|
photos: z.array(z.string()).optional()
|
||||||
});
|
});
|
||||||
|
|
||||||
type ReviewFormData = z.infer<typeof reviewSchema>;
|
type ReviewFormData = z.infer<typeof reviewSchema>;
|
||||||
|
|
||||||
interface ReviewFormProps {
|
interface ReviewFormProps {
|
||||||
entityType: 'park' | 'ride';
|
entityType: 'park' | 'ride';
|
||||||
entityId: string;
|
entityId: string;
|
||||||
entityName: string;
|
entityName: string;
|
||||||
onReviewSubmitted: () => void;
|
onReviewSubmitted: () => void;
|
||||||
}
|
}
|
||||||
|
export function ReviewForm({
|
||||||
export function ReviewForm({ entityType, entityId, entityName, onReviewSubmitted }: ReviewFormProps) {
|
entityType,
|
||||||
const { user } = useAuth();
|
entityId,
|
||||||
|
entityName,
|
||||||
|
onReviewSubmitted
|
||||||
|
}: ReviewFormProps) {
|
||||||
|
const {
|
||||||
|
user
|
||||||
|
} = useAuth();
|
||||||
const [rating, setRating] = useState(0);
|
const [rating, setRating] = useState(0);
|
||||||
const [submitting, setSubmitting] = useState(false);
|
const [submitting, setSubmitting] = useState(false);
|
||||||
const [photos, setPhotos] = useState<string[]>([]);
|
const [photos, setPhotos] = useState<string[]>([]);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
register,
|
register,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
reset,
|
reset,
|
||||||
setValue,
|
setValue,
|
||||||
formState: { errors }
|
formState: {
|
||||||
|
errors
|
||||||
|
}
|
||||||
} = useForm<ReviewFormData>({
|
} = useForm<ReviewFormData>({
|
||||||
resolver: zodResolver(reviewSchema)
|
resolver: zodResolver(reviewSchema)
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleRatingChange = (selectedRating: number) => {
|
const handleRatingChange = (selectedRating: number) => {
|
||||||
setRating(selectedRating);
|
setRating(selectedRating);
|
||||||
setValue('rating', selectedRating);
|
setValue('rating', selectedRating);
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSubmit = async (data: ReviewFormData) => {
|
const onSubmit = async (data: ReviewFormData) => {
|
||||||
if (!user) {
|
if (!user) {
|
||||||
toast({
|
toast({
|
||||||
@@ -62,7 +64,6 @@ export function ReviewForm({ entityType, entityId, entityName, onReviewSubmitted
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setSubmitting(true);
|
setSubmitting(true);
|
||||||
try {
|
try {
|
||||||
const reviewData = {
|
const reviewData = {
|
||||||
@@ -74,20 +75,20 @@ export function ReviewForm({ entityType, entityId, entityName, onReviewSubmitted
|
|||||||
wait_time_minutes: data.wait_time_minutes || null,
|
wait_time_minutes: data.wait_time_minutes || null,
|
||||||
photos: photos.length > 0 ? photos : null,
|
photos: photos.length > 0 ? photos : null,
|
||||||
moderation_status: 'pending' as const,
|
moderation_status: 'pending' as const,
|
||||||
...(entityType === 'park' ? { park_id: entityId } : { ride_id: entityId })
|
...(entityType === 'park' ? {
|
||||||
|
park_id: entityId
|
||||||
|
} : {
|
||||||
|
ride_id: entityId
|
||||||
|
})
|
||||||
};
|
};
|
||||||
|
const {
|
||||||
const { error } = await supabase
|
error
|
||||||
.from('reviews')
|
} = await supabase.from('reviews').insert([reviewData]);
|
||||||
.insert([reviewData]);
|
|
||||||
|
|
||||||
if (error) throw error;
|
if (error) throw error;
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: "Review Submitted!",
|
title: "Review Submitted!",
|
||||||
description: "Thank you for your review. It will be published after moderation."
|
description: "Thank you for your review. It will be published after moderation."
|
||||||
});
|
});
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
setRating(0);
|
setRating(0);
|
||||||
setPhotos([]);
|
setPhotos([]);
|
||||||
@@ -103,10 +104,8 @@ export function ReviewForm({ entityType, entityId, entityName, onReviewSubmitted
|
|||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return (
|
return <Card>
|
||||||
<Card>
|
|
||||||
<CardContent className="p-6 text-center">
|
<CardContent className="p-6 text-center">
|
||||||
<Star className="w-12 h-12 text-muted-foreground mx-auto mb-4" />
|
<Star className="w-12 h-12 text-muted-foreground mx-auto mb-4" />
|
||||||
<h3 className="text-lg font-semibold mb-2">Share Your Experience</h3>
|
<h3 className="text-lg font-semibold mb-2">Share Your Experience</h3>
|
||||||
@@ -117,12 +116,9 @@ export function ReviewForm({ entityType, entityId, entityName, onReviewSubmitted
|
|||||||
Sign In to Review
|
Sign In to Review
|
||||||
</Button>
|
</Button>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>;
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
return <Card>
|
||||||
return (
|
|
||||||
<Card>
|
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle>Write a Review for {entityName}</CardTitle>
|
<CardTitle>Write a Review for {entityName}</CardTitle>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
@@ -131,86 +127,39 @@ export function ReviewForm({ entityType, entityId, entityName, onReviewSubmitted
|
|||||||
{/* Rating */}
|
{/* Rating */}
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label>Rating *</Label>
|
<Label>Rating *</Label>
|
||||||
<StarRating
|
<StarRating rating={rating} onChange={handleRatingChange} interactive={true} showLabel={true} size="lg" />
|
||||||
rating={rating}
|
{errors.rating && <p className="text-sm text-destructive">Please select a rating</p>}
|
||||||
onChange={handleRatingChange}
|
|
||||||
interactive={true}
|
|
||||||
showLabel={true}
|
|
||||||
size="lg"
|
|
||||||
/>
|
|
||||||
{errors.rating && (
|
|
||||||
<p className="text-sm text-destructive">Please select a rating</p>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Title */}
|
{/* Title */}
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="title">Review Title</Label>
|
<Label htmlFor="title">Review Title</Label>
|
||||||
<Input
|
<Input id="title" placeholder="Give your review a title" {...register('title')} />
|
||||||
id="title"
|
|
||||||
placeholder="Give your review a title"
|
|
||||||
{...register('title')}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Content */}
|
{/* Content */}
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="content">Your Review *</Label>
|
<Label htmlFor="content">Your Review *</Label>
|
||||||
<Textarea
|
<Textarea id="content" placeholder="Share your experience..." rows={4} {...register('content')} />
|
||||||
id="content"
|
{errors.content && <p className="text-sm text-destructive">{errors.content.message}</p>}
|
||||||
placeholder="Share your experience..."
|
|
||||||
rows={4}
|
|
||||||
{...register('content')}
|
|
||||||
/>
|
|
||||||
{errors.content && (
|
|
||||||
<p className="text-sm text-destructive">{errors.content.message}</p>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Visit Date */}
|
{/* Visit Date */}
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="visit_date">Visit Date</Label>
|
<Label htmlFor="visit_date">Visit Date</Label>
|
||||||
<Input
|
<Input id="visit_date" type="date" {...register('visit_date')} />
|
||||||
id="visit_date"
|
|
||||||
type="date"
|
|
||||||
{...register('visit_date')}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Wait Time (for rides) */}
|
{/* Wait Time (for rides) */}
|
||||||
{entityType === 'ride' && (
|
{entityType === 'ride' && <div className="space-y-2">
|
||||||
<div className="space-y-2">
|
|
||||||
<Label htmlFor="wait_time">Wait Time (minutes)</Label>
|
<Label htmlFor="wait_time">Wait Time (minutes)</Label>
|
||||||
<Input
|
<Input id="wait_time" type="number" min="0" placeholder="How long did you wait?" {...register('wait_time_minutes', {
|
||||||
id="wait_time"
|
valueAsNumber: true
|
||||||
type="number"
|
})} />
|
||||||
min="0"
|
</div>}
|
||||||
placeholder="How long did you wait?"
|
|
||||||
{...register('wait_time_minutes', { valueAsNumber: true })}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Photo Upload */}
|
{/* Photo Upload */}
|
||||||
<div className="space-y-2">
|
|
||||||
<Label>Photos (Optional)</Label>
|
|
||||||
<PhotoUpload
|
|
||||||
maxFiles={5}
|
|
||||||
onUploadComplete={setPhotos}
|
|
||||||
onError={(error) => {
|
|
||||||
toast({
|
|
||||||
title: "Upload Error",
|
|
||||||
description: error,
|
|
||||||
variant: "destructive"
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
variant="compact"
|
|
||||||
className="max-w-full"
|
|
||||||
/>
|
|
||||||
<p className="text-xs text-muted-foreground">
|
|
||||||
Add up to 5 photos to share your experience
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Button type="submit" disabled={submitting} className="w-full">
|
<Button type="submit" disabled={submitting} className="w-full">
|
||||||
<Send className="w-4 h-4 mr-2" />
|
<Send className="w-4 h-4 mr-2" />
|
||||||
@@ -218,6 +167,5 @@ export function ReviewForm({ entityType, entityId, entityName, onReviewSubmitted
|
|||||||
</Button>
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>;
|
||||||
);
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user