diff --git a/src/Pages/question/AddPage.tsx b/src/Pages/question/AddPage.tsx index 0452949..4fb8c70 100644 --- a/src/Pages/question/AddPage.tsx +++ b/src/Pages/question/AddPage.tsx @@ -102,7 +102,9 @@ const AddPage: React.FC = () => { { resetForm }: { resetForm: () => void }, ) => { const DataToSend = structuredClone(values); - + console.log(DataToSend); + + return ; setTagsSearch(null); const canAnswersBeShuffled = DataToSend?.canAnswersBeShuffled ? 1 : 0; if (isBseQuestion || DataToSend?.isBase === 1) { diff --git a/src/Pages/question/Model/Malty/ChoiceField/CheckboxField.tsx b/src/Pages/question/Model/Malty/ChoiceField/CheckboxField.tsx index 12d27aa..529317d 100644 --- a/src/Pages/question/Model/Malty/ChoiceField/CheckboxField.tsx +++ b/src/Pages/question/Model/Malty/ChoiceField/CheckboxField.tsx @@ -16,7 +16,6 @@ const CheckboxField = ({ const formik = useFormikContext(); const [t] = useTranslation(); const CheckboxhandleChange = (value: any) => { - console.log(value?.target?.checked); const allAreZero = formik?.values?.Questions?.[ parent_index diff --git a/src/Pages/question/Model/Malty/ChoiceField/ChoiceFields.tsx b/src/Pages/question/Model/Malty/ChoiceField/ChoiceFields.tsx index 0f88532..13bb225 100644 --- a/src/Pages/question/Model/Malty/ChoiceField/ChoiceFields.tsx +++ b/src/Pages/question/Model/Malty/ChoiceField/ChoiceFields.tsx @@ -9,6 +9,7 @@ import TextField from "./TextField"; import File from "./File"; import { FaTrash } from "react-icons/fa"; import { toast } from "react-toastify"; +import HintField from "./HintField"; const ChoiceFields = ({ index, @@ -45,6 +46,7 @@ const ChoiceFields = ({ ); }; return ( + <>

+
+ +
+ ); }; diff --git a/src/Pages/question/Model/Malty/ChoiceField/Choices.tsx b/src/Pages/question/Model/Malty/ChoiceField/Choices.tsx index 2db0d93..346777b 100644 --- a/src/Pages/question/Model/Malty/ChoiceField/Choices.tsx +++ b/src/Pages/question/Model/Malty/ChoiceField/Choices.tsx @@ -9,18 +9,25 @@ const Choices = ({ parent_index }: { parent_index: number }) => { const handleDragEnd = (result: any) => { // Check if the item was dropped outside the list + console.log(1); + console.log(result.destination); + if (!result.destination) return; + console.log(formik?.values?.Questions?.[parent_index]?.QuestionOptions); + // Create a new array from the current QuestionOptions - const items = Array.from(formik?.values?.QuestionOptions); - + const items = Array.from(formik?.values?.Questions?.[parent_index]?.QuestionOptions); + console.log(items); // Remove the item from the original position const [reorderedItem] = items.splice(result.source.index, 1); - + console.log(items); // Insert the item at the new position items.splice(result.destination.index, 0, reorderedItem); // Update the order keys based on the new indices + console.log(items,"items"); + const updatedItems = items.map((item, index) => ({ ...(item ?? {}), order: index + 1, // Update order to be 1-based index @@ -29,7 +36,7 @@ const Choices = ({ parent_index }: { parent_index: number }) => { // Update the formik state with the new order console.log(updatedItems, "updatedItems"); - formik.setFieldValue("QuestionOptions", updatedItems); + formik.setFieldValue(`Questions.${parent_index}.QuestionOptions`, updatedItems); }; return ( diff --git a/src/Pages/question/Model/Malty/ChoiceField/HintField.tsx b/src/Pages/question/Model/Malty/ChoiceField/HintField.tsx new file mode 100644 index 0000000..dc93761 --- /dev/null +++ b/src/Pages/question/Model/Malty/ChoiceField/HintField.tsx @@ -0,0 +1,54 @@ +import { Form, Input } from "antd"; +import React from "react"; +import useFormField from "../../../../../Hooks/useFormField"; +import { MdOutlineEdit } from "react-icons/md"; +import { Field } from "formik"; + +const HintField = ({ + name, + label, + label2, + placeholder, + isDisabled, + onChange, + props, + parent_index, + id, + className, +}: any) => { + const newName = `Questions[${parent_index}].QuestionOptions[${name}].hint`; + + const { formik, isError, errorMsg, t } = useFormField(newName, props); + const TextFilehandleChange = ( + e: React.ChangeEvent, + ) => { + // console.log('Change:', e.target.value); + formik.setFieldValue(newName, e.target.value); + }; + + return ( +
+ + + + +
+ ); +}; + +export default React.memo(HintField); diff --git a/src/Pages/question/Model/Malty/QuestionFIeld/CheckboxField.tsx b/src/Pages/question/Model/Malty/QuestionFIeld/CheckboxField.tsx index 4d3e571..a85176f 100644 --- a/src/Pages/question/Model/Malty/QuestionFIeld/CheckboxField.tsx +++ b/src/Pages/question/Model/Malty/QuestionFIeld/CheckboxField.tsx @@ -14,7 +14,6 @@ const CheckboxField = ({ const formik = useFormikContext(); const [t] = useTranslation(); const newName = `Questions[${name}].canAnswersBeShuffled`; - console.log(formik.values?.Questions?.[name]); const CheckboxhandleChange = (value: any, index: number) => { formik.setFieldValue(newName, value?.target?.checked ? 1 : 0); diff --git a/src/Pages/question/Model/Malty/QuestionFIeld/HintField.tsx b/src/Pages/question/Model/Malty/QuestionFIeld/HintField.tsx new file mode 100644 index 0000000..4baf9b1 --- /dev/null +++ b/src/Pages/question/Model/Malty/QuestionFIeld/HintField.tsx @@ -0,0 +1,52 @@ +import { Form, Input } from "antd"; +import React from "react"; +import useFormField from "../../../../../Hooks/useFormField"; +import { MdOutlineEdit } from "react-icons/md"; +import { Field } from "formik"; + +const HintField = ({ + name, + label, + label2, + placeholder, + isDisabled, + onChange, + props, + id, + className, +}: any) => { + const newName = `Questions[${name}].hint`; + const { formik, isError, errorMsg, t } = useFormField(newName, props); + const TextFilehandleChange = ( + e: React.ChangeEvent, + ) => { + // console.log('Change:', e.target.value); + formik.setFieldValue(newName, e.target.value); + }; + + return ( +
+ + + + +
+ ); +}; + +export default React.memo(HintField); diff --git a/src/Pages/question/Model/Malty/QuestionFIeld/QuestionFIeld.tsx b/src/Pages/question/Model/Malty/QuestionFIeld/QuestionFIeld.tsx index 9f1568d..ba68cd9 100644 --- a/src/Pages/question/Model/Malty/QuestionFIeld/QuestionFIeld.tsx +++ b/src/Pages/question/Model/Malty/QuestionFIeld/QuestionFIeld.tsx @@ -10,10 +10,10 @@ import { FaTrash } from "react-icons/fa"; import { useObjectToEdit } from "../../../../../zustand/ObjectToEditState"; import { toast } from "react-toastify"; import CheckboxField from "./CheckboxField"; +import HintField from "./HintField"; const QuestionFIeld = ({ index, data }: { index: number; data: Choice }) => { const formik = useFormikContext(); - console.log(index); const { setDeletedQuestions, DeletedQuestions } = useObjectToEdit(); const [t] = useTranslation(); @@ -33,6 +33,7 @@ const QuestionFIeld = ({ index, data }: { index: number; data: Choice }) => { }; return ( +
{ label={"canAnswersBeShuffled"} name={index} /> + +

+ +
+ +
+ +
); }; diff --git a/src/Pages/question/Model/Tags/DynamicTags.tsx b/src/Pages/question/Model/Tags/DynamicTags.tsx index d208b81..687611f 100644 --- a/src/Pages/question/Model/Tags/DynamicTags.tsx +++ b/src/Pages/question/Model/Tags/DynamicTags.tsx @@ -14,7 +14,6 @@ const DynamicTags = () => { name: TagsSearch, }); const suggests = data?.data; - // console.log(TagsSearch); const handleAddChoice = () => { const length = formik?.values?.tags.length; diff --git a/src/Styles/Pages/Classes.scss b/src/Styles/Pages/Classes.scss index 3ba38b9..588e7fd 100644 --- a/src/Styles/Pages/Classes.scss +++ b/src/Styles/Pages/Classes.scss @@ -92,3 +92,10 @@ .ant-upload-wrapper { width: 100%; } + + +.d-c{ + display: flex; + flex-direction: column; + flex: 1; +} \ No newline at end of file diff --git a/src/translate/ar.json b/src/translate/ar.json index b17a7e6..b6673ad 100644 --- a/src/translate/ar.json +++ b/src/translate/ar.json @@ -364,7 +364,7 @@ "question": "السؤال", "id": "الرقم التعريفي", "canAnswersBeShuffled": "يمكن خلط الإجابات", - "hint": "لحليح" + "hint": "تَلمِيح" }, "select": {