diff --git a/src/components/reviews/ProductReviews.tsx b/src/components/reviews/ProductReviews.tsx
index d729f22..ca91761 100644
--- a/src/components/reviews/ProductReviews.tsx
+++ b/src/components/reviews/ProductReviews.tsx
@@ -9,8 +9,7 @@ interface Review {
title: string;
body: string;
created_at: string;
- reviewer_name: string | null;
- profiles: { name: string | null } | null;
+ profiles: { name: string | null; avatar_url: string | null } | null;
}
interface ProductReviewsProps {
@@ -30,7 +29,7 @@ export function ProductReviews({ productId, type }: ProductReviewsProps) {
const fetchReviews = async () => {
let query = supabase
.from('reviews')
- .select('id, rating, title, body, created_at, reviewer_name, profiles!user_id (name)')
+ .select('id, rating, title, body, created_at, profiles!user_id (name, avatar_url)')
.eq('is_approved', true);
if (productId) {
@@ -75,7 +74,8 @@ export function ProductReviews({ productId, type }: ProductReviewsProps) {
rating={review.rating}
title={review.title}
body={review.body}
- authorName={review.profiles?.name || review.reviewer_name || 'Anonymous'}
+ authorName={review.profiles?.name || 'Anonymous'}
+ authorAvatar={review.profiles?.avatar_url}
date={review.created_at}
/>
))}
diff --git a/src/components/reviews/ReviewCard.tsx b/src/components/reviews/ReviewCard.tsx
index 104f110..279bc26 100644
--- a/src/components/reviews/ReviewCard.tsx
+++ b/src/components/reviews/ReviewCard.tsx
@@ -5,10 +5,11 @@ interface ReviewCardProps {
title: string;
body: string;
authorName: string;
+ authorAvatar?: string | null;
date: string;
}
-export function ReviewCard({ rating, title, body, authorName, date }: ReviewCardProps) {
+export function ReviewCard({ rating, title, body, authorName, authorAvatar, date }: ReviewCardProps) {
return (
@@ -24,7 +25,16 @@ export function ReviewCard({ rating, title, body, authorName, date }: ReviewCard
{title}
{body &&
{body}
}
-
{authorName}
+
+ {authorAvatar && (
+

+ )}
+
{authorName}
+
{new Date(date).toLocaleDateString('id-ID')}
diff --git a/src/components/reviews/ReviewModal.tsx b/src/components/reviews/ReviewModal.tsx
index a818509..66c12e2 100644
--- a/src/components/reviews/ReviewModal.tsx
+++ b/src/components/reviews/ReviewModal.tsx
@@ -33,36 +33,6 @@ export function ReviewModal({
const [title, setTitle] = useState('');
const [body, setBody] = useState('');
const [submitting, setSubmitting] = useState(false);
- const [userName, setUserName] = useState
(null);
-
- useEffect(() => {
- const fetchUserName = async () => {
- if (!userId) return;
-
- // Try to get name from profiles table first
- const { data: profileData } = await supabase
- .from('profiles')
- .select('name')
- .eq('id', userId)
- .maybeSingle();
-
- if (profileData?.name) {
- setUserName(profileData.name);
- return;
- }
-
- // Fallback: get from auth metadata
- const { data: { user } } = await supabase.auth.getUser();
- if (user?.user_metadata?.name) {
- setUserName(user.user_metadata.name);
- } else if (user?.email) {
- // Use email username as last resort
- const emailUsername = user.email.split('@')[0];
- setUserName(emailUsername);
- }
- };
- fetchUserName();
- }, [userId]);
const handleSubmit = async () => {
if (rating === 0) {
@@ -84,7 +54,6 @@ export function ReviewModal({
title: title.trim(),
body: body.trim() || null,
is_approved: false,
- reviewer_name: userName || null,
});
if (error) {
diff --git a/src/components/reviews/TestimonialsSection.tsx b/src/components/reviews/TestimonialsSection.tsx
index 6286eb9..a38f215 100644
--- a/src/components/reviews/TestimonialsSection.tsx
+++ b/src/components/reviews/TestimonialsSection.tsx
@@ -8,8 +8,7 @@ interface Review {
title: string;
body: string;
created_at: string;
- reviewer_name: string | null;
- profiles: { name: string | null } | null;
+ profiles: { name: string | null; avatar_url: string | null } | null;
}
export function TestimonialsSection() {
@@ -23,7 +22,7 @@ export function TestimonialsSection() {
const fetchReviews = async () => {
const { data } = await supabase
.from('reviews')
- .select('id, rating, title, body, created_at, reviewer_name, profiles!user_id (name)')
+ .select('id, rating, title, body, created_at, profiles!user_id (name, avatar_url)')
.eq('is_approved', true)
.order('created_at', { ascending: false })
.limit(6);
@@ -46,7 +45,8 @@ export function TestimonialsSection() {
rating={review.rating}
title={review.title}
body={review.body}
- authorName={review.profiles?.name || review.reviewer_name || 'Anonymous'}
+ authorName={review.profiles?.name || 'Anonymous'}
+ authorAvatar={review.profiles?.avatar_url}
date={review.created_at}
/>
))}