mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-03 06:56:15 +00:00
#591 - ssh-keys
This commit is contained in:
79
resources/js/pages/ssh-keys/components/add-ssh-key.tsx
Normal file
79
resources/js/pages/ssh-keys/components/add-ssh-key.tsx
Normal file
@ -0,0 +1,79 @@
|
||||
import { LoaderCircle } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Dialog,
|
||||
DialogClose,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from '@/components/ui/dialog';
|
||||
import { useForm } from '@inertiajs/react';
|
||||
import { FormEventHandler, ReactNode, useState } from 'react';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import InputError from '@/components/ui/input-error';
|
||||
import { Form, FormField, FormFields } from '@/components/ui/form';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
|
||||
type SshKeyForm = {
|
||||
name: string;
|
||||
public_key: string;
|
||||
};
|
||||
|
||||
export default function AddSshKey({ children }: { children: ReactNode }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
const form = useForm<Required<SshKeyForm>>({
|
||||
name: '',
|
||||
public_key: '',
|
||||
});
|
||||
|
||||
const submit: FormEventHandler = (e) => {
|
||||
e.preventDefault();
|
||||
form.post(route('ssh-keys.store'), {
|
||||
onSuccess: () => {
|
||||
setOpen(false);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogTrigger asChild>{children}</DialogTrigger>
|
||||
<DialogContent className="sm:max-w-xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Add ssh key</DialogTitle>
|
||||
<DialogDescription className="sr-only">Add new ssh key</DialogDescription>
|
||||
</DialogHeader>
|
||||
<Form id="add-ssh-key-form" onSubmit={submit} className="p-4">
|
||||
<FormFields>
|
||||
<FormField>
|
||||
<Label htmlFor="name">Name</Label>
|
||||
<Input type="text" name="name" id="name" value={form.data.name} onChange={(e) => form.setData('name', e.target.value)} />
|
||||
<InputError message={form.errors.name} />
|
||||
</FormField>
|
||||
<FormField>
|
||||
<Label htmlFor="key">Public key</Label>
|
||||
<Textarea name="public_key" id="public_key" value={form.data.public_key} onChange={(e) => form.setData('public_key', e.target.value)} />
|
||||
<InputError message={form.errors.public_key} />
|
||||
</FormField>
|
||||
</FormFields>
|
||||
</Form>
|
||||
<DialogFooter>
|
||||
<DialogClose asChild>
|
||||
<Button type="button" variant="outline">
|
||||
Cancel
|
||||
</Button>
|
||||
</DialogClose>
|
||||
<Button type="button" onClick={submit} disabled={form.processing}>
|
||||
{form.processing && <LoaderCircle className="animate-spin" />}
|
||||
Connect
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
105
resources/js/pages/ssh-keys/components/columns.tsx
Normal file
105
resources/js/pages/ssh-keys/components/columns.tsx
Normal file
@ -0,0 +1,105 @@
|
||||
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>
|
||||
);
|
||||
},
|
||||
},
|
||||
];
|
38
resources/js/pages/ssh-keys/index.tsx
Normal file
38
resources/js/pages/ssh-keys/index.tsx
Normal file
@ -0,0 +1,38 @@
|
||||
import SettingsLayout from '@/layouts/settings/layout';
|
||||
import { Head, usePage } from '@inertiajs/react';
|
||||
import Container from '@/components/container';
|
||||
import Heading from '@/components/heading';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { DataTable } from '@/components/data-table';
|
||||
import React from 'react';
|
||||
import { SSHKey } from '@/types/ssh-key';
|
||||
import { columns } from '@/pages/ssh-keys/components/columns';
|
||||
import AddSshKey from '@/pages/ssh-keys/components/add-ssh-key';
|
||||
|
||||
type Page = {
|
||||
sshKeys: {
|
||||
data: SSHKey[];
|
||||
};
|
||||
};
|
||||
|
||||
export default function SshKeys() {
|
||||
const page = usePage<Page>();
|
||||
|
||||
return (
|
||||
<SettingsLayout>
|
||||
<Head title="SSH Keys" />
|
||||
<Container className="max-w-5xl">
|
||||
<div className="flex items-start justify-between">
|
||||
<Heading title="SSH Keys" description="Here you can manage all of your ssh keys" />
|
||||
<div className="flex items-center gap-2">
|
||||
<AddSshKey>
|
||||
<Button>Add</Button>
|
||||
</AddSshKey>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<DataTable columns={columns} data={page.props.sshKeys.data} />
|
||||
</Container>
|
||||
</SettingsLayout>
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user