import React, { useState } from 'react'; import { Button } from '@/components/ui/index'; import { Input } from '@/components/ui/index'; import { Label } from '@/components/ui/index'; import { DialogFooter } from '@/components/ui/index'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/index'; import { Alert, AlertDescription, AlertTitle } from '@/components/ui/index'; interface RemoteConfig { id?: string; name: string; url: string; username: string; password?: string; tokenName?: string; tokenValue?: string; type: 'pve' | 'pbs'; fingerprint?: string; verifyCertificate: boolean; description?: string; } interface AddRemoteFormProps { onAdd: (config: RemoteConfig) => void; onCancel: () => void; } export function AddRemoteForm({ onAdd, onCancel }: AddRemoteFormProps) { const [config, setConfig] = useState({ name: '', url: '', username: '', password: '', tokenName: '', tokenValue: '', type: 'pve', verifyCertificate: true, description: '', }); const [error, setError] = useState(''); const [loading, setLoading] = useState(false); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(''); if (!config.name.trim()) { setError('Remote name is required'); return; } if (!config.url.trim()) { setError('URL is required'); return; } if (!config.username.trim()) { setError('Username is required'); return; } setLoading(true); try { await onAdd(config); } catch (err) { setError(err instanceof Error ? err.message : 'Failed to add remote'); } finally { setLoading(false); } }; return (
{error && ( Error {error} )}
setConfig({ ...config, name: e.target.value })} placeholder="e.g., Production Cluster" disabled={loading} />
setConfig({ ...config, url: e.target.value })} placeholder="https://pve.example.com:8006" disabled={loading} />
setConfig({ ...config, username: e.target.value })} placeholder="root@pam" disabled={loading} />
setConfig({ ...config, password: e.target.value })} placeholder="Enter password" disabled={loading} />

Leave blank to use API token authentication

setConfig({ ...config, tokenName: e.target.value })} placeholder="e.g., mytoken" disabled={loading} />
setConfig({ ...config, tokenValue: e.target.value })} placeholder="Enter token value" disabled={loading} />
setConfig({ ...config, verifyCertificate: e.target.checked }) } disabled={loading} className="rounded border-gray-300 text-primary focus:ring-primary" />
setConfig({ ...config, description: e.target.value })} placeholder="Optional description" disabled={loading} />
); }