diff --git a/src/frontend/src/components/chatComponent/index.tsx b/src/frontend/src/components/chatComponent/index.tsx index 80d6fb991..853e21a81 100644 --- a/src/frontend/src/components/chatComponent/index.tsx +++ b/src/frontend/src/components/chatComponent/index.tsx @@ -17,7 +17,6 @@ export default function Chat({ flow }: ChatType): JSX.Element { const isBuilt = useFlowStore((state) => state.isBuilt); const setIsBuilt = useFlowStore((state) => state.setIsBuilt); const currentFlowState = useFlowsManagerStore((state) => state.currentFlowState); - useEffect(() => { const handleKeyDown = (event: KeyboardEvent) => { if ( @@ -60,8 +59,7 @@ export default function Chat({ flow }: ChatType): JSX.Element { } if ( currentFlowState && - currentFlowState.formKeysData && - currentFlowState.formKeysData.input_keys !== null + currentFlowState.input_keys !== null ) { setCanOpen(true); } else { @@ -82,7 +80,6 @@ export default function Chat({ flow }: ChatType): JSX.Element { /> {isBuilt && currentFlowState && - currentFlowState.formKeysData && canOpen && ( { try { - const formKeysData = currentFlowState?.formKeysData; - if (!formKeysData) { - throw new Error("formKeysData is undefined"); + if (!currentFlowState) { + throw new Error("currentFlowState is undefined"); } - const inputKeys = formKeysData.input_keys; - const handleKeys = formKeysData.handle_keys; + const inputKeys = currentFlowState.input_keys; + const handleKeys = currentFlowState.handle_keys; const keyToUse = Object.keys(inputKeys!).find( (key) => !handleKeys?.some((j) => j === key) && inputKeys![key] === "" @@ -68,7 +67,7 @@ export default function FormModal({ }); const [chatHistory, setChatHistory] = useState([]); - const template = useRef(currentFlowState?.formKeysData.template ?? undefined); + const template = useRef(currentFlowState?.template ?? undefined); const { accessToken } = useContext(AuthContext); const setErrorData = useAlertStore((state) => state.setErrorData); const ws = useRef(null); @@ -77,11 +76,11 @@ export default function FormModal({ const messagesRef = useRef(null); const [chatKey, setChatKey] = useState(() => { - if (currentFlowState?.formKeysData?.input_keys) { - return Object.keys(currentFlowState.formKeysData.input_keys!).find( + if (currentFlowState?.input_keys) { + return Object.keys(currentFlowState.input_keys!).find( (key) => - !currentFlowState.formKeysData.handle_keys!.some((j) => j === key) && - currentFlowState.formKeysData.input_keys![key] === "" + !currentFlowState.handle_keys!.some((j) => j === key) && + currentFlowState.input_keys![key] === "" ); } // TODO: return a sensible default @@ -387,7 +386,7 @@ export default function FormModal({ let nodeValidationErrors = validateNodes(nodes, edges); if (nodeValidationErrors.length === 0) { setLockChat(true); - let inputs = currentFlowState?.formKeysData.input_keys; + let inputs = currentFlowState?.input_keys; setChatValue(""); const message = inputs; addChatHistory(message!, true, chatKey!, template.current); @@ -402,7 +401,7 @@ export default function FormModal({ if (currentFlowState && chatKey) { setCurrentFlowState((old: FlowState | undefined) => { let newFlowState = cloneDeep(old!); - newFlowState.formKeysData.input_keys![chatKey] = ""; + newFlowState.input_keys![chatKey] = ""; return newFlowState; }); } @@ -415,7 +414,7 @@ export default function FormModal({ } function clearChat(): void { setChatHistory([]); - template.current = currentFlowState?.formKeysData.template; + template.current = currentFlowState?.template; ws.current?.send(JSON.stringify({ clear_history: true })); if (lockChat) setLockChat(false); } @@ -423,7 +422,7 @@ export default function FormModal({ function handleOnCheckedChange(checked: boolean, i: string) { if (checked === true) { setChatKey(i); - setChatValue(currentFlowState?.formKeysData.input_keys![i] ?? ""); + setChatValue(currentFlowState?.input_keys![i] ?? ""); } else { setChatKey(null!); setChatValue(""); @@ -432,7 +431,7 @@ export default function FormModal({ return ( - {currentFlowState && currentFlowState.formKeysData && ( + {currentFlowState && currentFlowState && ( @@ -468,8 +467,8 @@ export default function FormModal({ - {currentFlowState?.formKeysData?.input_keys - ? Object.keys(currentFlowState?.formKeysData.input_keys!).map( + {currentFlowState?.input_keys + ? Object.keys(currentFlowState?.input_keys!).map( (key, index) => (
t === key )} /> @@ -502,7 +501,7 @@ export default function FormModal({ keyValue={key} >
- {currentFlowState?.formKeysData.handle_keys!.some( + {currentFlowState?.handle_keys!.some( (t) => t === key ) && (
@@ -512,14 +511,14 @@ export default function FormModal({