import React 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 CheckboxField from "./CheckboxField"; import TextField from "./TextField"; import { toast } from "react-toastify"; import ImageBoxField from "../../../../../../Components/CustomFields/ImageBoxField/ImageBoxField"; import { GoTrash } from "react-icons/go"; import { Popconfirm } from "antd"; import { useObjectToEdit } from "../../../../../../zustand/ObjectToEditState"; const ChoiceFields = ({ index, parent_index, data, }: { index: number; parent_index: number; data: Choice; }) => { const formik = useFormikContext(); const [t] = useTranslation(); const { ShowHint } = useObjectToEdit(); const handleDeleteChoice = () => { document.getElementById(`ChoiceField_${parent_index}_${index}`)?.classList.add("exit") const updatedAnswers = formik.values.Questions?.[ parent_index ].answers.filter((_: any, i: any) => i !== index); setTimeout(() => { formik.setFieldValue(`Questions[${parent_index}].answers`, updatedAnswers); document.getElementById(`ChoiceField_${parent_index}_${index}`)?.classList.remove("exit") }, 500); }; const values = formik.values.Questions?.[parent_index]?.answers?.[index] ; const handelCanDeleteAnswers = ()=>{ const content = values?.content ; const content_image = values?.content_image ; if(!content && !content_image ){ return true } return false } return ( <>
{handelCanDeleteAnswers() ?

{handleDeleteChoice()}} > {t("header.delete_choice")}

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

{t("header.delete_choice")}

}
{ShowHint && }
); }; export default ChoiceFields;