MCPcopy Create free account
hub / github.com/9d8dev/directory / handleSubmit

Function handleSubmit

components/admin/bookmark-manager.tsx:153–196  ·  view source on GitHub ↗
(e: React.FormEvent<HTMLFormElement>)

Source from the content-addressed store, hash-verified

151
152 // Handle form submission
153 const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
154 e.preventDefault();
155 setIsSaving(true);
156
157 try {
158 const formData = new FormData(e.currentTarget);
159 const formDataObject = {
160 title: formData.get("title") as string,
161 description: formData.get("description") as string,
162 url: formData.get("url") as string,
163 slug: formData.get("slug") as string,
164 overview: formData.get("overview") as string,
165 favicon: formData.get("favicon") as string,
166 ogImage: formData.get("ogImage") as string,
167 search_results: formData.get("search_results") as string,
168 categoryId: formData.get("categoryId") as string,
169 isFavorite: formData.get("isFavorite") as string,
170 isArchived: formData.get("isArchived") as string,
171 };
172
173 if (!isNewBookmark) {
174 (formDataObject as any).id = formData.get("id") as string;
175 }
176
177 const result = isNewBookmark
178 ? await createBookmark(null, formDataObject)
179 : await updateBookmark(null, formDataObject as any);
180
181 if (result.error) {
182 toast.error(result.error);
183 } else {
184 toast.success(
185 isNewBookmark ? "Bookmark created!" : "Bookmark updated!",
186 );
187 setIsSheetOpen(false);
188 resetForm();
189 }
190 } catch (err) {
191 console.error("Error saving bookmark:", err);
192 toast.error("Failed to save bookmark");
193 } finally {
194 setIsSaving(false);
195 }
196 };
197
198 // Reset form when sheet opens/closes
199 useEffect(() => {

Callers

nothing calls this directly

Calls 3

createBookmarkFunction · 0.90
updateBookmarkFunction · 0.90
resetFormFunction · 0.85

Tested by

no test coverage detected