feat: implement admin API for user and representation management
- Updated UsersPage to fetch users from the new admin endpoint. - Enhanced user data structure to include 'name' and modified rendering logic. - Added RepresentationDetailPage for detailed representation management. - Created AdminApiController to handle user and representation CRUD operations. - Implemented pagination and search functionality for users and representations. - Updated user and representation data models to reflect new API structure.
This commit is contained in:
@@ -16,17 +16,16 @@ import Modal from '../components/ui/Modal';
|
||||
const TABS: { key: CategoryBundle; label: string }[] = [
|
||||
{ key: 'state', label: 'استانها' },
|
||||
{ key: 'city', label: 'شهرها' },
|
||||
{ key: 'specialty', label: 'تخصصها' },
|
||||
{ key: 'doctor_service', label: 'خدمات پزشک' },
|
||||
{ key: 'specially_doctor', label: 'تخصصها' },
|
||||
{ key: 'doctor_services', label: 'خدمات پزشک' },
|
||||
{ key: 'insurance_type', label: 'نوع بیمه' },
|
||||
{ key: 'supplementary_insurance', label: 'بیمه تکمیلی' },
|
||||
{ key: 'tag', label: 'تگهای بلاگ' },
|
||||
];
|
||||
|
||||
const schema = z.object({
|
||||
name: z.string().min(1, 'نام الزامی است'),
|
||||
code: z.string().optional(),
|
||||
parent_uuid: z.string().optional(),
|
||||
label: z.string().min(1, 'نام الزامی است'),
|
||||
parent_id: z.string().optional(),
|
||||
});
|
||||
type FormData = z.infer<typeof schema>;
|
||||
|
||||
@@ -41,7 +40,7 @@ export default function CategoriesPage() {
|
||||
const { data, isLoading } = useQuery({
|
||||
queryKey: ['categories', activeTab],
|
||||
queryFn: () =>
|
||||
api.get<ApiResponse<Category[]>>(`/api/v1/categorys/${activeTab}`),
|
||||
api.get<ApiResponse<{ data: Category[] }>>(`/api/v1/categorys/${activeTab}`),
|
||||
});
|
||||
|
||||
const { register, handleSubmit, reset, setValue, formState: { errors, isSubmitting } } = useForm<FormData>({
|
||||
@@ -50,7 +49,11 @@ export default function CategoriesPage() {
|
||||
|
||||
const createMutation = useMutation({
|
||||
mutationFn: (d: FormData) =>
|
||||
api.post<ApiResponse<Category>>('/api/v1/category', { ...d, bundle: activeTab }),
|
||||
api.post<ApiResponse<Category>>('/api/v1/category', {
|
||||
label: d.label,
|
||||
bundle: activeTab,
|
||||
...(d.parent_id ? { parent_id: parseInt(d.parent_id) } : {}),
|
||||
}),
|
||||
onSuccess: () => {
|
||||
toast.success('دستهبندی اضافه شد');
|
||||
setAddOpen(false);
|
||||
@@ -61,8 +64,8 @@ export default function CategoriesPage() {
|
||||
});
|
||||
|
||||
const updateMutation = useMutation({
|
||||
mutationFn: ({ uuid, d }: { uuid: string; d: FormData }) =>
|
||||
api.patch<ApiResponse<Category>>(`/api/v1/category/${uuid}`, d),
|
||||
mutationFn: ({ id, d }: { id: number; d: FormData }) =>
|
||||
api.patch<ApiResponse<Category>>(`/api/v1/category/${id}`, { label: d.label }),
|
||||
onSuccess: () => {
|
||||
toast.success('دستهبندی بروزرسانی شد');
|
||||
setEditTarget(null);
|
||||
@@ -73,7 +76,7 @@ export default function CategoriesPage() {
|
||||
});
|
||||
|
||||
const deleteMutation = useMutation({
|
||||
mutationFn: (c: Category) => api.delete<ApiResponse<null>>(`/api/v1/category/${c.uuid}`),
|
||||
mutationFn: (c: Category) => api.delete<ApiResponse<null>>(`/api/v1/category/${c.id}`),
|
||||
onSuccess: () => {
|
||||
toast.success('دستهبندی حذف شد');
|
||||
setDeleteTarget(null);
|
||||
@@ -84,20 +87,34 @@ export default function CategoriesPage() {
|
||||
|
||||
const openEdit = (c: Category) => {
|
||||
setEditTarget(c);
|
||||
setValue('name', c.name);
|
||||
setValue('code', c.code ?? '');
|
||||
setValue('parent_uuid', c.parent_uuid ?? '');
|
||||
setValue('label', c.label);
|
||||
};
|
||||
|
||||
const allItems = data?.data ?? [];
|
||||
const allItems = data?.data?.data ?? [];
|
||||
const filtered = search
|
||||
? allItems.filter((c) => c.name.includes(search))
|
||||
? allItems.filter((c) => c.label.includes(search))
|
||||
: allItems;
|
||||
|
||||
const columns: Column<Category>[] = [
|
||||
{ key: 'name', header: 'نام', render: (c) => <span className="font-medium">{c.name}</span> },
|
||||
{ key: 'code', header: 'کد', render: (c) => c.code ? <span dir="ltr" className="font-mono text-xs">{c.code}</span> : '—' },
|
||||
{ key: 'parent_name', header: 'والد', render: (c) => c.parent_name ?? '—' },
|
||||
{ key: 'label', header: 'نام', render: (c) => <span className="font-medium">{c.label}</span> },
|
||||
{
|
||||
key: 'bundle',
|
||||
header: 'نوع',
|
||||
render: (c) => (
|
||||
<span className="text-xs bg-gray-100 text-gray-600 px-2 py-0.5 rounded-full">{c.bundle}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'status',
|
||||
header: 'وضعیت',
|
||||
render: (c) => (
|
||||
<span className={`text-xs px-2 py-0.5 rounded-full font-medium ${
|
||||
c.status === 1 ? 'bg-green-100 text-green-700' : 'bg-gray-100 text-gray-500'
|
||||
}`}>
|
||||
{c.status === 1 ? 'فعال' : 'غیرفعال'}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
const handleTabChange = (tab: CategoryBundle) => {
|
||||
@@ -158,6 +175,7 @@ export default function CategoriesPage() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Add Modal */}
|
||||
<Modal open={addOpen} title={`افزودن — ${TABS.find((t) => t.key === activeTab)?.label}`}
|
||||
onClose={() => { setAddOpen(false); reset(); }}
|
||||
footer={
|
||||
@@ -176,25 +194,21 @@ export default function CategoriesPage() {
|
||||
<form id="cat-form" onSubmit={handleSubmit((d) => createMutation.mutate(d))} className="space-y-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">نام</label>
|
||||
<input {...register('name')}
|
||||
<input {...register('label')}
|
||||
className="w-full h-11 border border-gray-300 rounded-[10px] px-3 text-sm focus:outline-none focus:ring-2 focus:ring-primary-500" />
|
||||
{errors.name && <p className="text-red-500 text-xs mt-1">{errors.name.message}</p>}
|
||||
{errors.label && <p className="text-red-500 text-xs mt-1">{errors.label.message}</p>}
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">کد (اختیاری)</label>
|
||||
<input {...register('code')} dir="ltr"
|
||||
className="w-full h-11 border border-gray-300 rounded-[10px] px-3 text-sm focus:outline-none focus:ring-2 focus:ring-primary-500" />
|
||||
</div>
|
||||
{(activeTab === 'city') && (
|
||||
{activeTab === 'city' && (
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">استان (UUID)</label>
|
||||
<input {...register('parent_uuid')} dir="ltr" placeholder="uuid استان"
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">شناسه استان</label>
|
||||
<input {...register('parent_id')} dir="ltr" placeholder="ID عددی استان"
|
||||
className="w-full h-11 border border-gray-300 rounded-[10px] px-3 text-sm focus:outline-none focus:ring-2 focus:ring-primary-500" />
|
||||
</div>
|
||||
)}
|
||||
</form>
|
||||
</Modal>
|
||||
|
||||
{/* Edit Modal */}
|
||||
<Modal open={!!editTarget} title="ویرایش دستهبندی"
|
||||
onClose={() => { setEditTarget(null); reset(); }}
|
||||
footer={
|
||||
@@ -211,18 +225,13 @@ export default function CategoriesPage() {
|
||||
}
|
||||
>
|
||||
<form id="edit-cat-form"
|
||||
onSubmit={handleSubmit((d) => editTarget && updateMutation.mutate({ uuid: editTarget.uuid, d }))}
|
||||
onSubmit={handleSubmit((d) => editTarget && updateMutation.mutate({ id: editTarget.id, d }))}
|
||||
className="space-y-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">نام</label>
|
||||
<input {...register('name')}
|
||||
className="w-full h-11 border border-gray-300 rounded-[10px] px-3 text-sm focus:outline-none focus:ring-2 focus:ring-primary-500" />
|
||||
{errors.name && <p className="text-red-500 text-xs mt-1">{errors.name.message}</p>}
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">کد (اختیاری)</label>
|
||||
<input {...register('code')} dir="ltr"
|
||||
<input {...register('label')}
|
||||
className="w-full h-11 border border-gray-300 rounded-[10px] px-3 text-sm focus:outline-none focus:ring-2 focus:ring-primary-500" />
|
||||
{errors.label && <p className="text-red-500 text-xs mt-1">{errors.label.message}</p>}
|
||||
</div>
|
||||
</form>
|
||||
</Modal>
|
||||
@@ -230,7 +239,7 @@ export default function CategoriesPage() {
|
||||
<ConfirmDialog
|
||||
open={!!deleteTarget}
|
||||
title="حذف دستهبندی"
|
||||
message={`آیا از حذف "${deleteTarget?.name}" اطمینان دارید؟`}
|
||||
message={`آیا از حذف "${deleteTarget?.label}" اطمینان دارید؟`}
|
||||
confirmLabel="حذف"
|
||||
danger
|
||||
loading={deleteMutation.isPending}
|
||||
|
||||
Reference in New Issue
Block a user