Quiz_dashboard/src/Pages/Admin/question/Model/Malty/QuestionFIeld/QuestionFIeld.tsx
2024-09-14 11:59:18 +03:00

73 lines
2.4 KiB
TypeScript

import React, { useEffect } from "react";
import { Choice } from "../../../../../../types/Item";
import ValidationField from "../../../../../../Components/ValidationField/ValidationField";
import { useFormikContext } from "formik";
import { useTranslation } from "react-i18next";
import { getCharFromNumber } from "../../../../../../utils/getCharFromNumber";
import TextField from "./TextField";
import File from "./File";
import { FaTrash } from "react-icons/fa";
import { useObjectToEdit } from "../../../../../../zustand/ObjectToEditState";
import { toast } from "react-toastify";
import CheckboxField from "./CheckboxField";
import HintField from "./HintField";
import ImageBoxField from "../../../../../../Components/CustomFields/ImageBoxField/ImageBoxField";
import { GoTrash } from "react-icons/go";
const QuestionFIeld = ({ index, data }: { index: number; data: Choice }) => {
const formik = useFormikContext<any>();
const { setDeletedQuestions, DeletedQuestions } = useObjectToEdit();
const [t] = useTranslation();
useEffect(() => {
setDeletedQuestions([]);
}, [window?.location.pathname]);
const handleDeleteQuestion = () => {
const DeleteQuestionId = formik.values.Questions?.[index];
if (DeleteQuestionId?.id) {
setDeletedQuestions([...DeletedQuestions, DeleteQuestionId]);
}
const updatedAnswers = formik.values.Questions.filter(
(_: any, i: any) => i !== index,
);
formik.setFieldValue(`Questions`, updatedAnswers);
};
return (
<>
<div className="exercise_forms">
<div className="ChoiceFields">
<TextField
className="textarea_exercise"
placeholder={"question"}
label2={
t(`input.question`) +
` ` +
`( ${t(`alphabet.${getCharFromNumber(index)}`)} )`
}
name={index}
id={`question_${index + 1}`}
type="TextArea"
/>
<ImageBoxField name={`Questions.${index}.content_image`} />
<div className="answer_status" onClick={handleDeleteQuestion}>
<p className="delete_question_options">
{t("header.delete_question")}
<GoTrash
className="trash_icon"
size={17}
/>
</p>
</div>
</div>
</div>
</>
);
};
export default QuestionFIeld;