From a3c5480442564df7030dd643b4c7f65e9eeacc5c Mon Sep 17 00:00:00 2001 From: sherifButt <90522472+sherifButt@users.noreply.github.com> Date: Mon, 11 Mar 2024 15:57:19 +0000 Subject: [PATCH] - added checkbox for multy selection --- .../DynamicInput/OptionSelect/index.jsx | 87 ++++++++++++++++--- .../ChatContainer/DynamicInput/index.jsx | 63 +++++++------- 2 files changed, 108 insertions(+), 42 deletions(-) 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 ( -
+