(event: FormEvent)
| 158 | }; |
| 159 | |
| 160 | const submitAddScript = async (event: FormEvent) => { |
| 161 | event.preventDefault(); |
| 162 | const trimmedName = name.trim(); |
| 163 | const trimmedCommand = command.trim(); |
| 164 | if (trimmedName.length === 0) { |
| 165 | setValidationError("Name is required."); |
| 166 | return; |
| 167 | } |
| 168 | if (trimmedCommand.length === 0) { |
| 169 | setValidationError("Command is required."); |
| 170 | return; |
| 171 | } |
| 172 | |
| 173 | setValidationError(null); |
| 174 | let payload: NewProjectScriptInput; |
| 175 | try { |
| 176 | const scriptIdForValidation = |
| 177 | editingScriptId ?? |
| 178 | nextProjectScriptId( |
| 179 | trimmedName, |
| 180 | scripts.map((script) => script.id), |
| 181 | ); |
| 182 | const keybindingRule = decodeProjectScriptKeybindingRule({ |
| 183 | keybinding, |
| 184 | command: commandForProjectScript(scriptIdForValidation), |
| 185 | }); |
| 186 | const trimmedPreviewUrl = previewUrl.trim(); |
| 187 | payload = { |
| 188 | name: trimmedName, |
| 189 | command: trimmedCommand, |
| 190 | icon, |
| 191 | runOnWorktreeCreate, |
| 192 | keybinding: keybindingRule?.key ?? null, |
| 193 | previewUrl: trimmedPreviewUrl.length > 0 ? trimmedPreviewUrl : null, |
| 194 | autoOpenPreview: trimmedPreviewUrl.length > 0 ? autoOpenPreview : false, |
| 195 | } satisfies NewProjectScriptInput; |
| 196 | } catch (error) { |
| 197 | setValidationError(error instanceof Error ? error.message : "Failed to save action."); |
| 198 | return; |
| 199 | } |
| 200 | |
| 201 | const result = editingScriptId |
| 202 | ? await onUpdateScript(editingScriptId, payload) |
| 203 | : await onAddScript(payload); |
| 204 | if (result._tag === "Failure") { |
| 205 | if (!isAtomCommandInterrupted(result)) { |
| 206 | const error = squashAtomCommandFailure(result); |
| 207 | setValidationError(error instanceof Error ? error.message : "Failed to save action."); |
| 208 | } |
| 209 | return; |
| 210 | } |
| 211 | setDialogOpen(false); |
| 212 | setIconPickerOpen(false); |
| 213 | }; |
| 214 | |
| 215 | const openAddDialog = () => { |
| 216 | setEditingScriptId(null); |
nothing calls this directly
no test coverage detected