feat: add confirmation popover for user deletion in TableList component
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
'use client';
|
'use client';
|
||||||
import { useEffect } from 'react';
|
import React, { useEffect } from 'react';
|
||||||
import { useForm } from 'react-hook-form';
|
import { useForm } from 'react-hook-form';
|
||||||
import { useUserStore } from './store/user';
|
import { useUserStore } from './store/user';
|
||||||
import { useAdminStore } from './store/admin';
|
import { useAdminStore } from './store/admin';
|
||||||
@@ -19,12 +19,25 @@ import {
|
|||||||
DialogHeader,
|
DialogHeader,
|
||||||
DialogTitle,
|
DialogTitle,
|
||||||
} from '@/components/ui/dialog';
|
} from '@/components/ui/dialog';
|
||||||
|
import {
|
||||||
|
Popover,
|
||||||
|
PopoverContent,
|
||||||
|
PopoverTrigger,
|
||||||
|
} from '@/components/ui/popover';
|
||||||
import { Plus, Pencil, Trash2 } from 'lucide-react';
|
import { Plus, Pencil, Trash2 } from 'lucide-react';
|
||||||
import { LayoutMain } from '@/modules/layout';
|
import { LayoutMain } from '@/modules/layout';
|
||||||
|
|
||||||
const TableList = () => {
|
const TableList = () => {
|
||||||
const { list, setShowEdit, setFormData, } = useUserStore();
|
const { list, setShowEdit, setFormData, getList } = useUserStore();
|
||||||
const { deleteUser } = useAdminStore()
|
const { deleteUser } = useAdminStore();
|
||||||
|
const [openPopover, setOpenPopover] = React.useState<string | null>(null);
|
||||||
|
|
||||||
|
const handleDelete = async (id: string) => {
|
||||||
|
await deleteUser(id);
|
||||||
|
setOpenPopover(null);
|
||||||
|
getList();
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="rounded-md border">
|
<div className="rounded-md border">
|
||||||
<Table>
|
<Table>
|
||||||
@@ -53,13 +66,42 @@ const TableList = () => {
|
|||||||
<Pencil className="w-4 h-4 mr-1" />
|
<Pencil className="w-4 h-4 mr-1" />
|
||||||
编辑
|
编辑
|
||||||
</Button>
|
</Button>
|
||||||
|
<Popover
|
||||||
|
open={openPopover === user.id}
|
||||||
|
onOpenChange={(open) => setOpenPopover(open ? user.id : null)}
|
||||||
|
>
|
||||||
|
<PopoverTrigger asChild>
|
||||||
<Button
|
<Button
|
||||||
variant="destructive"
|
variant="destructive"
|
||||||
size="sm"
|
size="sm"
|
||||||
onClick={() => deleteUser(user.id)}>
|
>
|
||||||
<Trash2 className="w-4 h-4 mr-1" />
|
<Trash2 className="w-4 h-4 mr-1" />
|
||||||
删除
|
删除
|
||||||
</Button>
|
</Button>
|
||||||
|
</PopoverTrigger>
|
||||||
|
<PopoverContent className="w-auto p-4" align="start">
|
||||||
|
<div className="space-y-3">
|
||||||
|
<p className="text-sm font-medium">确认删除用户 "{user.username}"?</p>
|
||||||
|
<p className="text-xs text-muted-foreground">此操作无法撤销。</p>
|
||||||
|
<div className="flex gap-2 justify-end">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => setOpenPopover(null)}
|
||||||
|
>
|
||||||
|
取消
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="destructive"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => handleDelete(user.id)}
|
||||||
|
>
|
||||||
|
确认删除
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</PopoverContent>
|
||||||
|
</Popover>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))}
|
))}
|
||||||
|
|||||||
Reference in New Issue
Block a user