diff --git a/src/static/Strategies.js b/src/static/Strategies.js index 991af5c..7c0a39d 100644 --- a/src/static/Strategies.js +++ b/src/static/Strategies.js @@ -1461,9 +1461,17 @@ class Strategies { if (data.success && data.strategy) { this.dataManager.addNewStrategy(data.strategy); this.uiManager.updateStrategiesHtml(this.dataManager.getAllStrategies()); + // Close the dialog only on success + this.uiManager.hideForm(); } else { console.error("Failed to create strategy:", data.message); - alert(`Strategy creation failed: ${data.message}`); + // Keep dialog open and show error - user can fix the issue + const errorMsg = data.message || 'Unknown error'; + if (errorMsg.toLowerCase().includes('name') || errorMsg.toLowerCase().includes('exists')) { + alert(`Strategy name already exists. Please choose a different name.`); + } else { + alert(`Strategy creation failed: ${errorMsg}`); + } } } @@ -1475,6 +1483,9 @@ class Strategies { if (data.success) { console.log("Strategy updated successfully:", data); + // Close the dialog on success + this.uiManager.hideForm(); + // Locate the strategy in the local state by its tbl_key const updatedStrategyKey = data.strategy.tbl_key; const updatedAt = data.updated_at; @@ -1523,7 +1534,13 @@ class Strategies { } } else { console.error("Failed to update strategy:", data.message); - alert(`Strategy update failed: ${data.message}`); + // Keep dialog open and show error - user can fix the issue + const errorMsg = data.message || 'Unknown error'; + if (errorMsg.toLowerCase().includes('name') || errorMsg.toLowerCase().includes('exists')) { + alert(`Strategy name already exists. Please choose a different name.`); + } else { + alert(`Strategy update failed: ${errorMsg}`); + } } } @@ -1704,7 +1721,8 @@ class Strategies { // Determine message type based on action const messageType = action === 'new' ? 'new_strategy' : 'edit_strategy'; this.comms.sendToApp(messageType, strategyData); - this.uiManager.hideForm(); + // Don't hide form here - wait for server response + // Form will be hidden in handleStrategyCreated/handleStrategyUpdated on success } else { console.error("Comms instance not available or invalid action type."); }