From 53d64f30b116128cdd4e2adcbafb012f3202e405 Mon Sep 17 00:00:00 2001
From: Sean Hatfield <seanhatfield5@gmail.com>
Date: Thu, 8 Aug 2024 13:37:17 -0700
Subject: [PATCH] Slash commands edit bug fix (#2073)

slash commands edit bug fix
---
 .../SlashCommands/SlashPresets/EditPresetModal.jsx     | 10 ++++++++--
 .../PromptInput/SlashCommands/SlashPresets/index.jsx   |  9 +++++++--
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/frontend/src/components/WorkspaceChat/ChatContainer/PromptInput/SlashCommands/SlashPresets/EditPresetModal.jsx b/frontend/src/components/WorkspaceChat/ChatContainer/PromptInput/SlashCommands/SlashPresets/EditPresetModal.jsx
index 4af3130a0..f3423d2f8 100644
--- a/frontend/src/components/WorkspaceChat/ChatContainer/PromptInput/SlashCommands/SlashPresets/EditPresetModal.jsx
+++ b/frontend/src/components/WorkspaceChat/ChatContainer/PromptInput/SlashCommands/SlashPresets/EditPresetModal.jsx
@@ -1,4 +1,4 @@
-import { useState } from "react";
+import { useState, useEffect } from "react";
 import { X } from "@phosphor-icons/react";
 import ModalWrapper from "@/components/ModalWrapper";
 import { CMD_REGEX } from ".";
@@ -10,9 +10,15 @@ export default function EditPresetModal({
   onDelete,
   preset,
 }) {
-  const [command, setCommand] = useState(preset?.command?.slice(1) || "");
+  const [command, setCommand] = useState("");
   const [deleting, setDeleting] = useState(false);
 
+  useEffect(() => {
+    if (preset && isOpen) {
+      setCommand(preset.command?.slice(1) || "");
+    }
+  }, [preset, isOpen]);
+
   const handleSubmit = (e) => {
     e.preventDefault();
     const form = new FormData(e.target);
diff --git a/frontend/src/components/WorkspaceChat/ChatContainer/PromptInput/SlashCommands/SlashPresets/index.jsx b/frontend/src/components/WorkspaceChat/ChatContainer/PromptInput/SlashCommands/SlashPresets/index.jsx
index ca39b68a8..edef845c1 100644
--- a/frontend/src/components/WorkspaceChat/ChatContainer/PromptInput/SlashCommands/SlashPresets/index.jsx
+++ b/frontend/src/components/WorkspaceChat/ChatContainer/PromptInput/SlashCommands/SlashPresets/index.jsx
@@ -62,13 +62,18 @@ export default function SlashPresets({ setShowing, sendCommand }) {
     }
 
     fetchPresets();
-    closeEditModal();
+    closeEditModalAndResetPreset();
   };
 
   const handleDeletePreset = async (presetId) => {
     await System.deleteSlashCommandPreset(presetId);
     fetchPresets();
+    closeEditModalAndResetPreset();
+  };
+
+  const closeEditModalAndResetPreset = () => {
     closeEditModal();
+    setSelectedPreset(null);
   };
 
   return (
@@ -116,7 +121,7 @@ export default function SlashPresets({ setShowing, sendCommand }) {
       {selectedPreset && (
         <EditPresetModal
           isOpen={isEditModalOpen}
-          onClose={closeEditModal}
+          onClose={closeEditModalAndResetPreset}
           onSave={handleUpdatePreset}
           onDelete={handleDeletePreset}
           preset={selectedPreset}
-- 
GitLab