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 4af3130a0021b217a31e2ac6baa66d6a5588f081..f3423d2f837a1661afbe4790ec3eaf7940b0a7af 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 ca39b68a823ced1552d78c6f9591c91c7cacd1cf..edef845c18a6c8b7b24e27a38705e0be6cfce6c3 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}