(e: React.FormEvent<HTMLFormElement>)
| 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(() => { |
nothing calls this directly
no test coverage detected