4.1 KiB
4.1 KiB
Review System
Function 1: ReviewPage – User Room Review Page
Objective
Allow users to write reviews for rooms they have successfully booked.
Detailed Tasks
- Route: /reviews
- API Calls:
GET /api/bookings/me → Get list of rooms user has booked. POST /api/reviews → Submit review. - Interface:
- Display list of booked rooms (name, stay dates, status)
- "Review" button (shown if room not yet reviewed)
- When clicking "Review" → open Modal:
- Input to select star rating (⭐ 1–5)
- Textarea to enter comment content
- "Submit Review" button
- Validation:
- Rating required (1–5)
- Comment cannot be empty
- After successful submission → toast notification "Your review is pending approval".
Expected Results
- Users only see "Review" button for rooms they have booked.
- Modal opens and validates correctly.
- Successful submission → review has status "pending".
- Toast displays appropriate notification.
- Clean, intuitive interface, no errors when no rooms booked.
Function 2: RoomDetailPage – Display Review List
Objective
Display list of reviews that have been approved by admin for each room.
Detailed Tasks
- Route: /rooms/:id
- API:
GET /api/reviews?roomId={id}&status=approved - Display review list:
- Avatar + user name
- Star rating (⭐)
- Comment content
- Post date (createdAt)
- Calculate and display average rating (e.g.: ⭐ 4.2 / 5)
- If no reviews → display: "No reviews yet."
Expected Results
- Review list displays correctly by room.
- Only reviews with status = approved are rendered.
- Calculate average rating accurately (rounded to 1 decimal place).
- Display avatar, name, stars, and date completely.
- Show "No reviews yet" message when list is empty.
Function 3: AdminReviewPage – Review Management Page
Objective
Allow Admin to view, approve or reject reviews submitted by users.
Detailed Tasks
- Route: /admin/reviews
- API:
GET /api/reviews PATCH /api/reviews/:id/approve PATCH /api/reviews/:id/reject - Actions: ✅ Approve → review changes to approved ❌ Reject → review changes to rejected
- After approval → update interface and display toast notification.
- Filter by status (pending, approved, rejected).
Expected Results
- Admin sees complete review list.
- Approve or reject works correctly with API.
- Table automatically updates when status changes.
- Toast clearly displays "Approved" or "Rejected".
- Only approved reviews are displayed publicly to users.
Function 4: Security & Display Logic
Objective
Ensure only valid users can submit reviews and system displays correct data.
Detailed Tasks
- Permission check:
- User not logged in → redirect /login
- User has never booked room → don't display "Review" button
- Logic check:
- Each person can only review once per room
- Review default status = pending
- Authorization:
- User: can only submit review
- Admin: approve / reject
- Staff: view only
Expected Results
- Users not logged in cannot submit reviews.
- Each room can only be reviewed once by one user.
- Data displays correctly according to permissions.
- Reviews only appear publicly when approved.
- No logic errors or incorrect status display.
Function 5: UX & Overall Display
Objective
Improve user experience and review display interface.
Detailed Tasks
- Use intuitive star rating component (e.g., react-rating-stars-component).
- Format creation date using:
new Date(createdAt).toLocaleDateString('en-US') - Add light hover effect when displaying review list.
- Use toast (react-hot-toast) for submit / approve / reject notifications.
- Loading spinner when waiting for API.
Expected Results
- Smooth, readable and user-friendly UI.
- Loading / toast displays correct status.
- Dates, stars and comments are formatted nicely.
- Admin and user interfaces have consistent styling.
- Smooth user experience, no lag or stuttering.