Keep strategy dialog open on save failure
Previously the dialog closed immediately after submitting, before knowing if the save succeeded. If there was an error (e.g., duplicate name), users had to recreate their entire strategy. Now the dialog only closes on success, and shows a helpful error message on failure so users can fix the issue without losing work. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
d2f31e7111
commit
5874f1cc7a
|
|
@ -1461,9 +1461,17 @@ class Strategies {
|
||||||
if (data.success && data.strategy) {
|
if (data.success && data.strategy) {
|
||||||
this.dataManager.addNewStrategy(data.strategy);
|
this.dataManager.addNewStrategy(data.strategy);
|
||||||
this.uiManager.updateStrategiesHtml(this.dataManager.getAllStrategies());
|
this.uiManager.updateStrategiesHtml(this.dataManager.getAllStrategies());
|
||||||
|
// Close the dialog only on success
|
||||||
|
this.uiManager.hideForm();
|
||||||
} else {
|
} else {
|
||||||
console.error("Failed to create strategy:", data.message);
|
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) {
|
if (data.success) {
|
||||||
console.log("Strategy updated successfully:", data);
|
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
|
// Locate the strategy in the local state by its tbl_key
|
||||||
const updatedStrategyKey = data.strategy.tbl_key;
|
const updatedStrategyKey = data.strategy.tbl_key;
|
||||||
const updatedAt = data.updated_at;
|
const updatedAt = data.updated_at;
|
||||||
|
|
@ -1523,7 +1534,13 @@ class Strategies {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.error("Failed to update strategy:", data.message);
|
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
|
// Determine message type based on action
|
||||||
const messageType = action === 'new' ? 'new_strategy' : 'edit_strategy';
|
const messageType = action === 'new' ? 'new_strategy' : 'edit_strategy';
|
||||||
this.comms.sendToApp(messageType, strategyData);
|
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 {
|
} else {
|
||||||
console.error("Comms instance not available or invalid action type.");
|
console.error("Comms instance not available or invalid action type.");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue