feat: complete payment retry, reviews system, catalog mode enforcement, and UI text defaults
Deploy Canina / deploy (push) Successful in 1m48s

This commit is contained in:
parsa aghaei committed 2026-08-17 09:01:33 +03:30
1 parent e1b035d6dd
commit 2fca778930
24 files changed
+2297 -242

No files matched your search

@@ -17,6 +17,7 @@ const menuGroups = [
{ icon: ShoppingCart, label: 'سفارشات', path: '/orders' },
{ icon: Receipt, label: 'تراکنش‌ها و لاگ پرداخت', path: '/transactions' },
{ icon: Package, label: 'محصولات', path: '/products' },
{ icon: MessageSquare, label: 'نظرات محصولات', path: '/reviews' },
{ icon: FolderTree, label: 'دسته‌بندی‌ها', path: '/categories' },
{ icon: Tag, label: 'کدهای تخفیف', path: '/coupons' },
{ icon: Sparkles, label: 'مشاور هوشمند', path: '/smart-advisor' },
+14 -14
View File
@@ -468,30 +468,30 @@ export default function Orders() {
const charityAmt = Number(order.charityDonation || 0);
return (
<tr key={order.id} className="hover:bg-gray-50/50 transition-colors">
<td className="py-4 px-6 font-bold text-purple-600 font-mono" dir="ltr">
<div>{toPersianDigits(displayCode)}</div>
<div className="flex flex-wrap gap-1 mt-1.5" dir="rtl">
<span className={`text-[9px] font-black px-2 py-0.5 rounded-md border flex items-center gap-1 ${payInfo.color}`}>
<CreditCard className="w-2.5 h-2.5" />
{payInfo.label}
<tr key={order.id} className="hover:bg-gray-50/50 transition-colors font-vazir">
<td className="py-4 px-6 font-vazir" dir="rtl">
<div className="font-black text-purple-700 text-sm tracking-wide font-vazir">{toPersianDigits(displayCode)}</div>
<div className="flex flex-wrap gap-1.5 mt-2 font-vazir" dir="rtl">
<span className={`text-[10px] font-bold font-vazir px-2 py-0.5 rounded-md border flex items-center gap-1 shadow-sm ${payInfo.color}`}>
<CreditCard className="w-3 h-3 shrink-0" />
<span className="font-vazir">{payInfo.label}</span>
</span>
{order.isRefill && (
<span className="text-[9px] font-black px-2 py-0.5 rounded-md bg-emerald-50 text-emerald-700 border border-emerald-200">
<span className="text-[10px] font-bold font-vazir px-2 py-0.5 rounded-md bg-emerald-50 text-emerald-700 border border-emerald-200 shadow-sm">
تمدید ۵٪-
</span>
)}
{charityAmt > 0 && (
<span className="text-[9px] font-black px-2 py-0.5 rounded-md bg-rose-50 text-rose-700 border border-rose-200 flex items-center gap-1">
<Heart className="w-2.5 h-2.5 fill-rose-500 text-rose-500" />
مهربانی: {toPersianDigits(charityAmt.toLocaleString())} ت
<span className="text-[10px] font-bold font-vazir px-2 py-0.5 rounded-md bg-rose-50 text-rose-700 border border-rose-200 shadow-sm flex items-center gap-1">
<Heart className="w-3 h-3 fill-rose-500 text-rose-500 shrink-0" />
<span className="font-vazir">مهربانی: {toPersianDigits(charityAmt.toLocaleString())} ت</span>
</span>
)}
</div>
</td>
<td className="py-4 px-6">
<div className="font-bold text-gray-900">{customerName}</div>
<div className="text-xs text-gray-400 font-medium" dir="ltr">{toPersianDigits(order.user?.phone || order.user?.mobile || '')}</div>
<td className="py-4 px-6 font-vazir">
<div className="font-bold text-gray-900 font-vazir">{customerName}</div>
<div className="text-xs text-gray-400 font-medium font-vazir" dir="ltr">{toPersianDigits(order.user?.phone || order.user?.mobile || '')}</div>
</td>
<td className="py-4 px-6 font-black text-gray-900">
{toPersianDigits(totalAmt.toLocaleString())} <span className="text-xs font-normal">تومان</span>
+493
View File
@@ -0,0 +1,493 @@
import { useState, useEffect, useCallback } from 'react';
import {
MessageSquare,
Search,
Star,
CheckCircle2,
XCircle,
Trash2,
Reply,
Loader2,
ExternalLink,
ChevronLeft,
ChevronRight,
Clock,
User,
Package,
} from 'lucide-react';
import { toast } from 'react-hot-toast';
import api from '../services/api';
import Spinner from '../components/ui/Spinner';
interface ProductReview {
id: string;
productId: string;
userId?: string;
userName: string;
userPhone?: string;
rating: number;
comment: string;
status: 'PENDING' | 'APPROVED' | 'REJECTED';
adminReply?: string;
createdAt: string;
product?: {
id: string;
nameFa: string;
nameEn: string;
slug: string;
imageUrl: string;
};
user?: {
id: string;
firstName: string;
lastName: string;
mobile: string;
};
}
const toPersianDigits = (n: string | number): string => {
if (n === null || n === undefined) return '';
const farsiDigits = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
return n.toString().replace(/\d/g, (x) => farsiDigits[parseInt(x)]);
};
export default function Reviews() {
const [reviews, setReviews] = useState<ProductReview[]>([]);
const [isLoading, setIsLoading] = useState(true);
const [page, setPage] = useState(1);
const [limit] = useState(15);
const [totalPages, setTotalPages] = useState(1);
const [totalCount, setTotalCount] = useState(0);
const [statusFilter, setStatusFilter] = useState('ALL');
const [search, setSearch] = useState('');
const [processingId, setProcessingId] = useState<string | null>(null);
// Reply Modal State
const [replyingReview, setReplyingReview] = useState<ProductReview | null>(null);
const [replyText, setReplyText] = useState('');
const [isSavingReply, setIsSavingReply] = useState(false);
const fetchReviews = useCallback(async () => {
try {
setIsLoading(true);
const params = new URLSearchParams();
params.append('page', page.toString());
params.append('limit', limit.toString());
if (statusFilter && statusFilter !== 'ALL') params.append('status', statusFilter);
if (search.trim()) params.append('search', search.trim());
const res = await api.get(`/admin/reviews?${params.toString()}`);
if (res.data?.success) {
setReviews(res.data.data || []);
setTotalPages(res.data.pagination?.totalPages || 1);
setTotalCount(res.data.pagination?.total || 0);
}
} catch (err: any) {
console.error('Failed to fetch reviews:', err);
} finally {
setIsLoading(false);
}
}, [page, limit, statusFilter, search]);
useEffect(() => {
fetchReviews();
}, [fetchReviews]);
const handleUpdateStatus = async (id: string, newStatus: 'APPROVED' | 'REJECTED') => {
try {
setProcessingId(id);
const res = await api.patch(`/admin/reviews/${id}`, { status: newStatus });
if (res.data?.success) {
toast.success(newStatus === 'APPROVED' ? 'دیدگاه تایید شد و در سایت نمایش می‌یابد.' : 'دیدگاه رد شد.');
setReviews((prev) =>
prev.map((r) => (r.id === id ? { ...r, status: newStatus } : r))
);
}
} catch (err: any) {
console.error('Error updating review status:', err);
} finally {
setProcessingId(null);
}
};
const handleOpenReplyModal = (review: ProductReview) => {
setReplyingReview(review);
setReplyText(review.adminReply || '');
};
const handleSaveReply = async () => {
if (!replyingReview) return;
try {
setIsSavingReply(true);
const res = await api.patch(`/admin/reviews/${replyingReview.id}`, {
adminReply: replyText.trim(),
status: 'APPROVED', // Auto-approve when replied
});
if (res.data?.success) {
toast.success('پاسخ با موفقیت ثبت شد.');
setReviews((prev) =>
prev.map((r) =>
r.id === replyingReview.id
? { ...r, adminReply: replyText.trim(), status: 'APPROVED' }
: r
)
);
setReplyingReview(null);
}
} catch (err: any) {
console.error('Error saving admin reply:', err);
} finally {
setIsSavingReply(false);
}
};
const handleDelete = async (id: string) => {
if (!window.confirm('آیا از حذف این دیدگاه اطمینان دارید؟')) return;
try {
setProcessingId(id);
const res = await api.delete(`/admin/reviews/${id}`);
if (res.data?.success) {
toast.success('دیدگاه با موفقیت حذف شد.');
setReviews((prev) => prev.filter((r) => r.id !== id));
setTotalCount((c) => Math.max(0, c - 1));
}
} catch (err: any) {
console.error('Error deleting review:', err);
} finally {
setProcessingId(null);
}
};
return (
<div className="space-y-6 font-vazir text-right" dir="rtl">
{/* Header */}
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4">
<div>
<h2 className="text-2xl font-black text-gray-900 flex items-center gap-2">
<MessageSquare className="w-6 h-6 text-purple-600" />
مدیریت نظرات و دیدگاه‌ها
</h2>
<p className="text-gray-500 font-medium mt-1">
بررسی امتیازات، تایید یا رد نظرات خریداران و پاسخ‌دهی کارشناسان به دیدگاه‌ها
</p>
</div>
{/* Search */}
<div className="relative w-full sm:w-80">
<Search className="w-5 h-5 text-gray-400 absolute right-3 top-1/2 -translate-y-1/2" />
<input
type="text"
placeholder="جستجو (نام خریدار، متن نظر، نام محصول)..."
className="pl-4 pr-10 py-2.5 border border-gray-200 rounded-xl outline-none focus:ring-2 focus:ring-purple-500 w-full font-medium text-sm bg-white"
value={search}
onChange={(e) => {
setSearch(e.target.value);
setPage(1);
}}
/>
</div>
</div>
{/* Filter Tabs */}
<div className="flex flex-wrap items-center gap-2 pt-1 border-b border-gray-200 pb-3">
{[
{ label: 'همه دیدگاه‌ها', value: 'ALL', count: totalCount },
{ label: 'در انتظار بررسی', value: 'PENDING', color: 'text-amber-700 bg-amber-50 border-amber-200' },
{ label: 'تایید شده', value: 'APPROVED', color: 'text-emerald-700 bg-emerald-50 border-emerald-200' },
{ label: 'رد شده', value: 'REJECTED', color: 'text-rose-700 bg-rose-50 border-rose-200' },
].map((tab) => {
const isSelected = statusFilter === tab.value;
return (
<button
key={tab.value}
onClick={() => {
setStatusFilter(tab.value);
setPage(1);
}}
className={`px-4 py-2 rounded-xl text-xs font-bold transition-all border ${
isSelected
? 'bg-purple-600 text-white border-purple-600 shadow-sm'
: 'bg-white text-gray-600 border-gray-200 hover:bg-gray-50'
}`}
>
{tab.label}
</button>
);
})}
</div>
{/* Reviews Table */}
<div className="bg-white border border-gray-200 rounded-2xl shadow-sm overflow-hidden">
<div className="overflow-x-auto">
<table className="w-full text-right border-collapse">
<thead>
<tr className="bg-gray-50/80 border-b border-gray-200 text-xs font-black text-gray-500">
<th className="py-4 px-6">محصول</th>
<th className="py-4 px-6">نویسنده دیدگاه</th>
<th className="py-4 px-6">امتیاز</th>
<th className="py-4 px-6">متن نظر و پاسخ</th>
<th className="py-4 px-6">تاریخ</th>
<th className="py-4 px-6">وضعیت</th>
<th className="py-4 px-6 text-center">عملیات</th>
</tr>
</thead>
<tbody className="divide-y divide-gray-100 text-sm">
{isLoading ? (
<tr>
<td colSpan={7} className="py-16 text-center">
<Spinner size="lg" />
<p className="text-gray-400 font-bold mt-2 text-xs">در حال بارگذاری نظرات...</p>
</td>
</tr>
) : reviews.length === 0 ? (
<tr>
<td colSpan={7} className="py-16 text-center text-gray-400 font-bold">
هیچ دیدگاهی در این بخش یافت نشد.
</td>
</tr>
) : (
reviews.map((review) => {
const isProcessing = processingId === review.id;
const date = new Date(review.createdAt);
return (
<tr key={review.id} className="hover:bg-gray-50/50 transition-colors">
{/* Product */}
<td className="py-4 px-6">
<div className="flex items-center gap-3">
{review.product?.imageUrl ? (
<img
src={review.product.imageUrl}
alt=""
className="w-11 h-11 object-contain rounded-lg border border-gray-100 p-1 bg-white shrink-0"
/>
) : (
<div className="w-11 h-11 bg-gray-100 rounded-lg flex items-center justify-center text-gray-400 shrink-0">
<Package className="w-5 h-5" />
</div>
)}
<div className="min-w-0">
<div className="font-bold text-gray-900 line-clamp-1 text-xs sm:text-sm">
{review.product?.nameFa || 'محصول کنینا'}
</div>
<div className="text-[11px] text-gray-400 font-medium line-clamp-1" dir="ltr">
{review.product?.nameEn}
</div>
</div>
</div>
</td>
{/* Author */}
<td className="py-4 px-6">
<div className="font-bold text-gray-900 flex items-center gap-1.5">
<User className="w-3.5 h-3.5 text-gray-400 shrink-0" />
<span>{review.userName}</span>
</div>
{review.userPhone && (
<div className="text-xs text-gray-400 font-mono mt-0.5" dir="ltr">
{toPersianDigits(review.userPhone)}
</div>
)}
</td>
{/* Rating */}
<td className="py-4 px-6">
<div className="flex items-center gap-1">
{Array.from({ length: 5 }).map((_, i) => (
<Star
key={i}
className={`w-4 h-4 ${
i < review.rating
? 'fill-amber-400 text-amber-400'
: 'text-gray-200'
}`}
/>
))}
<span className="font-bold text-xs text-gray-700 mr-1.5 font-vazir">
{toPersianDigits(review.rating)} از ۵
</span>
</div>
</td>
{/* Comment & Admin Reply */}
<td className="py-4 px-6 max-w-xs md:max-w-md">
<div className="text-gray-800 text-xs sm:text-sm leading-relaxed whitespace-pre-wrap">
{review.comment}
</div>
{review.adminReply && (
<div className="mt-2 p-2.5 bg-purple-50/70 border-r-2 border-purple-500 rounded-lg text-xs text-purple-900 space-y-1">
<span className="font-bold block text-purple-700 flex items-center gap-1">
<Reply className="w-3 h-3 rotate-180" />
پاسخ کنینا:
</span>
<p className="leading-relaxed">{review.adminReply}</p>
</div>
)}
</td>
{/* Date */}
<td className="py-4 px-6 text-gray-500 text-xs font-bold">
<div>{toPersianDigits(date.toLocaleDateString('fa-IR'))}</div>
<div className="text-[10px] text-gray-400">
{toPersianDigits(date.toLocaleTimeString('fa-IR', { hour: '2-digit', minute: '2-digit' }))}
</div>
</td>
{/* Status */}
<td className="py-4 px-6">
{review.status === 'PENDING' && (
<span className="inline-flex items-center gap-1 px-2.5 py-1 rounded-full text-xs font-bold bg-amber-50 text-amber-700 border border-amber-200">
<Clock className="w-3 h-3" />
در انتظار بررسی
</span>
)}
{review.status === 'APPROVED' && (
<span className="inline-flex items-center gap-1 px-2.5 py-1 rounded-full text-xs font-bold bg-emerald-50 text-emerald-700 border border-emerald-200">
<CheckCircle2 className="w-3 h-3" />
تایید شده
</span>
)}
{review.status === 'REJECTED' && (
<span className="inline-flex items-center gap-1 px-2.5 py-1 rounded-full text-xs font-bold bg-rose-50 text-rose-700 border border-rose-200">
<XCircle className="w-3 h-3" />
رد شده
</span>
)}
</td>
{/* Actions */}
<td className="py-4 px-6 text-center">
<div className="flex items-center justify-center gap-1.5">
{review.status !== 'APPROVED' && (
<button
disabled={isProcessing}
onClick={() => handleUpdateStatus(review.id, 'APPROVED')}
title="تایید دیدگاه"
className="p-1.5 text-emerald-600 hover:bg-emerald-50 rounded-lg transition-colors border border-emerald-200"
>
<CheckCircle2 className="w-4 h-4" />
</button>
)}
{review.status !== 'REJECTED' && (
<button
disabled={isProcessing}
onClick={() => handleUpdateStatus(review.id, 'REJECTED')}
title="رد دیدگاه"
className="p-1.5 text-rose-600 hover:bg-rose-50 rounded-lg transition-colors border border-rose-200"
>
<XCircle className="w-4 h-4" />
</button>
)}
<button
disabled={isProcessing}
onClick={() => handleOpenReplyModal(review)}
title="پاسخ به دیدگاه"
className="p-1.5 text-purple-600 hover:bg-purple-50 rounded-lg transition-colors border border-purple-200"
>
<Reply className="w-4 h-4" />
</button>
<button
disabled={isProcessing}
onClick={() => handleDelete(review.id)}
title="حذف دیدگاه"
className="p-1.5 text-gray-400 hover:text-red-600 hover:bg-red-50 rounded-lg transition-colors"
>
<Trash2 className="w-4 h-4" />
</button>
</div>
</td>
</tr>
);
})
)}
</tbody>
</table>
</div>
{/* Pagination */}
{totalPages > 1 && (
<div className="p-4 border-t border-gray-100 flex items-center justify-between">
<span className="text-xs text-gray-500 font-bold">
صفحه {toPersianDigits(page)} از {toPersianDigits(totalPages)}
</span>
<div className="flex items-center gap-2">
<button
disabled={page <= 1 || isLoading}
onClick={() => setPage((p) => Math.max(1, p - 1))}
className="p-2 border border-gray-200 rounded-xl hover:bg-gray-50 disabled:opacity-40 disabled:pointer-events-none transition-all text-xs font-bold flex items-center gap-1"
>
<ChevronRight className="w-4 h-4" />
<span>قبلی</span>
</button>
<button
disabled={page >= totalPages || isLoading}
onClick={() => setPage((p) => Math.min(totalPages, p + 1))}
className="p-2 border border-gray-200 rounded-xl hover:bg-gray-50 disabled:opacity-40 disabled:pointer-events-none transition-all text-xs font-bold flex items-center gap-1"
>
<span>بعدی</span>
<ChevronLeft className="w-4 h-4" />
</button>
</div>
</div>
)}
</div>
{/* Reply Modal */}
{replyingReview && (
<div className="fixed inset-0 z-50 bg-black/40 backdrop-blur-sm flex items-center justify-center p-4">
<div className="bg-white rounded-2xl p-6 w-full max-w-lg shadow-2xl space-y-4 font-vazir animate-in fade-in zoom-in-95 duration-150" dir="rtl">
<div className="flex items-center justify-between border-b border-gray-100 pb-3">
<h3 className="text-base font-black text-gray-900 flex items-center gap-2">
<Reply className="w-5 h-5 text-purple-600" />
پاسخ به دیدگاه {replyingReview.userName}
</h3>
<button
onClick={() => setReplyingReview(null)}
className="p-1 text-gray-400 hover:text-gray-600 rounded-lg hover:bg-gray-100"
>
✕
</button>
</div>
<div className="p-3 bg-gray-50 rounded-xl border border-gray-100 text-xs text-gray-600 space-y-1">
<span className="font-bold text-gray-700 block">متن دیدگاه خریدار:</span>
<p className="leading-relaxed whitespace-pre-wrap">{replyingReview.comment}</p>
</div>
<div>
<label className="block text-xs font-bold text-gray-700 mb-1.5">
متن پاسخ کارشناس رسمی کنینا:
</label>
<textarea
rows={4}
value={replyText}
onChange={(e) => setReplyText(e.target.value)}
placeholder="پاسخ و توضیحات رسمی برای نمایش در زیر نظر..."
className="w-full p-3 border border-gray-200 rounded-xl text-sm font-medium outline-none focus:ring-2 focus:ring-purple-500 resize-none leading-relaxed"
/>
</div>
<div className="flex items-center justify-end gap-3 pt-2">
<button
type="button"
onClick={() => setReplyingReview(null)}
className="px-4 py-2.5 text-xs font-bold text-gray-600 hover:bg-gray-100 rounded-xl transition-all"
>
انصراف
</button>
<button
type="button"
disabled={isSavingReply}
onClick={handleSaveReply}
className="px-5 py-2.5 text-xs font-bold bg-purple-600 hover:bg-purple-700 text-white rounded-xl shadow-lg shadow-purple-600/20 transition-all flex items-center gap-1.5"
>
{isSavingReply && <Loader2 className="w-3.5 h-3.5 animate-spin" />}
<span>ثبت و انتشار پاسخ</span>
</button>
</div>
</div>
</div>
)}
</div>
);
}
+12 -3
View File
@@ -15,7 +15,8 @@ const PAGE_TABS = [
const GROUPS: Record<string, string[]> = {
"تنظیمات کاتالوگ‌مود و حالت صیانت": [
"maintenance_mode", "catalog_mode", "catalog_hide_prices", "catalog_disable_cart", "catalog_disable_checkout",
"maintenance_mode", "maintenance_title", "maintenance_desc", "maintenance_eta", "maintenance_contact_phone", "maintenance_badge",
"catalog_mode", "catalog_hide_prices", "catalog_disable_cart", "catalog_disable_checkout",
],
"هدر و ناوبری": [
"shipping_notice", "brand_name_fa", "brand_subtitle",
@@ -94,8 +95,16 @@ const KEY_LABELS_FA: Record<string, string> = {
featured_title_line1: "عنوان بخش محصولات برگزیده",
cta_title: "عنوان کادر دعوت به اقدام (CTA)",
footer_copyright: "متن کپی‌رایت فوتر",
maintenance_mode: "حالت تعمیرات و صیانت سایت",
catalog_mode: "حالت کاتالوگ‌مود",
maintenance_mode: "حالت تعمیرات و صیانت سایت (غیرفعال‌سازی موقت دسترسی عموم)",
maintenance_title: "عنوان صفحه حالت تعمیرات",
maintenance_desc: "توضیحات و پیام اطلاع‌رسانی حالت تعمیرات",
maintenance_eta: "متن زمان تقریبی بازگشایی سامانه",
maintenance_contact_phone: "شماره تلفن تماس اضطراری در صفحه تعمیرات",
maintenance_badge: "بج بالای صفحه تعمیرات",
catalog_mode: "حالت کاتالوگ‌مود (غیرفعال‌سازی خرید مستقیم)",
catalog_hide_prices: "مخفی‌سازی قیمت محصولات در حالت کاتالوگ",
catalog_disable_cart: "غیرفعال‌سازی سبد خرید در حالت کاتالوگ",
catalog_disable_checkout: "غیرفعال‌سازی صفحه تسویه‌حساب در حالت کاتالوگ",
};
const GROUP_PAGE_MAP: Record<string, string> = {
@@ -37,6 +37,7 @@ const SmsSettingsPage = lazy(() => import('../pages/SmsSettingsPage'));
const SslSettingsPage = lazy(() => import('../pages/SslSettingsPage'));
const Transactions = lazy(() => import('../pages/Transactions'));
const Tickets = lazy(() => import('../pages/Tickets'));
const Reviews = lazy(() => import('../pages/Reviews'));
export interface AdminRouteConfig {
path: string;
@@ -86,6 +87,7 @@ export const router = createBrowserRouter([
{ path: 'wholesale/*', element: <WholesaleApplications /> },
{ path: 'contact/*', element: <ContactSubmissions /> },
{ path: 'tickets/*', element: <Tickets /> },
{ path: 'reviews/*', element: <Reviews /> },
],
},
],