'use client' import React from 'react' import { trpc } from '@/lib/trpc' import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from '@/components/ui/alert-dialog' import { toast } from 'sonner' interface DeptAdminDeleteDialogProps { deptAdminId: number | null isOpen: boolean onClose: () => void onDeptAdminDeleted: () => void } export function DeptAdminDeleteDialog({ deptAdminId, isOpen, onClose, onDeptAdminDeleted, }: DeptAdminDeleteDialogProps) { // 获取院系管理员详情 const { data: deptAdmin } = trpc.deptAdmin.getById.useQuery( { id: deptAdminId! }, { enabled: !!deptAdminId && isOpen } ) // 删除院系管理员 mutation const deleteDeptAdminMutation = trpc.deptAdmin.delete.useMutation({ onSuccess: () => { onClose() toast.success('院系管理员删除成功') onDeptAdminDeleted() }, onError: (error) => { toast.error(error.message || '删除院系管理员失败') }, }) const handleConfirm = () => { if (deptAdminId) { deleteDeptAdminMutation.mutate({ id: deptAdminId }) } } return ( !open && onClose()}> 确认删除 {deptAdmin ? ( <> 确定要删除院系管理员 {deptAdmin.user?.name || deptAdmin.uid}{deptAdmin.dept?.name || deptAdmin.deptCode} 的管理权限吗?
此操作无法撤销。 ) : ( '确定要删除该院系管理员吗?此操作无法撤销。' )}
取消 {deleteDeptAdminMutation.isPending ? '删除中...' : '确认删除'}
) }