feat(representation): update representation deactivation logic and enhance API documentation

This commit is contained in:
hamed
2026-06-19 00:46:34 +03:30
parent 0f3bf68fdd
commit 2943e29663
3 changed files with 41 additions and 19 deletions
+16 -13
View File
@@ -1,7 +1,7 @@
import React, { useState } from 'react';
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { useNavigate } from 'react-router-dom';
import { EyeIcon, TrashIcon, PlusIcon, MagnifyingGlassIcon } from '@heroicons/react/24/outline';
import { EyeIcon, NoSymbolIcon, PlusIcon, MagnifyingGlassIcon } from '@heroicons/react/24/outline';
import { useForm, Controller } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { z } from 'zod';
@@ -75,10 +75,11 @@ export default function RepresentationsPage() {
onError: (err: Error) => toast.error(err.message),
});
const deleteMutation = useMutation({
mutationFn: (r: Representation) => api.delete<ApiResponse<null>>(`/api/v1/representation/${r.uuid}`),
const deactivateMutation = useMutation({
mutationFn: (r: Representation) =>
api.patch<ApiResponse<Representation>>(`/api/v1/representation/${r.uuid}`, { active: false }),
onSuccess: () => {
toast.success('نماینده حذف شد');
toast.success('نماینده غیرفعال شد');
setDeleteTarget(null);
qc.invalidateQueries({ queryKey: ['representations'] });
},
@@ -146,10 +147,12 @@ export default function RepresentationsPage() {
className="mini-btn" title="مشاهده">
<EyeIcon style={{ width: 15, height: 15 }} />
</button>
<button onClick={() => setDeleteTarget(rep)}
className="mini-btn danger" title="حذف">
<TrashIcon style={{ width: 15, height: 15 }} />
</button>
{(rep.is_active ?? rep.active) && (
<button onClick={() => setDeleteTarget(rep)}
className="mini-btn danger" title="غیرفعال‌سازی">
<NoSymbolIcon style={{ width: 15, height: 15 }} />
</button>
)}
</>
)}
/>
@@ -206,12 +209,12 @@ export default function RepresentationsPage() {
<ConfirmDialog
open={!!deleteTarget}
title="حذف نماینده"
message={`آیا از حذف نماینده "${deleteTarget?.full_name}" اطمینان دارید؟`}
confirmLabel="حذف"
title="غیرفعال‌سازی نماینده"
message={`آیا از غیرفعال‌سازی نماینده "${deleteTarget?.full_name}" اطمینان دارید؟ این نماینده دیگر فعال نخواهد بود.`}
confirmLabel="غیرفعال‌سازی"
danger
loading={deleteMutation.isPending}
onConfirm={() => deleteTarget && deleteMutation.mutate(deleteTarget)}
loading={deactivateMutation.isPending}
onConfirm={() => deleteTarget && deactivateMutation.mutate(deleteTarget)}
onCancel={() => setDeleteTarget(null)}
/>
</div>