MCPcopy Create free account
hub / github.com/Microck/opencode-studio / handleSubmit

Function handleSubmit

client-next/src/components/add-mcp-dialog.tsx:152–189  ·  view source on GitHub ↗
(e: React.FormEvent)

Source from the content-addressed store, hash-verified

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(); }}>

Callers

nothing calls this directly

Calls 1

resetFormFunction · 0.70

Tested by

no test coverage detected