Merge branch 'main' of https://git.point-dev.net/Karimaldeen/nerd_project_dashboard
This commit is contained in:
commit
687640f7a4
|
|
@ -102,7 +102,9 @@ const AddPage: React.FC = () => {
|
||||||
{ resetForm }: { resetForm: () => void },
|
{ resetForm }: { resetForm: () => void },
|
||||||
) => {
|
) => {
|
||||||
const DataToSend = structuredClone(values);
|
const DataToSend = structuredClone(values);
|
||||||
|
console.log(DataToSend);
|
||||||
|
|
||||||
|
return ;
|
||||||
setTagsSearch(null);
|
setTagsSearch(null);
|
||||||
const canAnswersBeShuffled = DataToSend?.canAnswersBeShuffled ? 1 : 0;
|
const canAnswersBeShuffled = DataToSend?.canAnswersBeShuffled ? 1 : 0;
|
||||||
if (isBseQuestion || DataToSend?.isBase === 1) {
|
if (isBseQuestion || DataToSend?.isBase === 1) {
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ const CheckboxField = ({
|
||||||
const formik = useFormikContext<any>();
|
const formik = useFormikContext<any>();
|
||||||
const [t] = useTranslation();
|
const [t] = useTranslation();
|
||||||
const CheckboxhandleChange = (value: any) => {
|
const CheckboxhandleChange = (value: any) => {
|
||||||
console.log(value?.target?.checked);
|
|
||||||
|
|
||||||
const allAreZero = formik?.values?.Questions?.[
|
const allAreZero = formik?.values?.Questions?.[
|
||||||
parent_index
|
parent_index
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import TextField from "./TextField";
|
||||||
import File from "./File";
|
import File from "./File";
|
||||||
import { FaTrash } from "react-icons/fa";
|
import { FaTrash } from "react-icons/fa";
|
||||||
import { toast } from "react-toastify";
|
import { toast } from "react-toastify";
|
||||||
|
import HintField from "./HintField";
|
||||||
|
|
||||||
const ChoiceFields = ({
|
const ChoiceFields = ({
|
||||||
index,
|
index,
|
||||||
|
|
@ -45,6 +46,7 @@ const ChoiceFields = ({
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
|
<>
|
||||||
<div className="ChoiceFields">
|
<div className="ChoiceFields">
|
||||||
<TextField
|
<TextField
|
||||||
className="textarea_exercise"
|
className="textarea_exercise"
|
||||||
|
|
@ -73,6 +75,18 @@ const ChoiceFields = ({
|
||||||
<FaTrash onClick={handleDeleteChoice} size={17} />
|
<FaTrash onClick={handleDeleteChoice} size={17} />
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<HintField
|
||||||
|
className=""
|
||||||
|
label="hint"
|
||||||
|
placeholder="hint"
|
||||||
|
name={index}
|
||||||
|
|
||||||
|
parent_index={parent_index}
|
||||||
|
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,18 +9,25 @@ const Choices = ({ parent_index }: { parent_index: number }) => {
|
||||||
|
|
||||||
const handleDragEnd = (result: any) => {
|
const handleDragEnd = (result: any) => {
|
||||||
// Check if the item was dropped outside the list
|
// Check if the item was dropped outside the list
|
||||||
|
console.log(1);
|
||||||
|
console.log(result.destination);
|
||||||
|
|
||||||
if (!result.destination) return;
|
if (!result.destination) return;
|
||||||
|
|
||||||
|
console.log(formik?.values?.Questions?.[parent_index]?.QuestionOptions);
|
||||||
|
|
||||||
// Create a new array from the current 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
|
// Remove the item from the original position
|
||||||
const [reorderedItem] = items.splice(result.source.index, 1);
|
const [reorderedItem] = items.splice(result.source.index, 1);
|
||||||
|
console.log(items);
|
||||||
// Insert the item at the new position
|
// Insert the item at the new position
|
||||||
items.splice(result.destination.index, 0, reorderedItem);
|
items.splice(result.destination.index, 0, reorderedItem);
|
||||||
|
|
||||||
// Update the order keys based on the new indices
|
// Update the order keys based on the new indices
|
||||||
|
console.log(items,"items");
|
||||||
|
|
||||||
const updatedItems = items.map((item, index) => ({
|
const updatedItems = items.map((item, index) => ({
|
||||||
...(item ?? {}),
|
...(item ?? {}),
|
||||||
order: index + 1, // Update order to be 1-based index
|
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
|
// Update the formik state with the new order
|
||||||
console.log(updatedItems, "updatedItems");
|
console.log(updatedItems, "updatedItems");
|
||||||
|
|
||||||
formik.setFieldValue("QuestionOptions", updatedItems);
|
formik.setFieldValue(`Questions.${parent_index}.QuestionOptions`, updatedItems);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
54
src/Pages/question/Model/Malty/ChoiceField/HintField.tsx
Normal file
54
src/Pages/question/Model/Malty/ChoiceField/HintField.tsx
Normal file
|
|
@ -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<HTMLInputElement | HTMLTextAreaElement>,
|
||||||
|
) => {
|
||||||
|
// console.log('Change:', e.target.value);
|
||||||
|
formik.setFieldValue(newName, e.target.value);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={`ValidationField w-100 ${className ?? ""} `}>
|
||||||
|
<label htmlFor={name} className="text">
|
||||||
|
{label2 ? label2 : t(`input.${label ? label : name}`)}
|
||||||
|
</label>
|
||||||
|
<Form.Item
|
||||||
|
hasFeedback
|
||||||
|
validateStatus={isError ? "error" : ""}
|
||||||
|
help={isError ? errorMsg : ""}
|
||||||
|
>
|
||||||
|
<Field
|
||||||
|
as={Input}
|
||||||
|
placeholder={t(`input.${placeholder ? placeholder : name}`)}
|
||||||
|
name={newName}
|
||||||
|
disabled={isDisabled}
|
||||||
|
size="large"
|
||||||
|
onChange={onChange || TextFilehandleChange}
|
||||||
|
style={{ width: 200 }}
|
||||||
|
id={id}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default React.memo(HintField);
|
||||||
|
|
@ -14,7 +14,6 @@ const CheckboxField = ({
|
||||||
const formik = useFormikContext<any>();
|
const formik = useFormikContext<any>();
|
||||||
const [t] = useTranslation();
|
const [t] = useTranslation();
|
||||||
const newName = `Questions[${name}].canAnswersBeShuffled`;
|
const newName = `Questions[${name}].canAnswersBeShuffled`;
|
||||||
console.log(formik.values?.Questions?.[name]);
|
|
||||||
|
|
||||||
const CheckboxhandleChange = (value: any, index: number) => {
|
const CheckboxhandleChange = (value: any, index: number) => {
|
||||||
formik.setFieldValue(newName, value?.target?.checked ? 1 : 0);
|
formik.setFieldValue(newName, value?.target?.checked ? 1 : 0);
|
||||||
|
|
|
||||||
52
src/Pages/question/Model/Malty/QuestionFIeld/HintField.tsx
Normal file
52
src/Pages/question/Model/Malty/QuestionFIeld/HintField.tsx
Normal file
|
|
@ -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<HTMLInputElement | HTMLTextAreaElement>,
|
||||||
|
) => {
|
||||||
|
// console.log('Change:', e.target.value);
|
||||||
|
formik.setFieldValue(newName, e.target.value);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={`ValidationField w-100 ${className ?? ""} `}>
|
||||||
|
<label htmlFor={name} className="text">
|
||||||
|
{label2 ? label2 : t(`input.${label ? label : name}`)}
|
||||||
|
</label>
|
||||||
|
<Form.Item
|
||||||
|
hasFeedback
|
||||||
|
validateStatus={isError ? "error" : ""}
|
||||||
|
help={isError ? errorMsg : ""}
|
||||||
|
>
|
||||||
|
<Field
|
||||||
|
as={Input}
|
||||||
|
placeholder={t(`input.${placeholder ? placeholder : name}`)}
|
||||||
|
name={newName}
|
||||||
|
disabled={isDisabled}
|
||||||
|
size="large"
|
||||||
|
onChange={onChange || TextFilehandleChange}
|
||||||
|
style={{ width: 200 }}
|
||||||
|
id={id}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default React.memo(HintField);
|
||||||
|
|
@ -10,10 +10,10 @@ import { FaTrash } from "react-icons/fa";
|
||||||
import { useObjectToEdit } from "../../../../../zustand/ObjectToEditState";
|
import { useObjectToEdit } from "../../../../../zustand/ObjectToEditState";
|
||||||
import { toast } from "react-toastify";
|
import { toast } from "react-toastify";
|
||||||
import CheckboxField from "./CheckboxField";
|
import CheckboxField from "./CheckboxField";
|
||||||
|
import HintField from "./HintField";
|
||||||
|
|
||||||
const QuestionFIeld = ({ index, data }: { index: number; data: Choice }) => {
|
const QuestionFIeld = ({ index, data }: { index: number; data: Choice }) => {
|
||||||
const formik = useFormikContext<any>();
|
const formik = useFormikContext<any>();
|
||||||
console.log(index);
|
|
||||||
const { setDeletedQuestions, DeletedQuestions } = useObjectToEdit();
|
const { setDeletedQuestions, DeletedQuestions } = useObjectToEdit();
|
||||||
|
|
||||||
const [t] = useTranslation();
|
const [t] = useTranslation();
|
||||||
|
|
@ -33,6 +33,7 @@ const QuestionFIeld = ({ index, data }: { index: number; data: Choice }) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<div className="d-c">
|
||||||
<div className="ChoiceFields">
|
<div className="ChoiceFields">
|
||||||
<TextField
|
<TextField
|
||||||
className="textarea_exercise"
|
className="textarea_exercise"
|
||||||
|
|
@ -52,11 +53,19 @@ const QuestionFIeld = ({ index, data }: { index: number; data: Choice }) => {
|
||||||
label={"canAnswersBeShuffled"}
|
label={"canAnswersBeShuffled"}
|
||||||
name={index}
|
name={index}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<p className="delete_question_options">
|
<p className="delete_question_options">
|
||||||
<FaTrash onClick={handleDeleteQuestion} size={17} />
|
<FaTrash onClick={handleDeleteQuestion} size={17} />
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<HintField placeholder={"hint"} name={index} label="hint" id={`hint`} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ const DynamicTags = () => {
|
||||||
name: TagsSearch,
|
name: TagsSearch,
|
||||||
});
|
});
|
||||||
const suggests = data?.data;
|
const suggests = data?.data;
|
||||||
// console.log(TagsSearch);
|
|
||||||
|
|
||||||
const handleAddChoice = () => {
|
const handleAddChoice = () => {
|
||||||
const length = formik?.values?.tags.length;
|
const length = formik?.values?.tags.length;
|
||||||
|
|
|
||||||
|
|
@ -92,3 +92,10 @@
|
||||||
.ant-upload-wrapper {
|
.ant-upload-wrapper {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.d-c{
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
@ -364,7 +364,7 @@
|
||||||
"question": "السؤال",
|
"question": "السؤال",
|
||||||
"id": "الرقم التعريفي",
|
"id": "الرقم التعريفي",
|
||||||
"canAnswersBeShuffled": "يمكن خلط الإجابات",
|
"canAnswersBeShuffled": "يمكن خلط الإجابات",
|
||||||
"hint": "لحليح"
|
"hint": "تَلمِيح"
|
||||||
},
|
},
|
||||||
|
|
||||||
"select": {
|
"select": {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user