feat: complete tickets & vet consultation, fix wallet balance overflow, b2b toggle, and transaction manual verification
Deploy Canina / deploy (push) Successful in 1m51s

This commit is contained in:
parsa aghaei committed 2026-08-16 18:01:43 +03:30
1 parent 1aa9d6e34d
commit 42707c04cf
24 files changed
+1856 -139

No files matched your search

@@ -28,6 +28,7 @@ const menuGroups = [
items: [
{ icon: Users, label: 'کاربران', path: '/users' },
{ icon: Heart, label: 'حیوانات (Pets)', path: '/pets' },
{ icon: MessageSquare, label: 'تیکت‌ها & مشاوره دامپزشک', path: '/tickets' },
{ icon: Building2, label: 'مدیریت B2B & عمده', path: '/b2b' },
{ icon: PhoneCall, label: 'تماس با ما & اطلاعات', path: '/contact' },
]
+89 -1
View File
@@ -36,6 +36,18 @@ export interface OrderItem {
};
}
export interface PaymentTx {
id: string;
trackId?: string;
refNumber?: string;
cardNumber?: string;
amount?: number;
status: string;
message?: string;
gateway?: string;
createdAt: string;
}
export interface Order {
id: string;
trackingNumber?: string;
@@ -48,17 +60,21 @@ export interface Order {
isRefill?: boolean;
paymentMethod?: string;
address?: string;
shippingAddress?: string;
orderItems?: OrderItem[];
items?: OrderItem[];
paymentTransactions?: PaymentTx[];
user?: {
firstName?: string;
lastName?: string;
mobile?: string;
phone?: string;
email?: string;
};
}
const statusStyles: Record<string, { label: string; color: string; icon: React.ElementType }> = {
pending_payment: { label: 'در انتظار پرداخت / ناموفق', color: 'bg-rose-100 text-rose-800 border-rose-200', icon: Clock },
pending: { label: 'در حال بررسی', color: 'bg-orange-100 text-orange-700 border-orange-200', icon: Clock },
processing: { label: 'در حال پردازش', color: 'bg-amber-100 text-amber-800 border-amber-200', icon: Clock },
shipped: { label: 'ارسال شده', color: 'bg-blue-100 text-blue-700 border-blue-200', icon: Truck },
@@ -329,7 +345,7 @@ export default function Orders() {
<ShoppingCart className="w-6 h-6 text-purple-600" />
مدیریت سفارشات
</h2>
<p className="text-gray-500 font-medium mt-1">مشاهده فاکتورها، تغییر وضعیت، ثبت کد رهگیری پستی و چاپ فاکتور رسمی</p>
<p className="text-gray-500 font-medium mt-1">مشاهده فاکتورها، سفارش‌های در انتظار/ناموفق، تغییر وضعیت و چاپ فاکتور رسمی</p>
</div>
<div className="flex flex-col sm:flex-row items-center gap-3 w-full sm:w-auto">
@@ -339,6 +355,7 @@ export default function Orders() {
onChange={(e) => { setStatus(e.target.value); setPage(1); }}
>
<option value="">همه وضعیت‌ها</option>
<option value="pending_payment">در انتظار پرداخت / ناموفق</option>
<option value="processing">در حال پردازش</option>
<option value="shipped">ارسال شده</option>
<option value="delivered">تحویل داده شده</option>
@@ -358,6 +375,33 @@ export default function Orders() {
</div>
</div>
{/* Quick Filter Pills */}
<div className="flex flex-wrap gap-2 pt-1">
{[
{ label: 'همه سفارش‌ها', value: '' },
{ label: 'در انتظار پرداخت / ناموفق', value: 'pending_payment', color: 'text-rose-700 bg-rose-50 border-rose-200' },
{ label: 'در حال پردازش', value: 'processing', color: 'text-amber-700 bg-amber-50 border-amber-200' },
{ label: 'ارسال شده', value: 'shipped', color: 'text-blue-700 bg-blue-50 border-blue-200' },
{ label: 'تحویل شده', value: 'delivered', color: 'text-green-700 bg-green-50 border-green-200' },
{ label: 'لغو شده', value: 'cancelled', color: 'text-red-700 bg-red-50 border-red-200' },
].map((tab) => {
const isSelected = status === tab.value;
return (
<button
key={tab.value}
onClick={() => { setStatus(tab.value); setPage(1); }}
className={`px-4 py-2 rounded-xl font-bold text-xs border transition-all cursor-pointer ${
isSelected
? 'bg-purple-600 text-white border-purple-600 shadow-md shadow-purple-600/20'
: `${tab.color || 'bg-white text-gray-700 border-gray-200'} hover:bg-gray-50`
}`}
>
{tab.label}
</button>
);
})}
</div>
{/* Orders Table */}
<div className="bg-white rounded-2xl shadow-sm border border-gray-200 overflow-hidden">
<div className="overflow-x-auto">
@@ -432,6 +476,7 @@ export default function Orders() {
onChange={(e) => handleUpdateStatus(order.id, e.target.value)}
className={`text-xs font-bold px-3 py-1.5 rounded-xl border outline-none cursor-pointer transition-all ${statusStyles[order.status]?.color || 'bg-gray-100 text-gray-700'}`}
>
<option value="pending_payment">در انتظار پرداخت / ناموفق</option>
<option value="processing">در حال پردازش</option>
<option value="shipped">ارسال شده</option>
<option value="delivered">تحویل داده شده</option>
@@ -544,6 +589,7 @@ export default function Orders() {
onChange={(e) => setModalStatus(e.target.value)}
className="w-full bg-white border border-gray-300 text-gray-900 text-sm font-bold rounded-xl p-2.5 outline-none focus:ring-2 focus:ring-purple-500"
>
<option value="pending_payment">در انتظار پرداخت / ناموفق</option>
<option value="processing">در حال پردازش</option>
<option value="shipped">ارسال شده</option>
<option value="delivered">تحویل داده شده</option>
@@ -574,6 +620,48 @@ export default function Orders() {
</div>
</div>
{/* Payment Gateway Transactions Log */}
{selectedOrder.paymentTransactions && selectedOrder.paymentTransactions.length > 0 && (
<div className="bg-slate-50 p-6 rounded-2xl border border-slate-200 space-y-3">
<h4 className="text-xs font-black text-slate-800 uppercase tracking-widest flex items-center gap-2">
<Clock className="w-4 h-4 text-purple-600" />
لاگ تراکنش‌های درگاه پرداخت زیبال / بانکی
</h4>
<div className="space-y-2 text-xs">
{selectedOrder.paymentTransactions.map((tx) => (
<div key={tx.id} className="p-3 bg-white rounded-xl border border-slate-200 flex flex-col sm:flex-row sm:items-center justify-between gap-2">
<div className="space-y-1">
<div className="font-mono font-bold text-slate-700">
شناسه رهگیری زیبال (TrackID): <span className="text-purple-600">{tx.trackId || 'ثبت نشده'}</span>
</div>
{tx.refNumber && (
<div className="text-slate-600">
شماره ارجاع شاپرک (RRN): <span className="font-mono font-bold">{tx.refNumber}</span>
</div>
)}
{tx.message && (
<div className="text-slate-500">
پیام درگاه: <span className="font-semibold">{tx.message}</span>
</div>
)}
</div>
<div className="text-left">
<span className={`inline-block px-2.5 py-1 rounded-lg font-bold text-[11px] ${
tx.status === 'VERIFIED'
? 'bg-emerald-100 text-emerald-800'
: tx.status === 'PENDING'
? 'bg-amber-100 text-amber-800'
: 'bg-rose-100 text-rose-800'
}`}>
{tx.status === 'VERIFIED' ? 'پرداخت تایید شده' : tx.status === 'PENDING' ? 'در انتظار پرداخت' : 'پرداخت ناموفق'}
</span>
</div>
</div>
))}
</div>
</div>
)}
{/* Items Table */}
<div>
<h4 className="text-xs font-black text-gray-400 uppercase tracking-widest mb-4">
+467
View File
@@ -0,0 +1,467 @@
import { useState, useEffect, useCallback } from 'react';
import {
MessageSquare,
Search,
Filter,
Stethoscope,
FileText,
User,
Clock,
CheckCircle2,
AlertCircle,
XCircle,
Send,
RefreshCw,
ChevronLeft,
ChevronRight,
ShieldCheck,
Building2,
Calendar,
} from 'lucide-react';
import api from '../services/api';
import { toast } from 'react-hot-toast';
interface TicketMessage {
id: string;
senderId?: string;
senderRole: 'USER' | 'ADMIN' | 'VET_DOCTOR';
senderName: string;
message: string;
attachment?: string;
createdAt: string;
}
interface Ticket {
id: string;
ticketNumber: string;
subject: string;
category: 'VET_CONSULTATION' | 'ORDER_SUPPORT' | 'PRODUCT_INQUIRY' | 'GENERAL';
priority: 'LOW' | 'MEDIUM' | 'HIGH' | 'URGENT';
status: 'OPEN' | 'IN_PROGRESS' | 'ANSWERED' | 'CLOSED';
createdAt: string;
updatedAt: string;
user: {
id: string;
firstName?: string;
lastName?: string;
mobile: string;
};
pet?: {
id: string;
name: string;
type: string;
breed: string;
};
messages: TicketMessage[];
}
export default function Tickets() {
const [tickets, setTickets] = useState<Ticket[]>([]);
const [loading, setLoading] = useState(true);
const [total, setTotal] = useState(0);
const [page, setPage] = useState(1);
const [statusFilter, setStatusFilter] = useState<string>('ALL');
const [categoryFilter, setCategoryFilter] = useState<string>('ALL');
const [searchQuery, setSearchQuery] = useState('');
// Detail / Reply Modal
const [selectedTicket, setSelectedTicket] = useState<Ticket | null>(null);
const [fetchingDetail, setFetchingDetail] = useState(false);
const [replyMessage, setReplyMessage] = useState('');
const [replyStatus, setReplyStatus] = useState<string>('ANSWERED');
const [sendingReply, setSendingReply] = useState(false);
const fetchTickets = useCallback(async () => {
try {
setLoading(true);
const params: Record<string, any> = { page, limit: 15 };
if (statusFilter !== 'ALL') params.status = statusFilter;
if (categoryFilter !== 'ALL') params.category = categoryFilter;
if (searchQuery.trim()) params.search = searchQuery.trim();
const res = await api.get('/tickets/admin/all', { params });
setTickets(res.data?.data || []);
setTotal(res.data?.meta?.total || 0);
} catch {
toast.error('خطا در دریافت لیست تیکت‌ها');
} finally {
setLoading(false);
}
}, [page, statusFilter, categoryFilter, searchQuery]);
useEffect(() => {
fetchTickets();
}, [fetchTickets]);
const handleOpenTicket = async (ticketId: string) => {
try {
setFetchingDetail(true);
const res = await api.get(`/tickets/${ticketId}`);
setSelectedTicket(res.data?.data || null);
setReplyStatus(res.data?.data?.status === 'OPEN' ? 'ANSWERED' : res.data?.data?.status || 'ANSWERED');
} catch {
toast.error('خطا در بارگذاری جزئیات تیکت');
} finally {
setFetchingDetail(false);
}
};
const handleSendReply = async (e: React.FormEvent) => {
e.preventDefault();
if (!selectedTicket || !replyMessage.trim()) return;
try {
setSendingReply(true);
await api.post(`/tickets/${selectedTicket.id}/messages`, {
message: replyMessage.trim(),
status: replyStatus,
});
toast.success('پاسخ با موفقیت برای کاربر ارسال شد');
setReplyMessage('');
// Reload current ticket
handleOpenTicket(selectedTicket.id);
fetchTickets();
} catch (err: any) {
toast.error(err.response?.data?.message || 'خطا در ارسال پاسخ');
} finally {
setSendingReply(false);
}
};
const handleUpdateStatus = async (status: string) => {
if (!selectedTicket) return;
try {
await api.put(`/tickets/admin/${selectedTicket.id}/status`, { status });
toast.success('وضعیت تیکت تغییر یافت');
setSelectedTicket({ ...selectedTicket, status: status as any });
fetchTickets();
} catch {
toast.error('خطا در تغییر وضعیت تیکت');
}
};
const getCategoryBadge = (cat: string) => {
switch (cat) {
case 'VET_CONSULTATION':
return { label: 'مشاوره دامپزشک', bg: 'bg-emerald-50 text-emerald-700 border-emerald-200', icon: Stethoscope };
case 'ORDER_SUPPORT':
return { label: 'پشتیبانی سفارش', bg: 'bg-blue-50 text-blue-700 border-blue-200', icon: FileText };
case 'PRODUCT_INQUIRY':
return { label: 'سوال محصولی / دارویی', bg: 'bg-purple-50 text-purple-700 border-purple-200', icon: Building2 };
default:
return { label: 'عمومی', bg: 'bg-gray-50 text-gray-700 border-gray-200', icon: MessageSquare };
}
};
const getStatusBadge = (status: string) => {
switch (status) {
case 'OPEN':
return { label: 'در انتظار پاسخ', bg: 'bg-amber-50 text-amber-700 border-amber-200' };
case 'ANSWERED':
return { label: 'پاسخ داده شد', bg: 'bg-emerald-50 text-emerald-700 border-emerald-200' };
case 'IN_PROGRESS':
return { label: 'در حال بررسی', bg: 'bg-blue-50 text-blue-700 border-blue-200' };
case 'CLOSED':
return { label: 'بسته شده', bg: 'bg-gray-100 text-gray-600 border-gray-200' };
default:
return { label: status, bg: 'bg-gray-50 text-gray-600 border-gray-200' };
}
};
return (
<div className="space-y-6">
{/* 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-7 h-7 text-canina-blue" />
پشتیبانی، تیکتینگ و مشاوره دامپزشکی
</h2>
<p className="text-gray-500 font-medium mt-1">
مشاهده و پاسخ‌دهی به تیکت‌های پزشکی، مشاوره‌ای و پشتیبانی مشتریان کنینا
</p>
</div>
<button
onClick={() => fetchTickets()}
className="bg-gray-100 hover:bg-gray-200 text-gray-800 font-bold px-4 py-2.5 rounded-xl text-xs flex items-center gap-2 transition-colors self-start cursor-pointer"
>
<RefreshCw className={`w-4 h-4 ${loading ? 'animate-spin' : ''}`} />
<span>بروزرسانی لیست</span>
</button>
</div>
{/* Filters & Search */}
<div className="bg-white p-4 rounded-2xl border border-gray-200 shadow-sm space-y-4">
<div className="flex flex-col sm:flex-row gap-3">
<div className="flex-1 relative">
<Search className="w-4 h-4 text-gray-400 absolute right-3.5 top-1/2 -translate-y-1/2" />
<input
type="text"
placeholder="جستجو در موضوع، شماره تیکت، نام کاربر یا شماره موبایل..."
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
className="w-full pl-4 pr-10 py-2.5 rounded-xl border border-gray-200 text-xs font-medium focus:border-canina-blue outline-none"
/>
</div>
<div className="flex gap-2">
<select
value={statusFilter}
onChange={(e) => { setStatusFilter(e.target.value); setPage(1); }}
className="px-3 py-2.5 rounded-xl border border-gray-200 text-xs font-bold bg-white focus:border-canina-blue outline-none"
>
<option value="ALL">همه وضعیت‌ها</option>
<option value="OPEN">در انتظار پاسخ</option>
<option value="IN_PROGRESS">در حال بررسی</option>
<option value="ANSWERED">پاسخ داده شده</option>
<option value="CLOSED">بسته شده</option>
</select>
<select
value={categoryFilter}
onChange={(e) => { setCategoryFilter(e.target.value); setPage(1); }}
className="px-3 py-2.5 rounded-xl border border-gray-200 text-xs font-bold bg-white focus:border-canina-blue outline-none"
>
<option value="ALL">همه دسته‌بندی‌ها</option>
<option value="VET_CONSULTATION">مشاوره دامپزشک</option>
<option value="ORDER_SUPPORT">پشتیبانی سفارش</option>
<option value="PRODUCT_INQUIRY">سوال دارویی / محصولی</option>
<option value="GENERAL">عمومی</option>
</select>
</div>
</div>
</div>
{/* Tickets Table */}
<div className="bg-white rounded-2xl border border-gray-200 shadow-sm overflow-hidden">
<div className="overflow-x-auto">
<table className="w-full text-right text-xs">
<thead className="bg-gray-50 border-b border-gray-200 text-gray-500 font-bold">
<tr>
<th className="p-4">شماره تیکت</th>
<th className="p-4">کاربر / صاحب پت</th>
<th className="p-4">پت مرتبط</th>
<th className="p-4">موضوع و دسته‌بندی</th>
<th className="p-4">وضعیت</th>
<th className="p-4">آخرین بروزرسانی</th>
<th className="p-4 text-center">عملیات</th>
</tr>
</thead>
<tbody className="divide-y divide-gray-100">
{loading && tickets.length === 0 ? (
<tr>
<td colSpan={7} className="text-center py-12 text-gray-400 font-medium">
در حال دریافت تیکت‌ها...
</td>
</tr>
) : tickets.length === 0 ? (
<tr>
<td colSpan={7} className="text-center py-12 text-gray-400 font-medium">
تیکتی مطابق با فیلترهای انتخابی یافت نشد.
</td>
</tr>
) : (
tickets.map((t) => {
const cat = getCategoryBadge(t.category);
const st = getStatusBadge(t.status);
const userName = `${t.user?.firstName || ''} ${t.user?.lastName || ''}`.trim() || 'بدون نام';
return (
<tr key={t.id} className="hover:bg-gray-50/80 transition-colors">
<td className="p-4 font-mono font-bold text-canina-blue">
{t.ticketNumber}
</td>
<td className="p-4">
<div className="font-bold text-gray-900">{userName}</div>
<div className="text-gray-400 font-mono text-[11px] mt-0.5">{t.user?.mobile}</div>
</td>
<td className="p-4">
{t.pet ? (
<span className="inline-flex items-center gap-1 px-2.5 py-1 bg-purple-50 text-purple-700 rounded-lg text-[11px] font-bold border border-purple-100">
🐾 {t.pet.name} ({t.pet.breed || t.pet.type})
</span>
) : (
<span className="text-gray-400 font-medium">-</span>
)}
</td>
<td className="p-4">
<div className="font-bold text-gray-900 max-w-xs truncate">{t.subject}</div>
<span className={`inline-flex items-center gap-1 px-2 py-0.5 mt-1 rounded text-[10px] font-bold border ${cat.bg}`}>
<cat.icon className="w-3 h-3" />
{cat.label}
</span>
</td>
<td className="p-4">
<span className={`px-2.5 py-1 rounded-full font-bold text-[11px] border ${st.bg}`}>
{st.label}
</span>
</td>
<td className="p-4 text-gray-500 font-mono text-[11px]">
{new Date(t.updatedAt).toLocaleDateString('fa-IR')}
</td>
<td className="p-4 text-center">
<button
onClick={() => handleOpenTicket(t.id)}
className="px-3 py-1.5 bg-canina-blue text-white rounded-lg font-bold hover:bg-canina-dark transition-colors cursor-pointer"
>
مشاهده و پاسخ
</button>
</td>
</tr>
);
})
)}
</tbody>
</table>
</div>
{/* Pagination */}
<div className="p-4 border-t border-gray-100 flex items-center justify-between text-xs text-gray-500 font-medium">
<div>تعداد کل تیکت‌ها: {total}</div>
<div className="flex items-center gap-2">
<button
disabled={page <= 1}
onClick={() => setPage(page - 1)}
className="p-2 rounded-lg border border-gray-200 hover:bg-gray-50 disabled:opacity-40"
>
<ChevronRight className="w-4 h-4" />
</button>
<span>صفحه {page}</span>
<button
disabled={tickets.length < 15}
onClick={() => setPage(page + 1)}
className="p-2 rounded-lg border border-gray-200 hover:bg-gray-50 disabled:opacity-40"
>
<ChevronLeft className="w-4 h-4" />
</button>
</div>
</div>
</div>
{/* Ticket Details & Admin Reply Modal */}
{selectedTicket && (
<div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/60 backdrop-blur-sm">
<div className="bg-white w-full max-w-3xl rounded-3xl p-6 sm:p-8 shadow-2xl space-y-6 max-h-[90vh] flex flex-col" dir="rtl">
{/* Modal Header */}
<div className="flex items-start justify-between pb-4 border-b border-gray-100">
<div>
<div className="flex items-center gap-2">
<h3 className="text-lg font-black text-gray-900">{selectedTicket.subject}</h3>
<span className="px-2.5 py-0.5 bg-canina-blue/10 text-canina-blue font-mono font-bold text-xs rounded-lg">
{selectedTicket.ticketNumber}
</span>
</div>
<div className="flex items-center gap-3 text-xs text-gray-500 font-medium mt-1">
<span>کاربر: {selectedTicket.user?.firstName} {selectedTicket.user?.lastName} ({selectedTicket.user?.mobile})</span>
{selectedTicket.pet && (
<span className="text-purple-600 font-bold">• 🐾 {selectedTicket.pet.name} ({selectedTicket.pet.breed || selectedTicket.pet.type})</span>
)}
</div>
</div>
<div className="flex items-center gap-2">
<select
value={selectedTicket.status}
onChange={(e) => handleUpdateStatus(e.target.value)}
className="px-2.5 py-1.5 border border-gray-200 rounded-xl text-xs font-bold bg-gray-50 focus:border-canina-blue outline-none"
>
<option value="OPEN">در انتظار پاسخ</option>
<option value="IN_PROGRESS">در حال بررسی</option>
<option value="ANSWERED">پاسخ داده شد</option>
<option value="CLOSED">بسته شده</option>
</select>
<button
type="button"
onClick={() => setSelectedTicket(null)}
className="w-8 h-8 rounded-full bg-gray-100 hover:bg-gray-200 text-gray-600 flex items-center justify-center font-bold text-sm cursor-pointer"
>
✕
</button>
</div>
</div>
{/* Messages Chat Scroll */}
<div className="flex-1 overflow-y-auto space-y-4 p-2 min-h-[250px]">
{(selectedTicket.messages || []).map((msg) => {
const isAdminOrVet = msg.senderRole === 'ADMIN' || msg.senderRole === 'VET_DOCTOR';
return (
<div
key={msg.id}
className={`p-4 rounded-2xl max-w-[85%] text-xs font-medium leading-relaxed ${
isAdminOrVet
? 'bg-emerald-50 border border-emerald-200 text-emerald-950 mr-auto'
: 'bg-blue-50 border border-blue-200 text-blue-950 ml-auto'
}`}
>
<div className="flex items-center justify-between gap-4 mb-1.5 pb-1 border-b border-black/5">
<span className="font-black text-[11px] flex items-center gap-1.5">
{isAdminOrVet ? (
<>
<Stethoscope className="w-3.5 h-3.5 text-emerald-600" />
<span className="text-emerald-700">{msg.senderName} (تیم پزشکی / ادمین)</span>
</>
) : (
<>
<User className="w-3.5 h-3.5 text-blue-600" />
<span className="text-blue-700">{msg.senderName} (مشتری)</span>
</>
)}
</span>
<span className="text-[10px] text-gray-400 font-normal font-mono">
{new Date(msg.createdAt).toLocaleString('fa-IR')}
</span>
</div>
<p className="whitespace-pre-wrap">{msg.message}</p>
</div>
);
})}
</div>
{/* Admin Response Composer */}
<form onSubmit={handleSendReply} className="pt-3 border-t border-gray-100 space-y-3">
<div className="flex items-center justify-between text-xs">
<label className="font-bold text-gray-700">ارسال پاسخ دامپزشک / پشتیبانی:</label>
<div className="flex items-center gap-2">
<span className="text-gray-400">تغییر وضعیت به:</span>
<select
value={replyStatus}
onChange={(e) => setReplyStatus(e.target.value)}
className="px-2 py-1 bg-gray-50 border border-gray-200 rounded-lg text-xs font-bold"
>
<option value="ANSWERED">پاسخ داده شد</option>
<option value="IN_PROGRESS">در حال بررسی</option>
<option value="CLOSED">پاسخ و بستن تیکت</option>
</select>
</div>
</div>
<textarea
required
rows={3}
placeholder="متن پاسخ تخصصی به کاربر را وارد کنید..."
value={replyMessage}
onChange={(e) => setReplyMessage(e.target.value)}
className="w-full px-4 py-3 bg-gray-50 border border-gray-200 rounded-xl text-xs font-medium focus:border-canina-blue outline-none"
/>
<div className="flex justify-end gap-3">
<button
type="button"
onClick={() => setSelectedTicket(null)}
className="px-4 py-2 rounded-xl text-xs font-bold text-gray-600 bg-gray-100 hover:bg-gray-200 cursor-pointer"
>
بستن
</button>
<button
type="submit"
disabled={sendingReply || !replyMessage.trim()}
className="px-6 py-2 bg-canina-blue text-white rounded-xl text-xs font-black hover:bg-canina-dark disabled:opacity-50 transition-all flex items-center gap-2 cursor-pointer shadow-md shadow-canina-blue/20"
>
<Send className="w-3.5 h-3.5" />
<span>{sendingReply ? 'در حال ارسال...' : 'ارسال پاسخ به کاربر'}</span>
</button>
</div>
</form>
</div>
</div>
)}
</div>
);
}
@@ -209,6 +209,35 @@ export default function Transactions() {
}
};
const handleManualVerify = async (txId: string) => {
if (!window.confirm('آیا از تایید دستی این تراکنش (افزایش موجودی کیف پول یا تایید سفارش) اطمینان دارید؟')) return;
try {
const res = await api.post(`/payment/admin/manual-verify/${txId}`, {
adminNote: 'تایید دستی فیش واریزی توسط مدیر سیستم',
});
toast.success(res.data?.message || 'تراکنش با موفقیت تایید شد');
fetchTransactions();
fetchStats();
if (selectedTx) setSelectedTx(null);
} catch (e: any) {
toast.error(e.response?.data?.message || 'خطا در تایید دستی تراکنش');
}
};
const handleManualReject = async (txId: string) => {
const reason = window.prompt('لطفاً دلیل رد تراکنش را وارد کنید:', 'فیش واریزی نامعتبر است');
if (reason === null) return;
try {
const res = await api.post(`/payment/admin/manual-reject/${txId}`, { reason });
toast.success(res.data?.message || 'تراکنش رد شد');
fetchTransactions();
fetchStats();
if (selectedTx) setSelectedTx(null);
} catch (e: any) {
toast.error(e.response?.data?.message || 'خطا در رد تراکنش');
}
};
return (
<div className="space-y-6">
{/* Header */}
@@ -796,15 +825,38 @@ export default function Transactions() {
)}
</div>
{/* Close Button */}
<div className="flex justify-end">
{/* Modal Actions */}
<div className="flex items-center justify-between gap-3 pt-2">
<div className="flex items-center gap-2">
{selectedTx.status !== 'VERIFIED' && (
<button
type="button"
onClick={() => handleManualVerify(selectedTx.id)}
className="bg-emerald-600 hover:bg-emerald-700 text-white font-black px-4 py-2.5 rounded-xl text-xs flex items-center gap-1.5 shadow-md shadow-emerald-600/20 transition-all cursor-pointer"
>
<CheckCircle2 className="w-4 h-4" />
<span>تایید دستی و اعمال مالی</span>
</button>
)}
{selectedTx.status === 'PENDING' && (
<button
type="button"
onClick={() => handleManualReject(selectedTx.id)}
className="bg-rose-50 hover:bg-rose-100 text-rose-700 border border-rose-200 font-bold px-4 py-2.5 rounded-xl text-xs flex items-center gap-1.5 transition-all cursor-pointer"
>
<XCircle className="w-4 h-4" />
<span>رد کردن تراکنش</span>
</button>
)}
</div>
<button
type="button"
onClick={() => {
setSelectedTx(null);
setLiveInquiryData(null);
setShowRawLogs(false);
}}
className="bg-gray-100 hover:bg-gray-200 text-gray-800 font-bold px-6 py-2.5 rounded-xl text-xs transition-colors"
className="bg-gray-100 hover:bg-gray-200 text-gray-800 font-bold px-6 py-2.5 rounded-xl text-xs transition-colors cursor-pointer"
>
بستن
</button>
@@ -36,6 +36,7 @@ const SystemSettingsPage = lazy(() => import('../pages/SystemSettingsPage'));
const SmsSettingsPage = lazy(() => import('../pages/SmsSettingsPage'));
const SslSettingsPage = lazy(() => import('../pages/SslSettingsPage'));
const Transactions = lazy(() => import('../pages/Transactions'));
const Tickets = lazy(() => import('../pages/Tickets'));
export interface AdminRouteConfig {
path: string;
@@ -84,6 +85,7 @@ export const router = createBrowserRouter([
{ path: 'b2b/*', element: <B2BManager /> },
{ path: 'wholesale/*', element: <WholesaleApplications /> },
{ path: 'contact/*', element: <ContactSubmissions /> },
{ path: 'tickets/*', element: <Tickets /> },
],
},
],