Files
admin-frontend-domain/src/components/action-button-group.tsx
UUBulb fc923f3ab1 further implementing server page (#4)
* further implementing server page

* optimize icon button

* rename some unnecessary file extensions

* add terminal page & fm card
2024-11-18 20:48:30 +08:00

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>
)
}