()
| 83 | |
| 84 | |
| 85 | const handleEditSave = async () => { |
| 86 | if (!editingCmd) return; |
| 87 | if (!editingCmd.name.trim()) { |
| 88 | toast.error("Command name is required"); |
| 89 | return; |
| 90 | } |
| 91 | if (!editingCmd.template.trim()) { |
| 92 | toast.error("Template is required"); |
| 93 | return; |
| 94 | } |
| 95 | |
| 96 | // Check for duplicate name only if name changed |
| 97 | if (editingCmd.name !== editingCmd.originalName && commands.some(c => c.name === editingCmd.name.trim())) { |
| 98 | toast.error("Command already exists"); |
| 99 | return; |
| 100 | } |
| 101 | |
| 102 | try { |
| 103 | if (editingCmd.name !== editingCmd.originalName) { |
| 104 | await deleteCommand(editingCmd.originalName); |
| 105 | } |
| 106 | await saveCommand(editingCmd.name.trim(), editingCmd.template); |
| 107 | toast.success(`Command "${editingCmd.name}" updated`); |
| 108 | setEditOpen(false); |
| 109 | setEditingCmd(null); |
| 110 | fetchCommands(); |
| 111 | } catch { |
| 112 | toast.error("Failed to update command"); |
| 113 | } |
| 114 | }; |
| 115 | |
| 116 | |
| 117 | const handleDelete = async (name: string) => { |
nothing calls this directly
no test coverage detected