make question one_of_image_and_content_should_be_enter_in_question
This commit is contained in:
parent
b87a96e358
commit
16f6507f00
|
|
@ -38,12 +38,10 @@ const ImageBoxField = ({ name }: any) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process the file
|
// Process the file
|
||||||
console.log('File selected:', file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file) {
|
if (file) {
|
||||||
generateImagePreview(file, setImagePreview);
|
generateImagePreview(file, setImagePreview);
|
||||||
console.log(file,"file");
|
|
||||||
|
|
||||||
formik.setFieldValue(name, file);
|
formik.setFieldValue(name, file);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import React, { Suspense, lazy, useEffect } from "react";
|
import React, { useEffect } from "react";
|
||||||
import { Spin } from "antd";
|
import { Spin } from "antd";
|
||||||
import {
|
import {
|
||||||
getInitialValues,
|
getInitialValues,
|
||||||
|
|
@ -20,6 +20,7 @@ import ModelForm from "./Model/ModelForm";
|
||||||
import { toast } from "react-toastify";
|
import { toast } from "react-toastify";
|
||||||
import { Form, Formik } from "formik";
|
import { Form, Formik } from "formik";
|
||||||
import { MdOutlineArrowForwardIos } from "react-icons/md";
|
import { MdOutlineArrowForwardIos } from "react-icons/md";
|
||||||
|
import { getCharFromNumber } from "../../../utils/getCharFromNumber";
|
||||||
|
|
||||||
const AddPage: React.FC = () => {
|
const AddPage: React.FC = () => {
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
|
@ -99,12 +100,19 @@ const AddPage: React.FC = () => {
|
||||||
mutate(NewQuestion);
|
mutate(NewQuestion);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const handleValidateSingleQuestion = (values:any)=>{
|
const handleValidateSingleQuestion = (values:any)=>{
|
||||||
const haveMoreThanOneAnswer = values?.answers?.length > 1;
|
const haveMoreThanOneAnswer = values?.answers?.length > 1;
|
||||||
const haveOneAnswerRight = haveMoreThanOneAnswer && values?.answers?.some((item:any)=> item?.isCorrect === 1 || item.isCorrect === true )
|
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 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){
|
if(!haveMoreThanOneAnswer){
|
||||||
toast.error(t("validation.it_should_have_more_than_one_answers")) ;
|
toast.error(t("validation.it_should_have_more_than_one_answers")) ;
|
||||||
|
|
@ -115,21 +123,43 @@ const AddPage: React.FC = () => {
|
||||||
return false ;
|
return false ;
|
||||||
}
|
}
|
||||||
if(haveImageOrContent){
|
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
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleValidateBaseQuestion = (values: any) => {
|
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 answers = Question?.answers;
|
||||||
const haveAnswers = answers?.length > 0;
|
const haveAnswers = answers?.length > 0;
|
||||||
const haveMoreThanOneAnswer = haveAnswers && answers?.length > 1;
|
const haveMoreThanOneAnswer = haveAnswers && answers?.length > 1;
|
||||||
const haveOneAnswerRight = haveMoreThanOneAnswer && answers?.some((item: any) => item?.isCorrect === 1 || item.isCorrect === true);
|
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) )
|
const haveImageOrContent = haveOneAnswerRight && answers?.some((item:any)=> !(item?.content) && !(item.content_image) )
|
||||||
console.log(haveImageOrContent,"haveImageOrContent");
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (!haveAnswers) {
|
if (!haveAnswers) {
|
||||||
toast.error(t("validation.it_should_have_more_than_one_answers"));
|
toast.error(t("validation.it_should_have_more_than_one_answers"));
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -146,14 +176,14 @@ const AddPage: React.FC = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(haveImageOrContent){
|
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 false
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(haveAnswers, "haveAnswers");
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
|
||||||
|
|
@ -194,7 +194,15 @@ const EditPage: React.FC = () => {
|
||||||
const haveMoreThanOneAnswer = values?.answers?.length > 1;
|
const haveMoreThanOneAnswer = values?.answers?.length > 1;
|
||||||
const haveOneAnswerRight = haveMoreThanOneAnswer && values?.answers?.some((item:any)=> item?.isCorrect === 1 || item.isCorrect === true )
|
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 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){
|
if(!haveMoreThanOneAnswer){
|
||||||
toast.error(t("validation.it_should_have_more_than_one_answers")) ;
|
toast.error(t("validation.it_should_have_more_than_one_answers")) ;
|
||||||
return false ;
|
return false ;
|
||||||
|
|
@ -204,7 +212,7 @@ const EditPage: React.FC = () => {
|
||||||
return false ;
|
return false ;
|
||||||
}
|
}
|
||||||
if(haveImageOrContent){
|
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 false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -212,6 +220,18 @@ const EditPage: React.FC = () => {
|
||||||
|
|
||||||
const handleValidateBaseQuestion = (values: any) => {
|
const handleValidateBaseQuestion = (values: any) => {
|
||||||
const haveAnswers = values?.Questions?.every((Question: any, QuestionsIndex: number) => {
|
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 answers = Question?.answers;
|
||||||
const haveAnswers = answers?.length > 0;
|
const haveAnswers = answers?.length > 0;
|
||||||
const haveMoreThanOneAnswer = haveAnswers && answers?.length > 1;
|
const haveMoreThanOneAnswer = haveAnswers && answers?.length > 1;
|
||||||
|
|
@ -235,7 +255,7 @@ const handleValidateBaseQuestion = (values: any) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(haveImageOrContent){
|
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 false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,8 @@ import { toast } from "react-toastify";
|
||||||
const Form = () => {
|
const Form = () => {
|
||||||
const formik = useFormikContext<any>();
|
const formik = useFormikContext<any>();
|
||||||
const { setSuccess, Success, setSavedQuestionData ,ShowHint} = useObjectToEdit();
|
const { setSuccess, Success, setSavedQuestionData ,ShowHint} = useObjectToEdit();
|
||||||
|
console.log(formik.errors);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setSavedQuestionData(formik.values);
|
setSavedQuestionData(formik.values);
|
||||||
}, [formik?.values]);
|
}, [formik?.values]);
|
||||||
|
|
@ -33,7 +34,8 @@ const Form = () => {
|
||||||
|
|
||||||
{
|
{
|
||||||
answer: null,
|
answer: null,
|
||||||
answer_image: null,
|
content_image: null,
|
||||||
|
content:null,
|
||||||
isCorrect: 0,
|
isCorrect: 0,
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,16 @@ export const getValidationSchema = () => {
|
||||||
return hasCorrectAnswer && !haveImageOrContent ;
|
return hasCorrectAnswer && !haveImageOrContent ;
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
});
|
}).test(
|
||||||
|
"content-or-image-required",
|
||||||
|
"At least one of content or content_image must be provided",
|
||||||
|
(obj:any) => {
|
||||||
|
const isValid = !!obj.content || !!obj.content_image;
|
||||||
|
console.log(isValid,"isValid");
|
||||||
|
|
||||||
|
return isValid;
|
||||||
|
}
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getInitialValuesBase = (objectToEdit: Question): any => {
|
export const getInitialValuesBase = (objectToEdit: Question): any => {
|
||||||
|
|
@ -89,16 +98,16 @@ export const getValidationSchemaBase = () => {
|
||||||
// validate input
|
// validate input
|
||||||
return Yup.object().shape({
|
return Yup.object().shape({
|
||||||
content_image: Yup.string().nullable(),
|
content_image: Yup.string().nullable(),
|
||||||
content: Yup.string().required("validation.required"),
|
content: Yup.string(),
|
||||||
Questions: Yup.array().of(
|
Questions: Yup.array().of(
|
||||||
Yup.object().shape({
|
Yup.object().shape({
|
||||||
image: Yup.string().nullable(),
|
content_image: Yup.string().nullable(),
|
||||||
content: Yup.string().required("validation.required"),
|
content: Yup.string().nullable(),
|
||||||
answers: Yup.array()
|
answers: Yup.array()
|
||||||
.of(
|
.of(
|
||||||
Yup.object().shape({
|
Yup.object().shape({
|
||||||
content: Yup.string(),
|
content: Yup.string().nullable(),
|
||||||
answer_image: Yup.string().nullable(),
|
content_image: Yup.string().nullable(),
|
||||||
isCorrect: Yup.boolean(),
|
isCorrect: Yup.boolean(),
|
||||||
}),
|
}),
|
||||||
).min(2)
|
).min(2)
|
||||||
|
|
@ -114,9 +123,24 @@ export const getValidationSchemaBase = () => {
|
||||||
return hasCorrectAnswer && !haveImageOrContent ;
|
return hasCorrectAnswer && !haveImageOrContent ;
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
}),
|
}).test(
|
||||||
|
"content-or-image-required",
|
||||||
|
"At least one of content or content_image must be provided in question",
|
||||||
|
(obj:any) => {
|
||||||
|
|
||||||
|
const isValid = !!obj.content || !!obj.content_image;
|
||||||
|
return isValid;
|
||||||
|
}
|
||||||
|
),
|
||||||
).min(1),
|
).min(1),
|
||||||
});
|
}).test(
|
||||||
|
"content-or-image-required",
|
||||||
|
"At least one of content or content_image must be provided in base",
|
||||||
|
(obj:any) => {
|
||||||
|
const isValid = !!obj.content || !!obj.content_image;
|
||||||
|
return isValid;
|
||||||
|
}
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export function processTags(DataToSend: any) {
|
export function processTags(DataToSend: any) {
|
||||||
|
|
|
||||||
|
|
@ -322,12 +322,12 @@
|
||||||
|
|
||||||
.Choices {
|
.Choices {
|
||||||
transition: 0.5s ease-in-out ;
|
transition: 0.5s ease-in-out ;
|
||||||
animation: fadeIn .5s ease-in-out ;
|
animation: fadeIn .5s ease-in-out forwards ;
|
||||||
}
|
}
|
||||||
|
|
||||||
.exit {
|
.exit {
|
||||||
transition: 0.5s ease-in-out ;
|
transition: 0.5s ease-in-out ;
|
||||||
animation: fadeOut .5s ease-in-out ;
|
animation: fadeOut .7s ease-in-out forwards ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,8 @@
|
||||||
"it_should_have_more_than_one_answers": "يجب أن يحتوي على أكثر من إجابة",
|
"it_should_have_more_than_one_answers": "يجب أن يحتوي على أكثر من إجابة",
|
||||||
"it_should_have_more_than_one_correct_answers": "يجب أن يحتوي على إجابة صحيحة",
|
"it_should_have_more_than_one_correct_answers": "يجب أن يحتوي على إجابة صحيحة",
|
||||||
"File_size_exceeds_2_MB_limit.":"حجم الملف يتجاوز الحد الأقصى البالغ 2 ميجابايت",
|
"File_size_exceeds_2_MB_limit.":"حجم الملف يتجاوز الحد الأقصى البالغ 2 ميجابايت",
|
||||||
"one_of_image_and_content_should_be_enter":"يجب إدخال صورة أو محتوى واحد على الأقل"
|
"one_of_image_and_content_should_be_enter_in_answer":"يجب إدخال صورة أو محتوى واحد على الأقل في الاجابة",
|
||||||
|
"one_of_image_and_content_should_be_enter_in_question":"يجب إدخال صورة أو محتوى واحد على الأقل في السؤال"
|
||||||
},
|
},
|
||||||
"header": {
|
"header": {
|
||||||
"register_students": "تسجيل الطلاب",
|
"register_students": "تسجيل الطلاب",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user