/** * COURSE REVIEWS — student ratings & comments section (CourseDetail). * * ✅ FEATURE GAP FIX (pre-launch audit): the backend shipped a complete * review system (review.listByCourse / myReview / create upsert / delete, * entitlement-gated) but NO page rendered it — reviewCount on course cards * could never grow and students had no social proof, the #1 conversion * lever on competitor platforms (Udemy, Coursera, Thinkific). * * Behaviour: * - Public list (paginated) of published reviews for the course. * - Authenticated users get a star-picker + comment form; submitting * creates OR updates their single review (server-side upsert). * - Unauthenticated users get a sign-in CTA with ?redirect= back here. * - Server enforces entitlement (premium: active enrollment) — the client * only surfaces a friendly message on FORBIDDEN. */ import { BadgeCheck, Lock, MessageSquareText, ShieldCheck, Star } from "lucide-react"; import { useState } from "react"; import { Link } from "react-router"; import { toast } from "sonner"; import { useAuth } from "@/hooks/useAuth"; import { useTranslation } from "@/hooks/useTranslation"; import { trpc } from "@/providers/trpc"; interface ReviewItem { id: number; userId: number; courseId: number; rating: number; comment: string | null; createdAt: string | Date; updatedAt: string | Date; userName: string | null; userUsername: string | null; /** Reviewer's profile photo (data URL from users.avatar) — null when unset. */ userAvatar: string | null; } interface MyReview { id: number; rating: number; comment: string | null; } const PAGE_SIZE = 5; function Stars({ value, size = "h-4 w-4" }: { readonly value: number; readonly size?: string }) { return (
{reviewerDisplayName(r, lang)}
{/* Brand Kit §7 proof system — ONE green check badge. Truthful by construction: the server enforces that reviews come only from enrolled students, so every published review IS a verified student. */}{r.comment}
)}{lang === "ar" ? "لا توجد تقييمات منشورة بعد — كن أول من يشارك تجربته!" : "No published reviews yet — be the first to share your experience!"}