diff --git a/src/Components/CustomFields/ImageBoxField/ImageBoxField.tsx b/src/Components/CustomFields/ImageBoxField/ImageBoxField.tsx index 89888fc..6287c81 100644 --- a/src/Components/CustomFields/ImageBoxField/ImageBoxField.tsx +++ b/src/Components/CustomFields/ImageBoxField/ImageBoxField.tsx @@ -38,12 +38,10 @@ const ImageBoxField = ({ name }: any) => { } // Process the file - console.log('File selected:', file); } if (file) { generateImagePreview(file, setImagePreview); - console.log(file,"file"); formik.setFieldValue(name, file); } diff --git a/src/Components/Layout/SideBar/MenuItem.tsx b/src/Components/Layout/SideBar/MenuItem.tsx index bdcd0a7..637c394 100644 --- a/src/Components/Layout/SideBar/MenuItem.tsx +++ b/src/Components/Layout/SideBar/MenuItem.tsx @@ -37,14 +37,14 @@ export const MenuItem = ({ item, location, index, isOpen }: any) => { className="DropDownIcon" onClick={() => handleDropdown(index)} > - + ) : (
handleDropdown(index)} > - +
)} diff --git a/src/Layout/Dashboard/LayoutModel.tsx b/src/Layout/Dashboard/LayoutModel.tsx index a6c0584..249ac3d 100644 --- a/src/Layout/Dashboard/LayoutModel.tsx +++ b/src/Layout/Dashboard/LayoutModel.tsx @@ -7,6 +7,7 @@ import { useTranslation } from "react-i18next"; import { QueryStatusEnum } from "../../enums/QueryStatus"; import SpinContainer from "../../Components/Layout/SpinContainer"; import { MdCancel } from "react-icons/md"; +import { Form, Formik } from "formik"; interface LayoutModalProps { isAddModal?: boolean; @@ -65,12 +66,29 @@ const LayoutModel = ({ open={isOpen === ModelEnum} onCancel={handleCancel} > - -
+ + + {(formik) => { + useEffect(() => { + if (isOpen === "" || isOpen === "isSuccess") { + formik.setErrors({}); + formik.resetForm(); + } + }, [isOpen]); + + console.log(formik.initialValues); + console.log(formik?.values); + + + return
+ +
{t(`practical.${isAddModal ? "add" : "edit"}`)}{" "} {t(`models.${modelTitle}`)}{" "} @@ -88,7 +106,7 @@ const LayoutModel = ({ - + + ; + }} + ); diff --git a/src/Pages/Admin/question/AddPage.tsx b/src/Pages/Admin/question/AddPage.tsx index ea94e47..78a951a 100644 --- a/src/Pages/Admin/question/AddPage.tsx +++ b/src/Pages/Admin/question/AddPage.tsx @@ -1,4 +1,4 @@ -import React, { Suspense, lazy, useEffect } from "react"; +import React, { useEffect } from "react"; import { Spin } from "antd"; import { getInitialValues, @@ -20,13 +20,14 @@ import ModelForm from "./Model/ModelForm"; import { toast } from "react-toastify"; import { Form, Formik } from "formik"; import { MdOutlineArrowForwardIos } from "react-icons/md"; +import { getCharFromNumber } from "../../../utils/getCharFromNumber"; const AddPage: React.FC = () => { const location = useLocation(); const { mutateAsync,isLoading:LoadingAsync } = useAddQuestionAsync(); const { mutate, isLoading, isSuccess } = useAddQuestion(); - const { isBseQuestion, setTagsSearch, setSuccess } = + const { isBseQuestion, setTagsSearch, setSuccess , ShowHint,setShowHint } = useObjectToEdit(); const [t] = useTranslation(); @@ -99,12 +100,19 @@ const AddPage: React.FC = () => { mutate(NewQuestion); } }; - - const handleValidateSingleQuestion = (values:any)=>{ const haveMoreThanOneAnswer = values?.answers?.length > 1; const haveOneAnswerRight = haveMoreThanOneAnswer && values?.answers?.some((item:any)=> item?.isCorrect === 1 || item.isCorrect === true ) const haveImageOrContent = haveOneAnswerRight && values?.answers?.some((item:any)=> !(item?.content) && !(item.content_image) ) + const content = values.content ; + const content_image = values.content_image ; + const haveContentOrContentImage = !!content || !!content_image ; + + console.log(haveImageOrContent,"haveImageOrContent"); + if(!haveContentOrContentImage){ + toast.error(`${t("validation.one_of_image_and_content_should_be_enter_in_question")}`); + return false; + } if(!haveMoreThanOneAnswer){ toast.error(t("validation.it_should_have_more_than_one_answers")) ; @@ -115,21 +123,43 @@ const AddPage: React.FC = () => { return false ; } if(haveImageOrContent){ - toast.error(t("validation.one_of_image_and_content_should_be_enter")) + toast.error(t("validation.one_of_image_and_content_should_be_enter_in_answer_in_answer")) return false } } - const handleValidateBaseQuestion = (values: any) => { - const haveAnswers = values?.Questions?.every((Question: any, QuestionsIndex: number) => { + const content = values.content ; + const content_image = values.content_image ; + const haveContentOrContentImage = !!content || !!content_image ; + + if(!haveContentOrContentImage){ + toast.error(`${t("validation.one_of_image_and_content_should_be_enter_in_question")}`); + return false; + } + + values?.Questions?.every((Question: any, QuestionsIndex: number) => { + + + const content = Question.content ; + const content_image = Question.content_image ; + const haveContentOrContentImage = !!content || !!content_image ; + if(!haveContentOrContentImage){ + toast.error(`${t("validation.one_of_image_and_content_should_be_enter_in_question")}`); + return false; + } + + + //// answers const answers = Question?.answers; - const haveAnswers = answers?.length > 0; + const haveAnswers = answers?.length > 0; const haveMoreThanOneAnswer = haveAnswers && answers?.length > 1; const haveOneAnswerRight = haveMoreThanOneAnswer && answers?.some((item: any) => item?.isCorrect === 1 || item.isCorrect === true); const haveImageOrContent = haveOneAnswerRight && answers?.some((item:any)=> !(item?.content) && !(item.content_image) ) - console.log(haveImageOrContent,"haveImageOrContent"); + + + if (!haveAnswers) { toast.error(t("validation.it_should_have_more_than_one_answers")); return false; @@ -146,14 +176,14 @@ const AddPage: React.FC = () => { } if(haveImageOrContent){ - toast.error(t("validation.one_of_image_and_content_should_be_enter")) + toast.error(t("validation.one_of_image_and_content_should_be_enter_in_answer")) return false } return true; }); - - console.log(haveAnswers, "haveAnswers"); + + }; const navigate = useNavigate(); diff --git a/src/Pages/Admin/question/EditPage.tsx b/src/Pages/Admin/question/EditPage.tsx index 10ecad9..af248df 100644 --- a/src/Pages/Admin/question/EditPage.tsx +++ b/src/Pages/Admin/question/EditPage.tsx @@ -1,5 +1,5 @@ import React, { useEffect } from "react"; -import { Modal, Spin } from "antd"; +import { Checkbox, Modal, Popover, Spin } from "antd"; import { getInitialValues, getValidationSchema, @@ -26,10 +26,12 @@ import { toast } from "react-toastify"; import { deletePathSegments } from "../../../utils/deletePathSegments"; import { Form, Formik } from "formik"; import { MdOutlineArrowForwardIos } from "react-icons/md"; +import { SettingFilled } from "@ant-design/icons"; +import { CheckboxProps } from "antd/lib"; const EditPage: React.FC = () => { const { subject_id, lesson_id, question_id } = useParams(); - const { isBseQuestion, setIsBseQuestion, setTagsSearch, DeletedQuestions } = + const { isBseQuestion, setIsBseQuestion, setTagsSearch, DeletedQuestions , ShowHint,setShowHint } = useObjectToEdit(); const { mutate, isSuccess, isLoading } = useUpdateQuestion(); @@ -60,6 +62,7 @@ const EditPage: React.FC = () => { setTagsSearch(null); if (isBseQuestion) { + const UpdateBseQuestion = { id: DataToSend?.id, content: DataToSend?.content, @@ -74,7 +77,7 @@ const EditPage: React.FC = () => { console.log(DeletedQuestions, "DeletedQuestions"); console.log(UpdateBseQuestion); - mutate(UpdateBseQuestion); + // mutate(UpdateBseQuestion); DeletedQuestions?.map((item: any) => { DeleteQuestion({ id: item?.id }); @@ -97,8 +100,16 @@ const EditPage: React.FC = () => { const oldAnswers = [] as any; const newAnswers = [] as any; + if(updatedObject?.content_image === null){ + updatedObject["content_image"] = "" + } + updatedObject?.answers?.forEach((item: any) => { if (item?.id) { + if(item?.content_image === null){ + item["content_image"] = "" + + } oldAnswers.push({ ...item, isCorrect: item?.isCorrect ? 1 : 0 }); } else { newAnswers.push({ ...item, isCorrect: item?.isCorrect ? 1 : 0 }); @@ -108,11 +119,12 @@ const EditPage: React.FC = () => { old: oldAnswers, new: newAnswers, }; - console.log(answers); + const emptyTag = tags?.new?.length === 0 && tags?.old?.length === 0 + const tagToSend = emptyTag ? "" : tags mutate({ ...updatedObject, answers, - tags, + tags:tagToSend, }); } else { console.log(values?.id); @@ -182,7 +194,15 @@ const EditPage: React.FC = () => { const haveMoreThanOneAnswer = values?.answers?.length > 1; const haveOneAnswerRight = haveMoreThanOneAnswer && values?.answers?.some((item:any)=> item?.isCorrect === 1 || item.isCorrect === true ) const haveImageOrContent = haveOneAnswerRight && values?.answers?.some((item:any)=> !(item?.content) && !(item.content_image) ) + const content = values.content ; + const content_image = values.content_image ; + const haveContentOrContentImage = !!content || !!content_image ; + console.log(haveImageOrContent,"haveImageOrContent"); + if(!haveContentOrContentImage){ + toast.error(`${t("validation.one_of_image_and_content_should_be_enter_in_question")}`); + return false; + } if(!haveMoreThanOneAnswer){ toast.error(t("validation.it_should_have_more_than_one_answers")) ; return false ; @@ -192,7 +212,7 @@ const EditPage: React.FC = () => { return false ; } if(haveImageOrContent){ - toast.error(t("validation.one_of_image_and_content_should_be_enter")) + toast.error(t("validation.one_of_image_and_content_should_be_enter_in_answer")) return false } @@ -200,6 +220,18 @@ const EditPage: React.FC = () => { const handleValidateBaseQuestion = (values: any) => { const haveAnswers = values?.Questions?.every((Question: any, QuestionsIndex: number) => { + + + const content = Question.content ; + const content_image = Question.content_image ; + const haveContentOrContentImage = !!content || !!content_image ; + if(!haveContentOrContentImage){ + toast.error(`${t("validation.one_of_image_and_content_should_be_enter_in_question")}`); + return false; + } + + + //// answers const answers = Question?.answers; const haveAnswers = answers?.length > 0; const haveMoreThanOneAnswer = haveAnswers && answers?.length > 1; @@ -223,7 +255,7 @@ const handleValidateBaseQuestion = (values: any) => { } if(haveImageOrContent){ - toast.error(t("validation.one_of_image_and_content_should_be_enter")) + toast.error(t("validation.one_of_image_and_content_should_be_enter_in_answer")) return false } @@ -247,6 +279,22 @@ const handleNavigateToPage = () => { } }, [isSuccess]); + const onChange: CheckboxProps['onChange'] = (e) => { + setShowHint(e.target.checked); + }; + + const contentSetting = ( +
+ + + { t("header.show_hint")} + + +
+ ); + + + const Loading = LoadingAsync || isLoading if (dataLoading || QuestionsDataLoading) { @@ -277,7 +325,13 @@ const handleNavigateToPage = () => {
{t("practical.edit")} {t("models.exercise")}{" "}
+
+ + + +
{t("header.exercise")}
+
@@ -321,7 +375,7 @@ const handleNavigateToPage = () => { handleSubmit(values); }} > - {({ values,handleSubmit }) => ( + {({ values,handleSubmit , dirty }) => (
{/*
*/} @@ -335,13 +389,13 @@ const handleNavigateToPage = () => {
{t("practical.back")}