From 05d0a12527e124621b1c26cdaa6876f0cd171764 Mon Sep 17 00:00:00 2001 From: karimaldeen Date: Mon, 16 Sep 2024 15:48:33 +0300 Subject: [PATCH] fix tags --- src/Components/CustomFields/SelectTag.tsx | 11 +++++++-- .../Model/Malty/Tags/MaltySelectTag.tsx | 23 ++++++++++++++++--- src/Pages/Admin/subject/Model/EditModel.tsx | 6 +++-- src/Pages/Home/Dummy.tsx | 4 ++-- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/src/Components/CustomFields/SelectTag.tsx b/src/Components/CustomFields/SelectTag.tsx index aa91902..27bfc35 100644 --- a/src/Components/CustomFields/SelectTag.tsx +++ b/src/Components/CustomFields/SelectTag.tsx @@ -54,7 +54,14 @@ const SelectTag: React.FC = () => { formik?.values?.tags?.map((item: any) => item?.id ?? item) ?? []; const AllOptions = [...options, ...additionalData,NewAdditionalData]; - + const uniqueOptions = Array.from( + new Map( + AllOptions + .filter(item => Object.keys(item).length > 0) // Filter out empty objects + .map(item => [item.id, item]) // Create [id, item] pairs to ensure uniqueness + ).values() + ); + return (
@@ -65,7 +72,7 @@ const SelectTag: React.FC = () => { placeholder="" fieldNames={{ label: "name", value: "id" }} onChange={handleChange} - options={AllOptions} + options={uniqueOptions} filterOption={false} loading={isLoading} notFoundContent={isLoading ? : t("practical.not_found")} diff --git a/src/Pages/Admin/question/Model/Malty/Tags/MaltySelectTag.tsx b/src/Pages/Admin/question/Model/Malty/Tags/MaltySelectTag.tsx index e140d88..5e73b65 100644 --- a/src/Pages/Admin/question/Model/Malty/Tags/MaltySelectTag.tsx +++ b/src/Pages/Admin/question/Model/Malty/Tags/MaltySelectTag.tsx @@ -10,7 +10,16 @@ const MaltySelectTag = ({ parent_index }: { parent_index: number }) => { const [fieldValue, setFieldValue] = useState(""); const formik = useFormikContext(); const values = formik?.values?.Questions?.[parent_index]?.tags; - const handleChange = (value: string[]) => { + const [NewAdditionalData, setNewAdditionalData] = useState({}) + + const handleChange = (value: string[],option:any) => { + const newSelectedOption = option?.pop() + const newObject = { + id:newSelectedOption?.id, + name:newSelectedOption?.name + } + setNewAdditionalData(newObject) + formik.setFieldValue(`Questions.[${parent_index}].tags`, value); setSearchValue(""); setFieldValue(""); @@ -46,8 +55,16 @@ const MaltySelectTag = ({ parent_index }: { parent_index: number }) => { (item: any) => item?.id ?? item, ) ?? []; - const AllOptions = [...options, ...additionalData]; + const AllOptions = [...options, ...additionalData,NewAdditionalData]; + const uniqueOptions = Array.from( + new Map( + AllOptions + .filter(item => Object.keys(item).length > 0) // Filter out empty objects + .map(item => [item.id, item]) // Create [id, item] pairs to ensure uniqueness + ).values() + ); + return (
@@ -58,7 +75,7 @@ const MaltySelectTag = ({ parent_index }: { parent_index: number }) => { placeholder="" fieldNames={{ label: "name", value: "id" }} onChange={handleChange} - options={AllOptions} + options={uniqueOptions} filterOption={false} loading={isLoading} notFoundContent={isLoading ? : t("practical.not_found")} diff --git a/src/Pages/Admin/subject/Model/EditModel.tsx b/src/Pages/Admin/subject/Model/EditModel.tsx index 548d2e6..80bf254 100644 --- a/src/Pages/Admin/subject/Model/EditModel.tsx +++ b/src/Pages/Admin/subject/Model/EditModel.tsx @@ -7,14 +7,16 @@ import { handelImageState } from "../../../../utils/DataToSendImageState"; import LayoutModel from "../../../../Layout/Dashboard/LayoutModel"; import { QueryStatusEnum } from "../../../../enums/QueryStatus"; import ModelForm from "./ModelForm"; +import { useParams } from "react-router-dom"; +import { ParamsEnum } from "../../../../enums/params"; const ModalForm: React.FC = () => { const { objectToEdit } = useObjectToEdit((state) => state); const { mutate, status } = useUpdateSubject(); - + const {subject_id} = useParams() const handleSubmit = (values: any) => { - const Data_to_send = { ...values }; + const Data_to_send = { ...values,subject_id }; const handelImage = handelImageState(Data_to_send, "icon"); mutate(handelImage); }; diff --git a/src/Pages/Home/Dummy.tsx b/src/Pages/Home/Dummy.tsx index 34b0596..2b2308f 100644 --- a/src/Pages/Home/Dummy.tsx +++ b/src/Pages/Home/Dummy.tsx @@ -9,14 +9,14 @@ const Dummy = () => { return (
- + {/* karim