fix: 全部页面 confirm() 替换为 ConfirmDialog 组件 — 9个页面统一回调模式
This commit is contained in:
1 parent
41dab3deab
commit
7f6a4bb6df
9 files changed
+153
-62
No files matched your search
@@ -10,6 +10,7 @@ import { userApi, ldapApi } from '@/api/user';
|
||||
import { instanceGroupApi, type InstanceGroup } from '@/api/instanceGroup';
|
||||
import { nameToUsername } from '@/utils/pinyin';
|
||||
import { toast } from '@/hooks/useToast';
|
||||
import { ConfirmDialog } from '@/components/ConfirmDialog';
|
||||
|
||||
/* ───────── Types ───────── */
|
||||
|
||||
@@ -134,6 +135,7 @@ export default function UsersPage() {
|
||||
const [selectedIds, setSelectedIds] = useState<Set<number>>(new Set());
|
||||
const [showBatchMenu, setShowBatchMenu] = useState(false);
|
||||
const [showImport, setShowImport] = useState(false);
|
||||
const [deleteConfirm, setDeleteConfirm] = useState<{msg: string; onConfirm: () => void} | null>(null);
|
||||
|
||||
const fetchUsers = useCallback(async () => {
|
||||
setLoading(true);
|
||||
@@ -188,13 +190,15 @@ export default function UsersPage() {
|
||||
};
|
||||
|
||||
const handleDelete = async (id: number) => {
|
||||
if (!confirm('确定删除该用户?此操作不可恢复。')) return;
|
||||
try {
|
||||
await userApi.delete(id);
|
||||
setSelectedIds(prev => { const n = new Set(prev); n.delete(id); return n; });
|
||||
toast('success', '用户已删除');
|
||||
fetchUsers();
|
||||
} catch { toast('error', '删除失败'); }
|
||||
setDeleteConfirm({msg: '确定删除该用户?此操作不可恢复。', onConfirm: async () => {
|
||||
try {
|
||||
await userApi.delete(id);
|
||||
setSelectedIds(prev => { const n = new Set(prev); n.delete(id); return n; });
|
||||
toast('success', '用户已删除');
|
||||
fetchUsers();
|
||||
} catch { toast('error', '删除失败'); }
|
||||
}});
|
||||
return;
|
||||
};
|
||||
|
||||
const handleBatchAction = async (action: string) => {
|
||||
@@ -521,6 +525,14 @@ export default function UsersPage() {
|
||||
{showImport && (
|
||||
<BatchImportModal onClose={() => setShowImport(false)} onImported={() => { setShowImport(false); fetchUsers(); }} />
|
||||
)}
|
||||
<ConfirmDialog
|
||||
open={!!deleteConfirm}
|
||||
title={deleteConfirm?.msg || '确认操作'}
|
||||
variant="danger"
|
||||
confirmText="确定"
|
||||
onConfirm={() => { deleteConfirm?.onConfirm(); }}
|
||||
onCancel={() => setDeleteConfirm(null)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -888,6 +900,7 @@ function BatchImportModal({ onClose, onImported }: { onClose: () => void; onImpo
|
||||
const [newOuName, setNewOuName] = useState('');
|
||||
const [newOuDesc, setNewOuDesc] = useState('');
|
||||
const [creatingOu, setCreatingOu] = useState(false);
|
||||
const [deleteConfirm, setDeleteConfirm] = useState<{msg: string; onConfirm: () => void} | null>(null);
|
||||
|
||||
// Check LDAP readiness
|
||||
useEffect(() => {
|
||||
|
||||
Reference in new issue
Block a user