dix bug
This commit is contained in:
parent
482c7341f8
commit
bd59108fdc
|
|
@ -46,7 +46,8 @@ console.log(objectToEdit,"objectToEdit");
|
||||||
|
|
||||||
const DataToSend = structuredClone(values);
|
const DataToSend = structuredClone(values);
|
||||||
setTagsSearch(null);
|
setTagsSearch(null);
|
||||||
|
console.log(1);
|
||||||
|
|
||||||
const canAnswersBeShuffled = DataToSend?.canAnswersBeShuffled ? 1 : 0;
|
const canAnswersBeShuffled = DataToSend?.canAnswersBeShuffled ? 1 : 0;
|
||||||
|
|
||||||
if (isBseQuestion || DataToSend?.isBase === 1) {
|
if (isBseQuestion || DataToSend?.isBase === 1) {
|
||||||
|
|
@ -95,9 +96,10 @@ console.log(objectToEdit,"objectToEdit");
|
||||||
console.log(newBseQuestionId, "newBseQuestionId");
|
console.log(newBseQuestionId, "newBseQuestionId");
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
console.log(1);
|
||||||
|
|
||||||
const tags = processTags(DataToSend);
|
const tags = processTags(DataToSend);
|
||||||
const answers = values?.answers?.map((item: any, index: number) => {
|
const answers = values?.answers?.map((item: any, index: number) => {
|
||||||
console.log(item,"item");
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
order: index,
|
order: index,
|
||||||
|
|
@ -108,7 +110,8 @@ console.log(objectToEdit,"objectToEdit");
|
||||||
if(answers?.length > 0){
|
if(answers?.length > 0){
|
||||||
|
|
||||||
const isValidAnswers = answers?.some((answer:any) => answer?.isCorrect === 1)
|
const isValidAnswers = answers?.some((answer:any) => answer?.isCorrect === 1)
|
||||||
|
console.log(!isValidAnswers);
|
||||||
|
|
||||||
if(!isValidAnswers){
|
if(!isValidAnswers){
|
||||||
toast.error(t("validation.at_least_one_answer_should_be_correct"));
|
toast.error(t("validation.at_least_one_answer_should_be_correct"));
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -105,10 +105,10 @@ const EditPage: React.FC = () => {
|
||||||
|
|
||||||
const isValidAnswers = updatedObject?.answers?.some((answer:any) => answer?.isCorrect === 1)
|
const isValidAnswers = updatedObject?.answers?.some((answer:any) => answer?.isCorrect === 1)
|
||||||
|
|
||||||
if(!isValidAnswers){
|
// if(!isValidAnswers){
|
||||||
toast.error(t("validation.at_least_one_answer_should_be_correct"));
|
// toast.error(t("validation.at_least_one_answer_should_be_correct"));
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
updatedObject?.answers?.forEach((item: any) => {
|
updatedObject?.answers?.forEach((item: any) => {
|
||||||
if (item?.id) {
|
if (item?.id) {
|
||||||
|
|
@ -156,14 +156,15 @@ const EditPage: React.FC = () => {
|
||||||
const newAnswers = [] as any;
|
const newAnswers = [] as any;
|
||||||
if(updatedObject?.answers?.length > 0){
|
if(updatedObject?.answers?.length > 0){
|
||||||
|
|
||||||
const isValidAnswers = updatedObject?.answers?.some((answer:any) => answer?.isCorrect === 1 || answer?.isCorrect === true)
|
// const isValidAnswers = updatedObject?.answers?.some((answer:any) => answer?.isCorrect === 1 || answer?.isCorrect === true)
|
||||||
const isValidAnswers2 = updatedObject?.answers?.filter((answer: any) => answer?.isCorrect === 1 || answer?.isCorrect === true ).length > 1;
|
// const isValidAnswers2 = updatedObject?.answers?.filter((answer: any) => answer?.isCorrect === 1 || answer?.isCorrect === true ).length > 1;
|
||||||
console.log(isValidAnswers2);
|
// console.log(isValidAnswers2);
|
||||||
|
// console.log(isValidAnswers,"isValidAnswers");
|
||||||
if(!isValidAnswers || isValidAnswers2){
|
|
||||||
toast.error(t("validation.at_least_one_answer_should_be_correct"));
|
// if(!isValidAnswers || isValidAnswers2){
|
||||||
return;
|
// toast.error(t("validation.at_least_one_answer_should_be_correct"));
|
||||||
}
|
// return;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
updatedObject?.answers?.forEach((item: any) => {
|
updatedObject?.answers?.forEach((item: any) => {
|
||||||
if (item?.id) {
|
if (item?.id) {
|
||||||
|
|
@ -177,8 +178,15 @@ const EditPage: React.FC = () => {
|
||||||
old: oldAnswers,
|
old: oldAnswers,
|
||||||
new: newAnswers,
|
new: newAnswers,
|
||||||
};
|
};
|
||||||
|
console.log(tags,"tags");
|
||||||
|
if(tags?.new?.length < 1 && tags?.old?.length < 1){
|
||||||
|
mutate({ ...updatedObject, answers, tags:"" });
|
||||||
|
|
||||||
mutate({ ...updatedObject, answers, tags });
|
}else{
|
||||||
|
|
||||||
|
mutate({ ...updatedObject, answers, tags });
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,8 @@ const CheckboxField = ({
|
||||||
disabled={isDisabled}
|
disabled={isDisabled}
|
||||||
checked={
|
checked={
|
||||||
formik.values?.Questions?.[parent_index]?.answers?.[name]
|
formik.values?.Questions?.[parent_index]?.answers?.[name]
|
||||||
?.isCorrect === 1
|
?.isCorrect === 1 || formik.values?.Questions?.[parent_index]?.answers?.[name]
|
||||||
|
?.isCorrect === true
|
||||||
}
|
}
|
||||||
className={className}
|
className={className}
|
||||||
>
|
>
|
||||||
|
|
|
||||||
|
|
@ -43,11 +43,8 @@ const Form = () => {
|
||||||
handleAddChoice(true)
|
handleAddChoice(true)
|
||||||
|
|
||||||
});
|
});
|
||||||
console.log(Success);
|
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log(Success);
|
|
||||||
|
|
||||||
if(Success){
|
if(Success){
|
||||||
formik?.setValues({})
|
formik?.setValues({})
|
||||||
|
|
|
||||||
|
|
@ -34,13 +34,7 @@ export const getValidationSchema = () => {
|
||||||
content_image: Yup.string().nullable(),
|
content_image: Yup.string().nullable(),
|
||||||
isCorrect: Yup.boolean(),
|
isCorrect: Yup.boolean(),
|
||||||
}),
|
}),
|
||||||
).test(
|
)
|
||||||
'at-least-one-correct',
|
|
||||||
'At least one answer must be correct',
|
|
||||||
(answers:any) => {
|
|
||||||
return answers.some((answer:any) => answer.isCorrect === true);
|
|
||||||
}
|
|
||||||
),
|
|
||||||
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
@ -100,7 +94,7 @@ export const getValidationSchemaBase = () => {
|
||||||
(answers:any) => {
|
(answers:any) => {
|
||||||
console.log(answers,"answers");
|
console.log(answers,"answers");
|
||||||
|
|
||||||
return answers.some((answer:any) => answer.isCorrect === true);
|
return answers.some((answer:any) => answer.isCorrect === true || answer.isCorrect === 1);
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
}),
|
}),
|
||||||
|
|
@ -113,8 +107,8 @@ export function processTags(DataToSend: any) {
|
||||||
|
|
||||||
const oldTags = DataToSend?.tags
|
const oldTags = DataToSend?.tags
|
||||||
?.map((item: any, index: number) => {
|
?.map((item: any, index: number) => {
|
||||||
if (typeof item === "number") {
|
if (typeof item === "number" || typeof item?.id === "number") {
|
||||||
return item;
|
return item?.id ?? item ;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.filter((item: any) => item !== undefined);
|
.filter((item: any) => item !== undefined);
|
||||||
|
|
@ -123,10 +117,10 @@ export function processTags(DataToSend: any) {
|
||||||
?.map((item: any, index: number) => {
|
?.map((item: any, index: number) => {
|
||||||
console.log(item);
|
console.log(item);
|
||||||
|
|
||||||
if (typeof item === "string" && item !== "") {
|
if (typeof item === "string" && item !== "" || typeof item?.id === "string" && item?.id !== "" ) {
|
||||||
console.log(item);
|
console.log(item);
|
||||||
|
|
||||||
return { name: item };
|
return { name: item?.id ?? item };
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.filter((item: any) => item !== undefined);
|
.filter((item: any) => item !== undefined);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user