diff --git a/frontend/src/components/WorkspaceChat/ChatContainer/DynamicInput/OptionSelect/index.jsx b/frontend/src/components/WorkspaceChat/ChatContainer/DynamicInput/OptionSelect/index.jsx index a2b69654..ce60d9a4 100644 --- a/frontend/src/components/WorkspaceChat/ChatContainer/DynamicInput/OptionSelect/index.jsx +++ b/frontend/src/components/WorkspaceChat/ChatContainer/DynamicInput/OptionSelect/index.jsx @@ -1,7 +1,10 @@ +import { PaperPlaneRight } from "@phosphor-icons/react"; import { useEffect, useState } from "react"; const OptionSelect = ({ data, settings, submit, message, setMessage }) => { + const [selectedOptions, setSelectedOptions] = useState([]); const [submitMessage, setSubmitMessage] = useState(false); + useEffect(() => { if (submitMessage) { submit(); @@ -10,7 +13,20 @@ const OptionSelect = ({ data, settings, submit, message, setMessage }) => { }, [message]); const handleSelection = (value) => { - setMessage(value); + const currentIndex = selectedOptions.indexOf(value); + const newSelectedOptions = [...selectedOptions]; + + if (currentIndex === -1) { + newSelectedOptions.push(value); + } else { + newSelectedOptions.splice(currentIndex, 1); + } + + setSelectedOptions(newSelectedOptions); + setMessage(newSelectedOptions.join(", ")); + }; + + const handleSubmit = () => { setSubmitMessage(true); }; @@ -24,14 +40,19 @@ const OptionSelect = ({ data, settings, submit, message, setMessage }) => { @@ -51,10 +72,16 @@ const OptionSelect = ({ data, settings, submit, message, setMessage }) => { key={index} href={option.href} // assuming `href` is available in your option object className="block p-2.5 border-b border-white/10 last:border-0 hover:bg-sidebar/50 cursor-pointer" - onClick={() => handleSelection(option.value)} + onClick={() => { + { + handleSelection(option.value); + handleSubmit(); + } + }} >

- {index + 1}. {option.label} + {index + 1}.{" "} + {option.label}

))} @@ -62,9 +89,45 @@ const OptionSelect = ({ data, settings, submit, message, setMessage }) => { ); } + // Checkbox + if (settings.displayType === "checkbox") { + return ( +
+
+ ); + } + // Dropdown Menu return ( -
+