mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-01 05:56:16 +00:00
106 lines
3.0 KiB
TypeScript
106 lines
3.0 KiB
TypeScript
import { ColumnDef } from '@tanstack/react-table';
|
|
import DateTime from '@/components/date-time';
|
|
import {
|
|
Dialog,
|
|
DialogClose,
|
|
DialogContent,
|
|
DialogDescription,
|
|
DialogFooter,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
DialogTrigger,
|
|
} from '@/components/ui/dialog';
|
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
|
|
import { Button } from '@/components/ui/button';
|
|
import { useForm } from '@inertiajs/react';
|
|
import { LoaderCircleIcon, MoreVerticalIcon } from 'lucide-react';
|
|
import FormSuccessful from '@/components/form-successful';
|
|
import { useState } from 'react';
|
|
import { SshKey } from '@/types/ssh-key';
|
|
|
|
function Delete({ sshKey }: { sshKey: SshKey }) {
|
|
const [open, setOpen] = useState(false);
|
|
const form = useForm();
|
|
|
|
const submit = () => {
|
|
form.delete(route('ssh-keys.destroy', sshKey.id), {
|
|
onSuccess: () => {
|
|
setOpen(false);
|
|
},
|
|
});
|
|
};
|
|
return (
|
|
<Dialog open={open} onOpenChange={setOpen}>
|
|
<DialogTrigger asChild>
|
|
<DropdownMenuItem variant="destructive" onSelect={(e) => e.preventDefault()}>
|
|
Delete
|
|
</DropdownMenuItem>
|
|
</DialogTrigger>
|
|
<DialogContent>
|
|
<DialogHeader>
|
|
<DialogTitle>Delete {sshKey.name}</DialogTitle>
|
|
<DialogDescription className="sr-only">Delete ssh key</DialogDescription>
|
|
</DialogHeader>
|
|
<p className="p-4">Are you sure you want to delete this key?</p>
|
|
<DialogFooter>
|
|
<DialogClose asChild>
|
|
<Button variant="outline">Cancel</Button>
|
|
</DialogClose>
|
|
<Button variant="destructive" disabled={form.processing} onClick={submit}>
|
|
{form.processing && <LoaderCircleIcon className="animate-spin" />}
|
|
<FormSuccessful successful={form.recentlySuccessful} />
|
|
Delete
|
|
</Button>
|
|
</DialogFooter>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
}
|
|
|
|
export const columns: ColumnDef<SshKey>[] = [
|
|
{
|
|
accessorKey: 'id',
|
|
header: 'ID',
|
|
enableColumnFilter: true,
|
|
enableSorting: true,
|
|
enableHiding: true,
|
|
},
|
|
{
|
|
accessorKey: 'name',
|
|
header: 'Name',
|
|
enableColumnFilter: true,
|
|
enableSorting: true,
|
|
},
|
|
{
|
|
accessorKey: 'created_at',
|
|
header: 'Created at',
|
|
enableColumnFilter: true,
|
|
enableSorting: true,
|
|
cell: ({ row }) => {
|
|
return <DateTime date={row.original.created_at} />;
|
|
},
|
|
},
|
|
{
|
|
id: 'actions',
|
|
enableColumnFilter: false,
|
|
enableSorting: false,
|
|
cell: ({ row }) => {
|
|
return (
|
|
<div className="flex items-center justify-end">
|
|
<DropdownMenu modal={false}>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button variant="ghost" className="h-8 w-8 p-0">
|
|
<span className="sr-only">Open menu</span>
|
|
<MoreVerticalIcon />
|
|
</Button>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent align="end">
|
|
<Delete sshKey={row.original} />
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
</div>
|
|
);
|
|
},
|
|
},
|
|
];
|