(e: React.FormEvent)
| 150 | }, [pasteInput]); |
| 151 | |
| 152 | const handleSubmit = async (e: React.FormEvent) => { |
| 153 | e.preventDefault(); |
| 154 | setError(""); |
| 155 | |
| 156 | if (!name.trim()) { |
| 157 | setError("Please enter a server name"); |
| 158 | return; |
| 159 | } |
| 160 | |
| 161 | if (name.includes(" ")) { |
| 162 | setError("Server name should not contain spaces"); |
| 163 | return; |
| 164 | } |
| 165 | |
| 166 | let config: MCPConfig; |
| 167 | try { |
| 168 | config = JSON.parse(configJson); |
| 169 | if (typeof config !== "object" || Array.isArray(config)) { |
| 170 | setError("Config must be a JSON object"); |
| 171 | return; |
| 172 | } |
| 173 | } catch { |
| 174 | setError("Invalid JSON"); |
| 175 | return; |
| 176 | } |
| 177 | |
| 178 | try { |
| 179 | setLoading(true); |
| 180 | await onAdd(name, config); |
| 181 | resetForm(); |
| 182 | setOpen(false); |
| 183 | } catch (err: any) { |
| 184 | const msg = err.response?.data?.error || err.message || "Failed to add server"; |
| 185 | setError(msg); |
| 186 | } finally { |
| 187 | setLoading(false); |
| 188 | } |
| 189 | }; |
| 190 | |
| 191 | return ( |
| 192 | <Dialog open={open} onOpenChange={(o) => { setOpen(o); if (!o) resetForm(); }}> |
nothing calls this directly
no test coverage detected