From 5d3ead55caf42a9446ccb36b6f180611fd0de6ca Mon Sep 17 00:00:00 2001 From: Rahaf Date: Sun, 26 Apr 2026 13:46:30 +0300 Subject: [PATCH] Added API for rating --- app/components/ratings/PropertyRatingForm.js | 317 +++ app/components/ratings/PropertyRatingList.js | 286 +++ app/components/ratings/RatingForm.js | 216 -- app/components/ratings/RatingList.js | 149 -- app/components/ratings/StarRating.js | 200 +- app/property/[id]/PropertyDetail.js | 2174 ++++++++++-------- app/utils/ratings.js | 433 ++-- 7 files changed, 2223 insertions(+), 1552 deletions(-) create mode 100644 app/components/ratings/PropertyRatingForm.js create mode 100644 app/components/ratings/PropertyRatingList.js delete mode 100644 app/components/ratings/RatingForm.js delete mode 100644 app/components/ratings/RatingList.js diff --git a/app/components/ratings/PropertyRatingForm.js b/app/components/ratings/PropertyRatingForm.js new file mode 100644 index 0000000..c2384a3 --- /dev/null +++ b/app/components/ratings/PropertyRatingForm.js @@ -0,0 +1,317 @@ +// import { useState } from 'react'; +// import { motion } from 'framer-motion'; +// import { Star, Edit2, X, Check, Clock } from 'lucide-react'; +// import StarRating from './StarRating.js'; +// import toast, { Toaster } from 'react-hot-toast'; +// import { rateProperty, rateCustomer, getUserPropertyRating, canRateProperty } from '../../utils/ratings.js'; + +// const RatingForm = ({ +// propertyId, +// userId, +// propertyOwner = false, +// initialRating = 0, +// initialComment = '', +// onSubmitSuccess +// }) => { +// const [rating, setRating] = useState(initialRating); +// const [comment, setComment] = useState(initialComment); +// const [loading, setLoading] = useState(false); +// const [showForm, setShowForm] = useState(false); +// const [userRating, setUserRating] = useState(null); + +// // Check if user has already rated +// useState(() => { +// async function fetchUserRating() { +// try { +// const rating = await getUserPropertyRating(propertyId, userId); +// if (rating) { +// setUserRating(rating); +// setRating(rating.rating); +// setComment(rating.comment || ''); +// } +// } catch (error) { +// console.error('[RatingForm] Failed to fetch user rating:', error); +// } +// } + +// if (propertyId && userId) { +// fetchUserRating(); +// } +// }, [propertyId, userId]); + +// const handleSubmit = async (e) => { +// e.preventDefault(); + +// if (!rating) { +// toast.error('يرجى إعطاء تقييم من 1 إلى 5 نجوم'); +// return; +// } + +// setLoading(true); + +// try { +// const ratingData = { +// propertyId, +// customerId: userId, +// rating, +// comment: comment.trim() || null +// }; + +// await rateProperty(ratingData); + +// toast.success('تم إرسال التقييم بنجاح!'); + +// // Reset form +// setRating(0); +// setComment(''); +// setShowForm(false); + +// if (onSubmitSuccess) { +// onSubmitSuccess(); +// } +// } catch (error) { +// console.error('[RatingForm] Failed to submit rating:', error); +// toast.error('حدث خطأ أثناء إرسال التقييم. يرجى المحاولة مرة أخرى.'); +// } finally { +// setLoading(false); +// } +// }; + +// const handleEdit = () => { +// setShowForm(true); +// setRating(userRating?.rating || 0); +// setComment(userRating?.comment || ''); +// }; + +// const handleCancel = () => { +// setShowForm(false); +// setRating(userRating?.rating || 0); +// setComment(userRating?.comment || ''); +// }; + +// if (!propertyId || !userId) { +// return null; +// } + +// return ( +//
+// + +// {/* Display existing rating */} +// {userRating && !showForm && ( +// +//
+//
+// +// {userRating.rating} +// من 5 +//
+// +//
+ +// {userRating.comment && ( +//
+// "{userRating.comment}" +//
+// )} + +//
+// +// {userRating.createdAt ? new Date(userRating.createdAt).toLocaleDateString('ar-SA') : ''} +//
+//
+// )} + +// {/* Rating form */} +// {showForm && ( +// +//
+//
+// +//
+// +// {rating || '1'} +// /5 +//
+//
+ +//
+// +//