'use client' import { useEffect, useState } from 'react' import { useSearchParams } from 'next/navigation' import { Star } from 'lucide-react' const API_BASE = process.env.NEXT_PUBLIC_API_URL ?? 'http://localhost:4000/api/v1' interface ReviewInfo { reservationId: string companyName: string companyLogoUrl: string | null vehicle: string vehiclePhoto: string | null } function StarRating({ value, onChange, label }: { value: number; onChange: (v: number) => void; label: string }) { const [hovered, setHovered] = useState(0) return (

{label}

{[1, 2, 3, 4, 5].map((n) => ( ))}
) } export default function ReviewPage() { const params = useSearchParams() const token = params.get('token') ?? '' const [info, setInfo] = useState(null) const [loadState, setLoadState] = useState<'loading' | 'ready' | 'already_reviewed' | 'invalid'>('loading') const [overall, setOverall] = useState(0) const [vehicle, setVehicle] = useState(0) const [service, setService] = useState(0) const [comment, setComment] = useState('') const [submitState, setSubmitState] = useState<'idle' | 'submitting' | 'done' | 'error'>('idle') const [errorMsg, setErrorMsg] = useState('') useEffect(() => { if (!token) { setLoadState('invalid'); return } fetch(`${API_BASE}/marketplace/review/${token}`) .then(async (r) => { if (r.status === 409) { setLoadState('already_reviewed'); return } if (!r.ok) { setLoadState('invalid'); return } const json = await r.json() setInfo(json.data) setLoadState('ready') }) .catch(() => setLoadState('invalid')) }, [token]) async function handleSubmit(e: React.FormEvent) { e.preventDefault() if (overall === 0) { setErrorMsg('Please select an overall rating.'); return } setSubmitState('submitting') setErrorMsg('') try { const res = await fetch(`${API_BASE}/marketplace/review/${token}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ overallRating: overall, vehicleRating: vehicle || undefined, serviceRating: service || undefined, comment: comment.trim() || undefined, }), }) if (res.status === 409) { setLoadState('already_reviewed'); return } if (!res.ok) { const json = await res.json() throw new Error(json.message ?? 'Something went wrong.') } setSubmitState('done') } catch (err: any) { setSubmitState('error') setErrorMsg(err.message ?? 'Something went wrong. Please try again.') } } if (loadState === 'loading') { return (

Loading…

) } if (loadState === 'invalid') { return (

Link not found

This review link is invalid or has already been used.

) } if (loadState === 'already_reviewed') { return (

Already reviewed

You have already submitted a review for this rental. Thank you!

) } if (submitState === 'done') { return (

Thank you!

Your review has been submitted and will be visible on {info?.companyName}'s profile.

) } return (
{/* Header */}
{info?.vehiclePhoto ? ( // eslint-disable-next-line @next/next/no-img-element {info.vehicle} ) : (
)}

{info?.companyName}

{info?.vehicle}

How was your experience?