diff --git a/src/pages/ProductDetail.tsx b/src/pages/ProductDetail.tsx index 6082f7f..c8fa715 100644 --- a/src/pages/ProductDetail.tsx +++ b/src/pages/ProductDetail.tsx @@ -45,6 +45,15 @@ interface Lesson { position: number; } +interface UserReview { + id: string; + rating: number; + title: string; + body: string; + is_approved: boolean; + created_at: string; +} + export default function ProductDetail() { const { slug } = useParams<{ slug: string }>(); const navigate = useNavigate(); @@ -54,7 +63,7 @@ export default function ProductDetail() { const [hasAccess, setHasAccess] = useState(false); const [checkingAccess, setCheckingAccess] = useState(true); const [expandedModules, setExpandedModules] = useState>(new Set()); - const [hasReviewed, setHasReviewed] = useState(false); + const [userReview, setUserReview] = useState(null); const [reviewModalOpen, setReviewModalOpen] = useState(false); const { addItem, items } = useCart(); const { user } = useAuth(); @@ -165,13 +174,17 @@ export default function ProductDetail() { const { data } = await supabase .from('reviews') - .select('id') + .select('id, rating, title, body, is_approved, created_at') .eq('user_id', user.id) .eq('product_id', product.id) - .eq('is_approved', true) + .order('created_at', { ascending: false }) .limit(1); - setHasReviewed(!!(data && data.length > 0)); + if (data && data.length > 0) { + setUserReview(data[0] as UserReview); + } else { + setUserReview(null); + } }; // Check if webinar has ended (eligible for review) @@ -403,14 +416,59 @@ export default function ProductDetail() { {/* Webinar review prompt */} {hasAccess && product.type === 'webinar' && isWebinarEnded() && ( - - - {hasReviewed ? ( -
- - Terima kasih atas ulasan Anda (menunggu moderasi) -
+ + + {userReview ? ( + userReview.is_approved ? ( + // Approved review - celebratory display +
+
+
+ +
+
+
+

Ulasan Anda Terbit!

+ Disetujui +
+

Terima kasih telah berbagi pengalaman Anda. Ulasan Anda membantu peserta lain!

+
+
+ + {/* User's review display */} +
+
+ {[1, 2, 3, 4, 5].map((i) => ( + + ))} +
+

{userReview.title}

+ {userReview.body && ( +

{userReview.body}

+ )} +
+ +
+ Diterbitkan pada {new Date(userReview.created_at).toLocaleDateString('id-ID', { day: 'numeric', month: 'long', year: 'numeric' })} +
+
+ ) : ( + // Pending review +
+
+ +
+
+

Ulasan Anda sedang ditinjau

+

Terima kasih! Ulasan akan muncul setelah disetujui admin.

+
+
+ ) ) : ( + // No review yet - prompt to review

Bagaimana pengalaman webinar ini?

@@ -442,7 +500,7 @@ export default function ProductDetail() { productId={product.id} type="webinar" contextLabel={product.title} - onSuccess={() => setHasReviewed(true)} + onSuccess={() => checkUserReview()} /> )}