mirror of
https://github.com/Buriburizaem0n/admin-frontend-domain.git
synced 2026-02-04 12:40:08 +00:00
* further implementing server page * optimize icon button * rename some unnecessary file extensions * add terminal page & fm card
51 lines
1.8 KiB
TypeScript
51 lines
1.8 KiB
TypeScript
import { IconButton } from "@/components/xui/icon-button";
|
|
import {
|
|
AlertDialog,
|
|
AlertDialogAction,
|
|
AlertDialogCancel,
|
|
AlertDialogContent,
|
|
AlertDialogDescription,
|
|
AlertDialogFooter,
|
|
AlertDialogHeader,
|
|
AlertDialogTitle,
|
|
AlertDialogTrigger,
|
|
} from "@/components/ui/alert-dialog"
|
|
import { KeyedMutator } from "swr";
|
|
import { buttonVariants } from "@/components/ui/button"
|
|
|
|
interface ButtonGroupProps<T> {
|
|
className?: string;
|
|
children: React.ReactNode;
|
|
delete: { fn: (id: number[]) => Promise<void>, id: number, mutate: KeyedMutator<T> };
|
|
}
|
|
|
|
export function ActionButtonGroup<T>({ className, children, delete: { fn, id, mutate } }: ButtonGroupProps<T>) {
|
|
const handleDelete = async () => {
|
|
await fn([id]);
|
|
await mutate();
|
|
}
|
|
|
|
return (
|
|
<div className={className}>
|
|
{children}
|
|
<AlertDialog>
|
|
<AlertDialogTrigger asChild>
|
|
<IconButton variant="outline" icon="trash" />
|
|
</AlertDialogTrigger>
|
|
<AlertDialogContent className="sm:max-w-lg">
|
|
<AlertDialogHeader>
|
|
<AlertDialogTitle>Confirm Deletion?</AlertDialogTitle>
|
|
<AlertDialogDescription>
|
|
This operation is unrecoverable!
|
|
</AlertDialogDescription>
|
|
</AlertDialogHeader>
|
|
<AlertDialogFooter>
|
|
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
|
<AlertDialogAction className={buttonVariants({ variant: "destructive" })} onClick={handleDelete}>Confirm</AlertDialogAction>
|
|
</AlertDialogFooter>
|
|
</AlertDialogContent>
|
|
</AlertDialog>
|
|
</div>
|
|
)
|
|
}
|