This commit is contained in:
karimaldeen 2024-08-17 11:47:16 +03:00
parent a0000066ab
commit 2915d85fcf
5 changed files with 137 additions and 1 deletions

View File

@ -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 (
<>
<div className="ChoiceFields">
<TextField
className="textarea_exercise"
@ -73,6 +75,18 @@ const ChoiceFields = ({
<FaTrash onClick={handleDeleteChoice} size={17} />
</p>
</div>
<div>
<HintField
className=""
label="hint"
placeholder="hint"
name={index}
parent_index={parent_index}
/>
</div>
</>
);
};

View 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);

View 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);

View File

@ -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<any>();
console.log(index);
const { setDeletedQuestions, DeletedQuestions } = useObjectToEdit();
const [t] = useTranslation();
@ -33,6 +33,7 @@ const QuestionFIeld = ({ index, data }: { index: number; data: Choice }) => {
};
return (
<div className="d-c">
<div className="ChoiceFields">
<TextField
className="textarea_exercise"
@ -53,10 +54,18 @@ const QuestionFIeld = ({ index, data }: { index: number; data: Choice }) => {
name={index}
/>
<p className="delete_question_options">
<FaTrash onClick={handleDeleteQuestion} size={17} />
</p>
</div>
<div>
<HintField placeholder={"hint"} name={index} label="hint" id={`hint`} />
</div>
</div>
);
};

View File

@ -92,3 +92,10 @@
.ant-upload-wrapper {
width: 100%;
}
.d-c{
display: flex;
flex-direction: column;
flex: 1;
}