import React, { useEffect } from "react"; import { Choice } from "../../../../../../types/Item"; import { useFormikContext } from "formik"; import { useTranslation } from "react-i18next"; import { getCharFromNumber } from "../../../../../../utils/getCharFromNumber"; import TextField from "./TextField"; import { useObjectToEdit } from "../../../../../../zustand/ObjectToEditState"; import ImageBoxField from "../../../../../../Components/CustomFields/ImageBoxField/ImageBoxField"; import { GoTrash } from "react-icons/go"; import { Popconfirm } from "antd"; const QuestionFIeld = ({ index, data }: { index: number; data: Choice }) => { const formik = useFormikContext(); 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); }; const values = formik.values.Questions?.[index] ; const handelCanDeleteAnswers = ()=>{ const content = values?.content ; const content_image = values?.content_image ; if(!content && !content_image ){ return true } return false } return ( <>
{handelCanDeleteAnswers() ?

{handleDeleteQuestion()}}> {t("header.delete_question")}

:
{handleDeleteQuestion()}} defaultOpen={false} >

{t("header.delete_question")}

}
); }; export default QuestionFIeld;