import { useState, ReactNode } from 'react'; import { validateNodeConfig } from '../utils/wireguardConfig'; import './NodeEditor.css'; interface NodeData { label: string; ipAddress: string; listenPort: string; privateKey: string; publicKey: string; endpoint?: string; dnsServers?: string; persistentKeepalive?: string; } interface NodeEditorProps { node: NodeData; onUpdate: (data: NodeData) => void; onClose: () => void; } export default function NodeEditor({ node, onUpdate, onClose }: NodeEditorProps): ReactNode { const [formData, setFormData] = useState(node); const [errors, setErrors] = useState([]); const handleInputChange = (field: keyof NodeData, value: string): void => { setFormData(prev => ({ ...prev, [field]: value })); }; const handleSave = (): void => { const validation = validateNodeConfig(formData); if (!validation.isValid) { setErrors(validation.errors); return; } setErrors([]); onUpdate(formData); onClose(); }; return (

编辑节点: {formData.label || '新节点'}

{errors.length > 0 && (
{errors.map((error, idx) => (

• {error}

))}
)}
handleInputChange('label', e.target.value)} placeholder="例如: Node-A" />
handleInputChange('ipAddress', e.target.value)} placeholder="例如: 10.0.0.1" />
handleInputChange('listenPort', e.target.value)} placeholder="例如: 51820" />