feat(reviews): add product thumbnail, renavigation link, and fix broken image rendering in review moderation

This commit is contained in:
iFixKart Dev 2026-11-17 13:49:05 +05:30
parent 002802976a
commit b87070f93b

View file

@ -1,7 +1,7 @@
'use client'; 'use client';
import { useMemo, useState, useEffect } from 'react'; import { useMemo, useState, useEffect } from 'react';
import { Star, RefreshCw, Search, ShieldCheck, Image as ImageIcon } from 'lucide-react'; import { Star, RefreshCw, Search, ShieldCheck, Image as ImageIcon, ExternalLink, Package } from 'lucide-react';
import { toast } from 'sonner'; import { toast } from 'sonner';
import { TablePagination, useClientPagination } from '@/components/ui/TablePagination'; import { TablePagination, useClientPagination } from '@/components/ui/TablePagination';
import { adminService } from '@/services/api/adminService'; import { adminService } from '@/services/api/adminService';
@ -9,6 +9,9 @@ import { adminService } from '@/services/api/adminService';
interface ReviewItem { interface ReviewItem {
review_id: string; review_id: string;
product_id: string; product_id: string;
product_name?: string;
product_slug?: string;
product_thumbnail?: string;
author_name: string; author_name: string;
author_email?: string; author_email?: string;
rating: number; rating: number;
@ -161,7 +164,7 @@ export default function ReviewsModerationPage() {
<table className="crm-data-table w-full table-fixed min-w-[980px]"> <table className="crm-data-table w-full table-fixed min-w-[980px]">
<colgroup> <colgroup>
<col className="w-[160px]" /> <col className="w-[160px]" />
<col className="w-[200px]" /> <col className="w-[240px]" />
<col className="w-[110px]" /> <col className="w-[110px]" />
<col /> <col />
<col className="w-[100px]" /> <col className="w-[100px]" />
@ -187,6 +190,11 @@ export default function ReviewsModerationPage() {
) : ( ) : (
pager.items.map((rev) => { pager.items.map((rev) => {
const photos = (rev.images || []).filter(Boolean); const photos = (rev.images || []).filter(Boolean);
const prodThumb = rev.product_thumbnail
? (rev.product_thumbnail.startsWith('http')
? rev.product_thumbnail
: `https://ifixkart.trionixsolution.com${rev.product_thumbnail.startsWith('/') ? '' : '/'}${rev.product_thumbnail}`)
: null;
return ( return (
<tr key={rev.review_id} className="border-t border-border hover:bg-muted/10"> <tr key={rev.review_id} className="border-t border-border hover:bg-muted/10">
<td className="px-5 py-3.5 align-middle"> <td className="px-5 py-3.5 align-middle">
@ -202,9 +210,35 @@ export default function ReviewsModerationPage() {
)} )}
</td> </td>
<td className="px-5 py-3.5 align-middle text-muted-foreground"> <td className="px-5 py-3.5 align-middle text-muted-foreground">
<span className="block whitespace-normal break-words leading-snug text-[12px]"> <div className="flex items-center gap-2.5">
{prodThumb ? (
<img
src={prodThumb}
alt=""
onError={(e) => { e.currentTarget.style.display = 'none'; }}
className="w-10 h-10 object-contain rounded border border-border bg-white shrink-0 p-0.5"
/>
) : (
<div className="w-10 h-10 rounded border border-border bg-muted/40 flex items-center justify-center shrink-0 text-muted-foreground">
<Package className="w-4 h-4" />
</div>
)}
<div className="min-w-0 flex-1">
<a
href={`https://ifixkart.trionixsolution.com/products/${rev.product_slug || rev.product_id}`}
target="_blank"
rel="noopener noreferrer"
className="font-medium text-foreground hover:text-primary text-[12px] line-clamp-2 leading-snug transition-colors group flex items-start gap-1"
title="Renavigate to product on storefront"
>
<span>{rev.product_name || rev.product_id}</span>
<ExternalLink className="w-3 h-3 opacity-0 group-hover:opacity-100 shrink-0 mt-0.5 text-primary transition-opacity" />
</a>
<span className="text-[10px] text-muted-foreground block font-mono mt-0.5 truncate" title={rev.product_id}>
{rev.product_id} {rev.product_id}
</span> </span>
</div>
</div>
</td> </td>
<td className="px-5 py-3.5 align-middle"> <td className="px-5 py-3.5 align-middle">
{renderStars(rev.rating)} {renderStars(rev.rating)}
@ -214,12 +248,30 @@ export default function ReviewsModerationPage() {
<p className="text-muted-foreground mt-1 leading-relaxed break-words">{rev.comment}</p> <p className="text-muted-foreground mt-1 leading-relaxed break-words">{rev.comment}</p>
{photos.length > 0 && ( {photos.length > 0 && (
<div className="flex gap-1.5 mt-2"> <div className="flex gap-1.5 mt-2">
{photos.map((imgUrl, i) => ( {photos.map((imgUrl, i) => {
<a key={i} href={imgUrl} target="_blank" rel="noopener noreferrer" const fullUrl = imgUrl.startsWith('http')
className="w-10 h-10 crm-radius-icon border border-border overflow-hidden bg-muted block"> ? imgUrl
<img src={imgUrl} alt="" className="w-full h-full object-cover" /> : `https://ifixkart.trionixsolution.com${imgUrl.startsWith('/') ? '' : '/'}${imgUrl}`;
return (
<a
key={i}
href={fullUrl}
target="_blank"
rel="noopener noreferrer"
className="w-10 h-10 crm-radius-icon border border-border overflow-hidden bg-muted block"
>
<img
src={fullUrl}
alt=""
className="w-full h-full object-cover"
onError={(e) => {
const el = e.currentTarget.closest('a');
if (el) el.style.display = 'none';
}}
/>
</a> </a>
))} );
})}
</div> </div>
)} )}
{rev.images.length > 0 && photos.length === 0 && ( {rev.images.length > 0 && photos.length === 0 && (