feat(admin): add WholesaleApplications page for B2B clinic license review and role approval
This commit is contained in:
1 parent
a999627d28
commit
510c2f90de
5 files changed
+131
-17
No files matched your search
@@ -17,6 +17,7 @@ import Pets from './pages/Pets';
|
||||
import UITexts from './pages/UITexts';
|
||||
import Media from './pages/Media';
|
||||
import CMS from './pages/CMS';
|
||||
import WholesaleApplications from './pages/WholesaleApplications';
|
||||
|
||||
function App() {
|
||||
return (
|
||||
@@ -40,6 +41,7 @@ function App() {
|
||||
<Route path="ui-texts" element={<UITexts />} />
|
||||
<Route path="media" element={<Media />} />
|
||||
<Route path="cms" element={<CMS />} />
|
||||
<Route path="wholesale" element={<WholesaleApplications />} />
|
||||
</Route>
|
||||
</Route>
|
||||
</Routes>
|
||||
|
||||
@@ -25,6 +25,7 @@ const menuGroups = [
|
||||
items: [
|
||||
{ icon: Users, label: 'کاربران', path: '/users' },
|
||||
{ icon: Heart, label: 'حیوانات (Pets)', path: '/pets' },
|
||||
{ icon: Package, label: 'درخواستهای B2B', path: '/wholesale' },
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import api from '../services/api';
|
||||
|
||||
export default function WholesaleApplications() {
|
||||
const [requests, setRequests] = useState<any[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
fetchRequests();
|
||||
}, []);
|
||||
|
||||
const fetchRequests = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await api.get('/wholesale/requests');
|
||||
setRequests(res.data || []);
|
||||
} catch (err) {
|
||||
console.error('Failed to fetch wholesale requests:', err);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleApprove = async (userId: string) => {
|
||||
if (!confirm('آیا از تایید حساب همکار و اعطای قیمتهای عمده-۳۰٪ مطمئن هستید؟')) return;
|
||||
try {
|
||||
await api.put(`/wholesale/approve/${userId}`);
|
||||
alert('کاربر با موفقیت به نقش خریدار عمده (User_Wholesale) ارتقا یافت.');
|
||||
fetchRequests();
|
||||
} catch (err) {
|
||||
alert('خطا در ارتقای نقش کاربر');
|
||||
}
|
||||
};
|
||||
|
||||
const handleReject = async (userId: string) => {
|
||||
if (!confirm('آیا از رد درخواست همکاری مطمئن هستید؟')) return;
|
||||
try {
|
||||
await api.put(`/wholesale/reject/${userId}`);
|
||||
alert('درخواست رد شد.');
|
||||
fetchRequests();
|
||||
} catch (err) {
|
||||
alert('خطا در رد درخواست');
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="p-6 font-vazir" dir="rtl">
|
||||
<h1 className="text-2xl font-bold mb-2 text-gray-800">بررسی درخواستهای ثبتنام همکاران B2B (کلینیکها و داروخانهها)</h1>
|
||||
<p className="text-sm text-gray-500 mb-6">استعلام شماره پروانه نظام دامپزشکی و اعطای دسترسی خرید عمده با تخفیف ۳۰٪ کاتالوگ Canina</p>
|
||||
|
||||
{loading ? (
|
||||
<div className="text-center py-12 text-gray-500 font-bold">در حال بارگذاری درخواستها...</div>
|
||||
) : (
|
||||
<div className="bg-white rounded-2xl border border-gray-200 overflow-hidden shadow-sm">
|
||||
<table className="w-full text-right">
|
||||
<thead className="bg-gray-50 border-b border-gray-200 text-xs font-bold text-gray-500">
|
||||
<tr>
|
||||
<th className="px-6 py-4">کاربر / ایمیل</th>
|
||||
<th className="px-6 py-4">نقش فعلی</th>
|
||||
<th className="px-6 py-4">تاریخ ثبتنام</th>
|
||||
<th className="px-6 py-4 text-center">عملیات تایید همکار</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-gray-100 text-sm">
|
||||
{requests.length === 0 ? (
|
||||
<tr>
|
||||
<td colSpan={4} className="text-center py-8 text-gray-400 font-medium">هیچ درخواستی در انتظار بررسی یافت نشد.</td>
|
||||
</tr>
|
||||
) : (
|
||||
requests.map((u: any) => (
|
||||
<tr key={u.id} className="hover:bg-gray-50/60 transition-colors">
|
||||
<td className="px-6 py-4">
|
||||
<div className="font-bold text-gray-900">{u.fullName || u.email || 'کاربر بدون نام'}</div>
|
||||
<div className="text-xs text-gray-400 dir-ltr text-right">{u.email || u.phoneNumber}</div>
|
||||
</td>
|
||||
<td className="px-6 py-4">
|
||||
<span className={`inline-flex px-3 py-1 rounded-full text-xs font-bold ${
|
||||
u.role === 'User_Wholesale' ? 'bg-green-100 text-green-700' : 'bg-amber-100 text-amber-700'
|
||||
}`}>
|
||||
{u.role === 'User_Wholesale' ? 'خریدار عمده تاییدشده' : 'در انتظار بررسی B2B'}
|
||||
</span>
|
||||
</td>
|
||||
<td className="px-6 py-4 text-xs text-gray-500 font-mono">
|
||||
{new Date(u.createdAt).toLocaleDateString('fa-IR')}
|
||||
</td>
|
||||
<td className="px-6 py-4 text-center space-x-2 space-x-reverse">
|
||||
{u.role !== 'User_Wholesale' && (
|
||||
<button
|
||||
onClick={() => handleApprove(u.id)}
|
||||
className="bg-green-600 hover:bg-green-700 text-white font-bold text-xs px-4 py-2 rounded-xl transition-all shadow-sm"
|
||||
>
|
||||
تایید و اعطای لایسنس B2B
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
onClick={() => handleReject(u.id)}
|
||||
className="bg-gray-100 hover:bg-red-50 hover:text-red-600 text-gray-600 font-bold text-xs px-4 py-2 rounded-xl transition-all"
|
||||
>
|
||||
رد درخواست
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user