Compare commits

..

2 Commits

Author SHA1 Message Date
karimaldeen
9f05382d6c fix 2024-10-09 16:27:26 +03:00
karimaldeen
7c54d52d98 fix nullable content 2024-10-08 09:42:14 +03:00
4 changed files with 17 additions and 14 deletions

View File

@ -75,10 +75,9 @@ const LaTeXInputMemo: React.FC<any> = React.memo(({ field ,form, label, ...prop
console.log(values);
let metaName = name.substring(0, name.lastIndexOf('.'));
if (metaName.includes('.')) { metaName += ".meta";} else {metaName += "meta"}
console.log(metaName);
if (metaName.includes('.') || metaName.includes('[')) { metaName += ".meta";} else {metaName += "meta"}
const meta = getFieldProps(metaName).value ;
console.log(meta);
console.log(metaName,meta);
const direction = meta?.direction === "ltr" ? "ltr" : "rtl"
const [Dir, setDir] = useState<"ltr" | "rtl">(direction)

View File

@ -7,6 +7,7 @@ export const handleValidateSingleQuestion = (values:any,isValid:boolean,handleSu
const haveImageOrContent = haveOneAnswerRight && values?.answers?.some((item:any)=> !(item?.content) && !(item.content_image) )
const haveDuplicatedContent = hasDuplicateArrayValue(values?.answers,"content")
console.log("karim","karim");
const content = values.content ;
const content_image = values.content_image ;
@ -45,6 +46,7 @@ export const handleValidateBaseQuestion = (values: any,isValid:boolean,handleSub
const content_image = values.content_image ;
const haveContentOrContentImage = !!content || !!content_image ;
const haveDuplicatedContent = hasDuplicateArrayValue(values?.Questions,"content")
console.log(1);
if(!haveContentOrContentImage){
toast.error(`${t("validation.one_of_image_and_content_should_be_enter_in_question")}`);

View File

@ -19,7 +19,7 @@ export const getInitialValues = (objectToEdit: Question): any => {
parent_id: objectToEdit?.parent_id ?? "",
answers: objectToEdit?.answers ?? null,
tags: tags ?? [],
meta : objectToEdit?.meta ?? { direction : "rtl" }
meta : objectToEdit?.meta
};
};
@ -78,32 +78,34 @@ export const getInitialValuesBase = (objectToEdit: Question): any => {
}
})
console.log(objectToEdit?.meta );
return {
...item,
answer:newAnswers,
canAnswersBeShuffled: objectToEdit?.canAnswersBeShuffled ? 1 : 0,
hint: objectToEdit?.hint ?? "",
hint: item?.hint ?? "",
canAnswersBeShuffled:0,
isBase: 0,
tags,
meta : objectToEdit?.meta ?? { direction : "rtl" }
meta : item?.meta
};
});
const questions = newQuestions ?? [{answers:[]}];
console.log(questions?.[0]?.meta,"questions");
return {
id: objectToEdit?.id ?? null,
content: objectToEdit?.content ?? null,
content_image: objectToEdit?.content_image ?? "",
content_image: objectToEdit?.content_image ?? null,
subject_id: objectToEdit?.subject_id ?? "",
isBase: 1,
parent_id: objectToEdit?.parent_id ?? "",
canAnswersBeShuffled: objectToEdit?.canAnswersBeShuffled ? 1 : 0,
hint: objectToEdit?.hint ?? null,
Questions: questions,
meta : objectToEdit?.meta ?? { direction : "rtl" }
meta : objectToEdit?.meta
};
};
@ -112,7 +114,7 @@ export const getValidationSchemaBase = () => {
// validate input
return Yup.object().shape({
content_image: Yup.string().nullable(),
content: Yup.string(),
content: Yup.string().nullable(),
Questions: Yup.array().of(
Yup.object().shape({
content_image: Yup.string().nullable(),

View File

@ -11,7 +11,7 @@ export const hasDuplicateArrayValue = <T>(data: T[], key: keyof T): boolean => {
for (const item of data) {
const value = item[key]; // Accessing the value using the key
if (hashMap.has(value)) {
if (hashMap.has(value) && value !== null ) {
return true; // Duplicate found
} else {
hashMap.set(value, true); // Store the value as a key in the map