#591 - server-ssh-keys

This commit is contained in:
Saeed Vaziry
2025-05-29 21:20:33 +02:00
parent 8b6f65db97
commit 0fce4dba9c
22 changed files with 438 additions and 195 deletions

View File

@ -0,0 +1,50 @@
import { useQuery } from '@tanstack/react-query';
import axios from 'axios';
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
import React from 'react';
import { SelectTriggerProps } from '@radix-ui/react-select';
import { SshKey } from '@/types/ssh-key';
import AddSshKey from '@/pages/ssh-keys/components/add-ssh-key';
import { Button } from '@/components/ui/button';
import { PlusIcon } from 'lucide-react';
export default function SshKeySelect({
value,
onValueChange,
...props
}: {
value: string;
onValueChange: (value: string) => void;
} & SelectTriggerProps) {
const query = useQuery<SshKey[]>({
queryKey: ['sshKey'],
queryFn: async () => {
return (await axios.get(route('ssh-keys.json'))).data;
},
});
return (
<div className="flex items-center gap-2">
<Select value={value} onValueChange={onValueChange} disabled={query.isFetching}>
<SelectTrigger {...props}>
<SelectValue placeholder={query.isFetching ? 'Loading...' : 'Select a key'} />
</SelectTrigger>
<SelectContent>
<SelectGroup>
{query.isSuccess &&
query.data.map((sshKey: SshKey) => (
<SelectItem key={`db-${sshKey.name}`} value={sshKey.id.toString()}>
{sshKey.name}
</SelectItem>
))}
</SelectGroup>
</SelectContent>
</Select>
<AddSshKey onKeyAdded={() => query.refetch()}>
<Button variant="outline">
<PlusIcon />
</Button>
</AddSshKey>
</div>
);
}