Compare commits
3 Commits
687640f7a4
...
6213253337
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6213253337 | ||
|
|
fa8e8a7099 | ||
|
|
e020fb69c1 |
51
src/Components/Drage/DragAndDropList.tsx
Normal file
51
src/Components/Drage/DragAndDropList.tsx
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
import React, { useState } from 'react';
|
||||
|
||||
const DragAndDropList: React.FC = () => {
|
||||
const [items, setItems] = useState<string[]>(['Item 1', 'Item 2', 'Item 3', 'Item 4']);
|
||||
const [draggedItemIndex, setDraggedItemIndex] = useState<number | null>(null);
|
||||
|
||||
const handleDragStart = (index: number) => {
|
||||
setDraggedItemIndex(index);
|
||||
};
|
||||
|
||||
const handleDragOver = (index: number) => {
|
||||
if (index !== draggedItemIndex && draggedItemIndex !== null) {
|
||||
const newItems = [...items];
|
||||
const draggedItem = newItems[draggedItemIndex];
|
||||
newItems.splice(draggedItemIndex, 1);
|
||||
newItems.splice(index, 0, draggedItem);
|
||||
setItems(newItems);
|
||||
setDraggedItemIndex(index);
|
||||
}
|
||||
};
|
||||
|
||||
const handleDrop = () => {
|
||||
setDraggedItemIndex(null);
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
{items.map((item, index) => (
|
||||
<div
|
||||
key={index}
|
||||
draggable
|
||||
onDragStart={() => handleDragStart(index)}
|
||||
onDragOver={() => handleDragOver(index)}
|
||||
onDrop={handleDrop}
|
||||
style={{
|
||||
padding: '8px',
|
||||
margin: '4px',
|
||||
border: '1px solid #ccc',
|
||||
backgroundColor: '#f9f9f9',
|
||||
cursor: 'move',
|
||||
userSelect: 'none'
|
||||
}}
|
||||
>
|
||||
{item}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default DragAndDropList;
|
||||
|
|
@ -10,11 +10,11 @@ const App: React.FC = () => {
|
|||
const { subject_id } = useParams<ParamsEnum>();
|
||||
const response = useGetAllUnit({ subject_id: subject_id, pagination: true });
|
||||
const { setOldObjectToEdit } = useObjectToEdit();
|
||||
console.log(response?.data?.data, "response?.data");
|
||||
// console.log(response?.data?.data, "response?.data");
|
||||
const data = response?.data?.data;
|
||||
const lastElement =
|
||||
response?.data?.data && response?.data?.data[data?.length - 1];
|
||||
console.log(lastElement);
|
||||
// console.log(lastElement);
|
||||
|
||||
useEffect(() => {
|
||||
if (lastElement) {
|
||||
|
|
|
|||
|
|
@ -11,11 +11,11 @@ const App: React.FC = () => {
|
|||
const response = useGetAllLesson({ unit_id: unit_id, pagination: true });
|
||||
|
||||
const { setOldObjectToEdit } = useObjectToEdit();
|
||||
console.log(response?.data?.data, "response?.data");
|
||||
// console.log(response?.data?.data, "response?.data");
|
||||
const data = response?.data?.data;
|
||||
const lastElement =
|
||||
response?.data?.data && response?.data?.data[data?.length - 1];
|
||||
console.log(lastElement);
|
||||
// console.log(lastElement);
|
||||
|
||||
useEffect(() => {
|
||||
if (lastElement) {
|
||||
|
|
|
|||
|
|
@ -103,8 +103,7 @@ const AddPage: React.FC = () => {
|
|||
) => {
|
||||
const DataToSend = structuredClone(values);
|
||||
console.log(DataToSend);
|
||||
|
||||
return ;
|
||||
|
||||
setTagsSearch(null);
|
||||
const canAnswersBeShuffled = DataToSend?.canAnswersBeShuffled ? 1 : 0;
|
||||
if (isBseQuestion || DataToSend?.isBase === 1) {
|
||||
|
|
@ -126,25 +125,42 @@ const AddPage: React.FC = () => {
|
|||
Questions?.map((item: Question) => {
|
||||
const tags = processTags(item);
|
||||
console.log(item);
|
||||
const answers = item?.answers?.map((item:any,index:number)=>{
|
||||
return {
|
||||
order:index,
|
||||
...item
|
||||
}
|
||||
})
|
||||
console.log(answers);
|
||||
|
||||
mutate({
|
||||
mutate({
|
||||
...item,
|
||||
parent_id: newBseQuestionId,
|
||||
subject_id: subject_id,
|
||||
tags,
|
||||
lessons_ids: [lesson_id],
|
||||
answers
|
||||
});
|
||||
});
|
||||
console.log(newBseQuestionId, "newBseQuestionId");
|
||||
});
|
||||
} else {
|
||||
const tags = processTags(DataToSend);
|
||||
console.log(values,"values");
|
||||
const answers = values?.answers?.map((item:any,index:number)=>{
|
||||
return {
|
||||
order:index,
|
||||
...item
|
||||
}
|
||||
})
|
||||
|
||||
mutate({
|
||||
...values,
|
||||
subject_id: subject_id,
|
||||
tags,
|
||||
lessons_ids: [lesson_id],
|
||||
canAnswersBeShuffled,
|
||||
answers
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -168,8 +184,8 @@ const AddPage: React.FC = () => {
|
|||
}
|
||||
}, [isSuccess, isSuccessAsync]);
|
||||
|
||||
let cleanedQuestionOptions = cleanObject(SavedQuestionData);
|
||||
let noChange = hasItems(cleanedQuestionOptions);
|
||||
let cleanedAnswers = cleanObject(SavedQuestionData);
|
||||
let noChange = hasItems(cleanedAnswers);
|
||||
|
||||
useSaveOnDisconnect(noChange, QUESTION_OBJECT_KEY, SavedQuestionData);
|
||||
|
||||
|
|
|
|||
|
|
@ -152,25 +152,25 @@ const EditPage: React.FC = () => {
|
|||
console.log(updatedObject, "updatedObject");
|
||||
|
||||
const tags = processTags(updatedObject);
|
||||
const oldQuestionOptions = [] as any;
|
||||
const newQuestionOptions = [] as any;
|
||||
const oldanswers = [] as any;
|
||||
const newanswers = [] as any;
|
||||
|
||||
updatedObject?.QuestionOptions?.forEach((item: any) => {
|
||||
updatedObject?.answers?.forEach((item: any) => {
|
||||
if (item?.id) {
|
||||
oldQuestionOptions.push(item);
|
||||
oldanswers.push(item);
|
||||
} else {
|
||||
newQuestionOptions.push(item);
|
||||
newanswers.push(item);
|
||||
}
|
||||
});
|
||||
const QuestionOptions = {
|
||||
old: oldQuestionOptions,
|
||||
new: newQuestionOptions,
|
||||
const answers = {
|
||||
old: oldanswers,
|
||||
new: newanswers,
|
||||
};
|
||||
console.log(QuestionOptions);
|
||||
console.log(answers);
|
||||
|
||||
mutate({
|
||||
...updatedObject,
|
||||
QuestionOptions,
|
||||
answers,
|
||||
tags,
|
||||
});
|
||||
} else {
|
||||
|
|
@ -197,26 +197,26 @@ const EditPage: React.FC = () => {
|
|||
}
|
||||
console.log(updatedObject);
|
||||
|
||||
const oldQuestionOptions = [] as any;
|
||||
const newQuestionOptions = [] as any;
|
||||
const oldanswers = [] as any;
|
||||
const newanswers = [] as any;
|
||||
|
||||
updatedObject?.QuestionOptions?.forEach((item: any) => {
|
||||
updatedObject?.answers?.forEach((item: any) => {
|
||||
if (item?.id) {
|
||||
console.log(item);
|
||||
|
||||
oldQuestionOptions.push(item);
|
||||
oldanswers.push(item);
|
||||
} else {
|
||||
newQuestionOptions.push(item);
|
||||
newanswers.push(item);
|
||||
}
|
||||
});
|
||||
|
||||
const QuestionOptions = {
|
||||
old: oldQuestionOptions,
|
||||
new: newQuestionOptions,
|
||||
const answers = {
|
||||
old: oldanswers,
|
||||
new: newanswers,
|
||||
};
|
||||
console.log(QuestionOptions, "QuestionOptions");
|
||||
console.log(answers, "answers");
|
||||
|
||||
mutate({ ...updatedObject, QuestionOptions, tags });
|
||||
mutate({ ...updatedObject, answers, tags });
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -15,18 +15,18 @@ const CheckboxField = ({
|
|||
const formik = useFormikContext<any>();
|
||||
const [t] = useTranslation();
|
||||
const CheckboxhandleChange = (value: any, index: number) => {
|
||||
const allAreZero = formik?.values?.QuestionOptions?.some(
|
||||
const allAreZero = formik?.values?.answers?.some(
|
||||
(item: any) => item.isCorrect === 1,
|
||||
);
|
||||
|
||||
if (allAreZero) {
|
||||
formik?.values.QuestionOptions.forEach((item: any, index: number) => {
|
||||
formik.setFieldValue(`QuestionOptions[${index}].isCorrect`, 0);
|
||||
formik?.values.answers.forEach((item: any, index: number) => {
|
||||
formik.setFieldValue(`answers[${index}].isCorrect`, 0);
|
||||
});
|
||||
}
|
||||
|
||||
formik.setFieldValue(
|
||||
`QuestionOptions[${name}].isCorrect`,
|
||||
`answers[${name}].isCorrect`,
|
||||
value?.target?.checked ? 1 : 0,
|
||||
);
|
||||
};
|
||||
|
|
@ -35,7 +35,7 @@ const CheckboxField = ({
|
|||
<Checkbox
|
||||
onChange={onChange || CheckboxhandleChange}
|
||||
disabled={isDisabled}
|
||||
checked={formik.values?.QuestionOptions?.[name]?.isCorrect === 1}
|
||||
checked={formik.values?.answers?.[name]?.isCorrect === 1}
|
||||
className={className}
|
||||
>
|
||||
{t(`input.${label ? label : name}`)}
|
||||
|
|
|
|||
|
|
@ -18,13 +18,13 @@ const ChoiceFields = ({ index, data }: { index: number; data: Choice }) => {
|
|||
|
||||
const handleDeleteChoice = () => {
|
||||
console.log(index);
|
||||
console.log(formik.values.QuestionOptions[index]);
|
||||
console.log(formik.values.answers[index]);
|
||||
|
||||
const updatedQuestionOptions = formik.values.QuestionOptions.filter(
|
||||
const updatedAnswers = formik.values.answers.filter(
|
||||
(_: any, i: any) => i !== index,
|
||||
);
|
||||
|
||||
formik.setFieldValue("QuestionOptions", updatedQuestionOptions);
|
||||
formik.setFieldValue("answers", updatedAnswers);
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ const Choices = () => {
|
|||
// Check if the item was dropped outside the list
|
||||
if (!result.destination) return;
|
||||
|
||||
// Create a new array from the current QuestionOptions
|
||||
const items = Array.from(formik?.values?.QuestionOptions);
|
||||
// Create a new array from the current answers
|
||||
const items = Array.from(formik?.values?.answers);
|
||||
|
||||
// Remove the item from the original position
|
||||
const [reorderedItem] = items.splice(result.source.index, 1);
|
||||
|
|
@ -29,7 +29,7 @@ const Choices = () => {
|
|||
// Update the formik state with the new order
|
||||
console.log(updatedItems, "updatedItems");
|
||||
|
||||
formik.setFieldValue("QuestionOptions", updatedItems);
|
||||
formik.setFieldValue("answers", updatedItems);
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
@ -37,7 +37,7 @@ const Choices = () => {
|
|||
<Droppable droppableId="choices">
|
||||
{(provided) => (
|
||||
<div {...provided.droppableProps} ref={provided.innerRef}>
|
||||
{formik?.values?.QuestionOptions?.map(
|
||||
{formik?.values?.answers?.map(
|
||||
(item: Choice, index: number) => {
|
||||
// Use a unique identifier for draggableId
|
||||
const draggableId = item.name
|
||||
|
|
|
|||
|
|
@ -12,10 +12,10 @@ const File = ({
|
|||
className,
|
||||
props,
|
||||
}: any) => {
|
||||
const newName = `QuestionOptions[${name}].answer_image`;
|
||||
const newName = `answers[${name}].answer_image`;
|
||||
|
||||
const { formik, t, isError, errorMsg } = useFormField(newName, props);
|
||||
let imageUrl = formik?.values?.QuestionOptions[name]?.answer_image ?? null;
|
||||
let imageUrl = formik?.values?.answers[name]?.answer_image ?? null;
|
||||
// console.log(imageUrl);
|
||||
|
||||
const fileList: UploadFile[] = useMemo(() => {
|
||||
|
|
@ -46,7 +46,7 @@ const File = ({
|
|||
formik.setFieldValue(newName, null);
|
||||
} else {
|
||||
formik.setFieldValue(
|
||||
`QuestionOptions[${name}].answer_image`,
|
||||
`answers[${name}].answer_image`,
|
||||
value?.file?.originFileObj,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ const HintField = ({
|
|||
id,
|
||||
className,
|
||||
}: any) => {
|
||||
const newName = `QuestionOptions[${name}].hint`;
|
||||
const newName = `answers[${name}].hint`;
|
||||
const { formik, isError, errorMsg, t } = useFormField(newName, props);
|
||||
const TextFilehandleChange = (
|
||||
e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>,
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ const TextField = ({
|
|||
id,
|
||||
className,
|
||||
}: any) => {
|
||||
const newName = `QuestionOptions[${name}].answer`;
|
||||
const newName = `answers[${name}].content`;
|
||||
const { formik, isError, errorMsg, t } = useFormField(newName, props);
|
||||
const TextFilehandleChange = (
|
||||
e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>,
|
||||
|
|
|
|||
|
|
@ -33,9 +33,9 @@ const Form = () => {
|
|||
const handleAddChoice = (parent_index: number) => {
|
||||
console.log(parent_index);
|
||||
|
||||
formik.setFieldValue(`Questions.[${parent_index}].QuestionOptions`, [
|
||||
formik.setFieldValue(`Questions.[${parent_index}].answers`, [
|
||||
...((formik?.values as any)?.Questions?.[parent_index]
|
||||
.QuestionOptions as Choice[]),
|
||||
.answers as Choice[]),
|
||||
|
||||
{
|
||||
answer: null,
|
||||
|
|
@ -54,9 +54,9 @@ const Form = () => {
|
|||
image: "",
|
||||
parent: "",
|
||||
isBase: 0,
|
||||
max_mark: 1,
|
||||
min_mark_to_pass: 1,
|
||||
QuestionOptions: [{ answer: null, answer_image: null, isCorrect: 0 }],
|
||||
// max_mark: 1,
|
||||
// min_mark_to_pass: 1,
|
||||
answers: [{ answer: null, answer_image: null, isCorrect: 0 }],
|
||||
tags: [],
|
||||
},
|
||||
]);
|
||||
|
|
@ -106,7 +106,7 @@ const Form = () => {
|
|||
|
||||
<Choices parent_index={parent_index} />
|
||||
|
||||
{formik?.values?.Questions?.[parent_index]?.QuestionOptions
|
||||
{formik?.values?.Questions?.[parent_index]?.answers
|
||||
?.length < 5 && (
|
||||
<p className="add_new_button">
|
||||
<FaCirclePlus
|
||||
|
|
|
|||
|
|
@ -19,12 +19,12 @@ const CheckboxField = ({
|
|||
|
||||
const allAreZero = formik?.values?.Questions?.[
|
||||
parent_index
|
||||
]?.QuestionOptions?.some((item: any) => item.isCorrect === 1);
|
||||
]?.answers?.some((item: any) => item.isCorrect === 1);
|
||||
if (allAreZero) {
|
||||
formik?.values?.Questions?.[parent_index]?.QuestionOptions.forEach(
|
||||
formik?.values?.Questions?.[parent_index]?.answers.forEach(
|
||||
(item: any, index: number) => {
|
||||
formik.setFieldValue(
|
||||
`Questions[${parent_index}].QuestionOptions[${index}].isCorrect`,
|
||||
`Questions[${parent_index}].answers[${index}].isCorrect`,
|
||||
0,
|
||||
);
|
||||
},
|
||||
|
|
@ -32,7 +32,7 @@ const CheckboxField = ({
|
|||
}
|
||||
|
||||
formik.setFieldValue(
|
||||
`Questions[${parent_index}].QuestionOptions[${name}].isCorrect`,
|
||||
`Questions[${parent_index}].answers[${name}].isCorrect`,
|
||||
value?.target?.checked ? 1 : 0,
|
||||
);
|
||||
};
|
||||
|
|
@ -42,7 +42,7 @@ const CheckboxField = ({
|
|||
onChange={onChange || CheckboxhandleChange}
|
||||
disabled={isDisabled}
|
||||
checked={
|
||||
formik.values?.Questions?.[parent_index]?.QuestionOptions?.[name]
|
||||
formik.values?.Questions?.[parent_index]?.answers?.[name]
|
||||
?.isCorrect === 1
|
||||
}
|
||||
className={className}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ const ChoiceFields = ({
|
|||
|
||||
const handleDeleteChoice = () => {
|
||||
const arrayLength =
|
||||
formik.values.Questions?.[parent_index].QuestionOptions?.length;
|
||||
formik.values.Questions?.[parent_index].answers?.length;
|
||||
|
||||
console.log(arrayLength);
|
||||
|
||||
|
|
@ -37,12 +37,12 @@ const ChoiceFields = ({
|
|||
return;
|
||||
}
|
||||
|
||||
const updatedQuestionOptions = formik.values.Questions?.[
|
||||
const updatedAnswers = formik.values.Questions?.[
|
||||
parent_index
|
||||
].QuestionOptions.filter((_: any, i: any) => i !== index);
|
||||
].answers.filter((_: any, i: any) => i !== index);
|
||||
formik.setFieldValue(
|
||||
`Questions[${parent_index}].QuestionOptions`,
|
||||
updatedQuestionOptions,
|
||||
`Questions[${parent_index}].answers`,
|
||||
updatedAnswers,
|
||||
);
|
||||
};
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -14,10 +14,10 @@ const Choices = ({ parent_index }: { parent_index: number }) => {
|
|||
|
||||
if (!result.destination) return;
|
||||
|
||||
console.log(formik?.values?.Questions?.[parent_index]?.QuestionOptions);
|
||||
console.log(formik?.values?.Questions?.[parent_index]?.answers);
|
||||
|
||||
// Create a new array from the current QuestionOptions
|
||||
const items = Array.from(formik?.values?.Questions?.[parent_index]?.QuestionOptions);
|
||||
// Create a new array from the current answers
|
||||
const items = Array.from(formik?.values?.Questions?.[parent_index]?.answers);
|
||||
console.log(items);
|
||||
// Remove the item from the original position
|
||||
const [reorderedItem] = items.splice(result.source.index, 1);
|
||||
|
|
@ -36,7 +36,7 @@ const Choices = ({ parent_index }: { parent_index: number }) => {
|
|||
// Update the formik state with the new order
|
||||
console.log(updatedItems, "updatedItems");
|
||||
|
||||
formik.setFieldValue(`Questions.${parent_index}.QuestionOptions`, updatedItems);
|
||||
formik.setFieldValue(`Questions.${parent_index}.answers`, updatedItems);
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
@ -47,7 +47,7 @@ const Choices = ({ parent_index }: { parent_index: number }) => {
|
|||
<div {...provided.droppableProps} ref={provided.innerRef}>
|
||||
{(
|
||||
(formik?.values as any)?.Questions?.[parent_index]
|
||||
?.QuestionOptions || []
|
||||
?.answers || []
|
||||
).map((item: Choice, index: number) => {
|
||||
const draggableId = item.name
|
||||
? item.name.toString()
|
||||
|
|
|
|||
|
|
@ -13,11 +13,11 @@ const File = ({
|
|||
parent_index,
|
||||
props,
|
||||
}: any) => {
|
||||
const newName = `Questions[${parent_index}].QuestionOptions[${name}].answer_image`;
|
||||
const newName = `Questions[${parent_index}].answers[${name}].answer_image`;
|
||||
|
||||
const { formik, t, isError, errorMsg } = useFormField(newName, props);
|
||||
let imageUrl =
|
||||
formik?.values?.Questions?.[parent_index]?.QuestionOptions[name]
|
||||
formik?.values?.Questions?.[parent_index]?.answers[name]
|
||||
?.answer_image ?? null;
|
||||
// console.log(imageUrl);
|
||||
|
||||
|
|
@ -49,7 +49,7 @@ const File = ({
|
|||
formik.setFieldValue(newName, null);
|
||||
} else {
|
||||
formik.setFieldValue(
|
||||
`Questions[${parent_index}].QuestionOptions[${name}].answer_image`,
|
||||
`Questions[${parent_index}].answers[${name}].answer_image`,
|
||||
value?.file?.originFileObj,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ const HintField = ({
|
|||
id,
|
||||
className,
|
||||
}: any) => {
|
||||
const newName = `Questions[${parent_index}].QuestionOptions[${name}].hint`;
|
||||
const newName = `Questions[${parent_index}].answers[${name}].hint`;
|
||||
|
||||
const { formik, isError, errorMsg, t } = useFormField(newName, props);
|
||||
const TextFilehandleChange = (
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ const TextField = ({
|
|||
parent_index,
|
||||
className,
|
||||
}: any) => {
|
||||
const newName = `Questions[${parent_index}].QuestionOptions[${name}].answer`;
|
||||
const newName = `Questions[${parent_index}].answers[${name}].content`;
|
||||
const { formik, isError, errorMsg, t } = useFormField(newName, props);
|
||||
const TextFilehandleChange = (
|
||||
e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>,
|
||||
|
|
|
|||
|
|
@ -30,9 +30,9 @@ const Form = () => {
|
|||
const handleAddChoice = (parent_index: number) => {
|
||||
console.log(parent_index);
|
||||
console.log(formik?.values?.Questions);
|
||||
formik.setFieldValue(`Questions.[${parent_index}].QuestionOptions`, [
|
||||
formik.setFieldValue(`Questions.[${parent_index}].answers`, [
|
||||
...((formik?.values as any)?.Questions?.[parent_index]
|
||||
.QuestionOptions as Choice[]),
|
||||
.answers as Choice[]),
|
||||
|
||||
{
|
||||
answer: null,
|
||||
|
|
@ -53,7 +53,7 @@ const Form = () => {
|
|||
isBase: 0,
|
||||
max_mark: 1,
|
||||
min_mark_to_pass: 1,
|
||||
QuestionOptions: [{ answer: null, answer_image: null, isCorrect: 0 }],
|
||||
answers: [{ answer: null, answer_image: null, isCorrect: 0 }],
|
||||
tags: [],
|
||||
},
|
||||
]);
|
||||
|
|
@ -103,7 +103,7 @@ const Form = () => {
|
|||
|
||||
{(
|
||||
(formik?.values as any)?.Questions?.[parent_index]
|
||||
?.QuestionOptions || []
|
||||
?.answers || []
|
||||
).map((item: Choice, index: number) => {
|
||||
return (
|
||||
<ChoiceFields
|
||||
|
|
@ -114,7 +114,7 @@ const Form = () => {
|
|||
/>
|
||||
);
|
||||
})}
|
||||
{formik?.values?.Questions?.[parent_index]?.QuestionOptions
|
||||
{formik?.values?.Questions?.[parent_index]?.answers
|
||||
?.length < 5 && (
|
||||
<p className="add_new_button">
|
||||
<FaCirclePlus
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ const HintField = ({
|
|||
// console.log('Change:', e.target.value);
|
||||
formik.setFieldValue(newName, e.target.value);
|
||||
};
|
||||
|
||||
|
||||
return (
|
||||
<div className={`ValidationField w-100 ${className ?? ""} `}>
|
||||
<label htmlFor={name} className="text">
|
||||
|
|
|
|||
|
|
@ -26,10 +26,10 @@ const QuestionFIeld = ({ index, data }: { index: number; data: Choice }) => {
|
|||
if (DeleteQuestionId?.id) {
|
||||
setDeletedQuestions([...DeletedQuestions, DeleteQuestionId]);
|
||||
}
|
||||
const updatedQuestionOptions = formik.values.Questions.filter(
|
||||
const updatedAnswers = formik.values.Questions.filter(
|
||||
(_: any, i: any) => i !== index,
|
||||
);
|
||||
formik.setFieldValue(`Questions`, updatedQuestionOptions);
|
||||
formik.setFieldValue(`Questions`, updatedAnswers);
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -1,33 +0,0 @@
|
|||
import React, { useState } from "react";
|
||||
import MathJax from "react-mathjax";
|
||||
|
||||
const MathInput: React.FC = () => {
|
||||
const [input, setInput] = useState<string>(
|
||||
"a^2+b^2=c^2 (x+a)^n=x=(-b±√(b^2-4ac))/2a ∑_(k=0)^n▒〖(n¦k) x^k a^(n-k) 〗",
|
||||
);
|
||||
|
||||
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const formattedInput = event.target.value.replace("_", " _ ");
|
||||
console.log(event.target.value);
|
||||
|
||||
setInput(formattedInput);
|
||||
};
|
||||
|
||||
return (
|
||||
<MathJax.Provider>
|
||||
<div>
|
||||
<input
|
||||
type="text"
|
||||
id="mathInput"
|
||||
value={input}
|
||||
onChange={handleChange}
|
||||
/>
|
||||
<div>
|
||||
<MathJax.Node formula={input} />
|
||||
</div>
|
||||
</div>
|
||||
</MathJax.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export default MathInput;
|
||||
|
|
@ -28,10 +28,10 @@ const Form = () => {
|
|||
}, [formik?.values]);
|
||||
|
||||
const handleAddChoice = () => {
|
||||
formik.setFieldValue("QuestionOptions", [
|
||||
...((formik?.values as any)?.QuestionOptions as Choice[]),
|
||||
formik.setFieldValue("answers", [
|
||||
...((formik?.values as any)?.answers as Choice[]),
|
||||
{
|
||||
answer: null,
|
||||
content: null,
|
||||
answer_image: null,
|
||||
isCorrect: 0,
|
||||
},
|
||||
|
|
@ -69,7 +69,7 @@ const Form = () => {
|
|||
/>
|
||||
</div>
|
||||
<Choices />
|
||||
{formik?.values?.QuestionOptions?.length < 5 && (
|
||||
{formik?.values?.answers?.length < 5 && (
|
||||
<p className="add_new_button">
|
||||
<FaCirclePlus onClick={handleAddChoice} size={23} />{" "}
|
||||
{t("header.add_new_choice")}
|
||||
|
|
|
|||
|
|
@ -7,16 +7,18 @@ export const getInitialValues = (objectToEdit: Question): any => {
|
|||
const tags = objectToEdit?.tags?.map((item: any, index: number) => {
|
||||
return { ...item, key: index };
|
||||
});
|
||||
|
||||
console.log(objectToEdit);
|
||||
|
||||
return {
|
||||
id: objectToEdit?.id ?? null,
|
||||
content: objectToEdit?.content ?? "",
|
||||
image: objectToEdit?.image ?? "",
|
||||
subject_id: objectToEdit?.subject_id ?? "",
|
||||
canAnswersBeShuffled: objectToEdit?.canAnswersBeShuffled ?? 0,
|
||||
canAnswersBeShuffled: objectToEdit?.canAnswersBeShuffled ? 1 : 0,
|
||||
hint: objectToEdit?.hint ?? "",
|
||||
isBase: 0,
|
||||
parent_id: objectToEdit?.parent_id ?? "",
|
||||
QuestionOptions: objectToEdit?.QuestionOptions ?? [],
|
||||
answers: objectToEdit?.answers ?? [],
|
||||
tags: tags ?? [],
|
||||
};
|
||||
};
|
||||
|
|
@ -26,10 +28,10 @@ export const getValidationSchema = () => {
|
|||
return Yup.object().shape({
|
||||
image: Yup.string().nullable(),
|
||||
content: Yup.string().required("validation.required"),
|
||||
QuestionOptions: Yup.array()
|
||||
answers: Yup.array()
|
||||
.of(
|
||||
Yup.object().shape({
|
||||
answer: Yup.string().required("validation.required"),
|
||||
content: Yup.string().required("validation.required"),
|
||||
answer_image: Yup.string().nullable(),
|
||||
isCorrect: Yup.boolean(),
|
||||
}),
|
||||
|
|
@ -45,10 +47,11 @@ export const getInitialValuesBase = (objectToEdit: Question): any => {
|
|||
name: tag?.name,
|
||||
key: `${tag?.id}_key_${tag?.name}`,
|
||||
}));
|
||||
|
||||
|
||||
return {
|
||||
...item,
|
||||
canAnswersBeShuffled: item?.canAnswersBeShuffled ?? 0,
|
||||
canAnswersBeShuffled: objectToEdit?.canAnswersBeShuffled ? 1 : 0,
|
||||
hint: item?.hint ?? "",
|
||||
tags,
|
||||
};
|
||||
});
|
||||
|
|
@ -62,8 +65,8 @@ export const getInitialValuesBase = (objectToEdit: Question): any => {
|
|||
subject_id: objectToEdit?.subject_id ?? "",
|
||||
isBase: 1,
|
||||
parent_id: objectToEdit?.parent_id ?? "",
|
||||
canAnswersBeShuffled: objectToEdit?.canAnswersBeShuffled ?? 0,
|
||||
|
||||
canAnswersBeShuffled: objectToEdit?.canAnswersBeShuffled ? 1 : 0,
|
||||
hint: objectToEdit?.hint ?? "",
|
||||
Questions: questions,
|
||||
};
|
||||
};
|
||||
|
|
@ -77,10 +80,10 @@ export const getValidationSchemaBase = () => {
|
|||
Yup.object().shape({
|
||||
image: Yup.string().nullable(),
|
||||
content: Yup.string().required("validation.required"),
|
||||
QuestionOptions: Yup.array()
|
||||
answers: Yup.array()
|
||||
.of(
|
||||
Yup.object().shape({
|
||||
answer: Yup.string().required("validation.required"),
|
||||
content: Yup.string().required("validation.required"),
|
||||
answer_image: Yup.string().nullable(),
|
||||
isCorrect: Yup.boolean(),
|
||||
}),
|
||||
|
|
|
|||
|
|
@ -60,12 +60,14 @@ export const useColumns = () => {
|
|||
record?.isBase ? t("practical.yes") : t("practical.no"),
|
||||
},
|
||||
{
|
||||
title: `${t("columns.question_options_count")}`,
|
||||
dataIndex: "name",
|
||||
key: "name",
|
||||
title: t("columns.canAnswersBeShuffled"),
|
||||
dataIndex: "canAnswersBeShuffled",
|
||||
key: "canAnswersBeShuffled",
|
||||
align: "center",
|
||||
render: (text, record) => record?.question_options_count,
|
||||
render: (text, record) =>
|
||||
record?.canAnswersBeShuffled ? t("practical.yes") : t("practical.no"),
|
||||
},
|
||||
|
||||
{
|
||||
title: canAddQuestion ? (
|
||||
<button onClick={() => handelAdd()} className="add_button">
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ export const menuItems: TMenuItem[] = [
|
|||
abilities: ABILITIES_ENUM?.PASS,
|
||||
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
|
||||
prevPath: 0,
|
||||
|
||||
},
|
||||
{
|
||||
header: "page_header.grade",
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
export const BaseURL = "http://192.168.1.111:8000/api/";
|
||||
export const BaseURL = "http://127.0.0.1:8000/api/";
|
||||
// export const BaseURL = "http://127.0.0.1:8000/api/";
|
||||
|
||||
// export const BaseURL = "http://192.168.1.120:8000/api/";
|
||||
|
||||
// export const ImageBaseURL = "http://192.168.1.9:8000/";
|
||||
|
||||
export const ImageBaseURL = "http://192.168.1.111:8000/api/";
|
||||
export const ImageBaseURL = "http://127.0.0.1:8000/api/";
|
||||
export const HEADER_KEY = "X-Custom-Query-Key";
|
||||
|
|
|
|||
5
src/enums/UserType.ts
Normal file
5
src/enums/UserType.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
export enum UserTypeEnum {
|
||||
ADMIN = "ADMIN",
|
||||
RE_SELLER = "RE_SELLER",
|
||||
}
|
||||
|
||||
|
|
@ -6,7 +6,7 @@ function QueryProvider({ children }: any) {
|
|||
defaultOptions: {
|
||||
queries: {
|
||||
refetchOnWindowFocus: false,
|
||||
// staleTime:Infinity
|
||||
staleTime:60
|
||||
},
|
||||
},
|
||||
});
|
||||
|
|
|
|||
|
|
@ -155,6 +155,7 @@
|
|||
"min_mark_to_pass": "علامة النجاح",
|
||||
"isBase": "سؤال رئيسي",
|
||||
"question_options_count": "عدد الخيارات",
|
||||
"canAnswersBeShuffled":"يمكن خلط الإجابات",
|
||||
"price":"السعر",
|
||||
"grade_id":"رقم تعريف الدرجة"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { ReactElement, LazyExoticComponent, ReactNode } from "react";
|
||||
import { Mark_State, Payment_type, term_type } from "./Item";
|
||||
import { ABILITIES_ENUM, ABILITIES_VALUES_ENUM } from "../enums/abilities";
|
||||
import { UserTypeEnum } from "../enums/UserType";
|
||||
|
||||
export type ChildrenType = {
|
||||
children: ReactNode;
|
||||
|
|
@ -14,6 +15,7 @@ type TMenuItemBase = {
|
|||
withOutLayout?: boolean;
|
||||
abilities: ABILITIES_ENUM;
|
||||
abilities_value: ABILITIES_VALUES_ENUM;
|
||||
type?:UserTypeEnum
|
||||
prevPath: number;
|
||||
};
|
||||
|
||||
|
|
@ -37,6 +39,7 @@ export type TCrudRoute = {
|
|||
element: ReactElement | LazyExoticComponent<any>;
|
||||
abilities: ABILITIES_ENUM;
|
||||
abilities_value: ABILITIES_VALUES_ENUM;
|
||||
type?:ABILITIES_ENUM
|
||||
prevPath: number;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -312,7 +312,8 @@ export interface Question {
|
|||
image: string | null;
|
||||
Questions?: any[];
|
||||
question_options_count?: any;
|
||||
QuestionOptions: QuestionOption[];
|
||||
answers: QuestionOption[];
|
||||
hint?:string;
|
||||
tags: tags[]; // Assuming tags are strings, adjust as per actual data type
|
||||
}
|
||||
|
||||
|
|
|
|||
5
src/types/UserType.ts
Normal file
5
src/types/UserType.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import { Nullable } from "./App";
|
||||
|
||||
// Define the Teacher interface
|
||||
|
||||
export type UserType = "admin" | "reSeller"
|
||||
|
|
@ -28,11 +28,14 @@ class AbilityManager {
|
|||
}
|
||||
return new Set(JSON.parse(abilitiesString));
|
||||
}
|
||||
|
||||
public hasAbility(
|
||||
category: ABILITIES_ENUM,
|
||||
value: ABILITIES_VALUES_ENUM,
|
||||
): boolean {
|
||||
// Allow all abilities if the category is PASS
|
||||
|
||||
|
||||
return true;
|
||||
if (category === ABILITIES_ENUM.PASS) {
|
||||
return true;
|
||||
|
|
@ -44,7 +47,7 @@ class AbilityManager {
|
|||
}
|
||||
|
||||
// Construct the ability string
|
||||
const abilityString = `${category}::${value}`;
|
||||
const abilityString = `${category}`;
|
||||
|
||||
// Check if the constructed ability string exists in the abilities set
|
||||
return this.abilities.has(abilityString);
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ export const setLocalStorageBaseQuestions = async (key: string, data: any) => {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (Array.isArray(data.Questions.QuestionOptions)) {
|
||||
for (const option of data.Questions.QuestionOptions) {
|
||||
if (Array.isArray(data.Questions.answers)) {
|
||||
for (const option of data.Questions.answers) {
|
||||
if (option.answer_image instanceof File) {
|
||||
option.answer_image = await convertFileToBase64(option.answer_image);
|
||||
}
|
||||
|
|
@ -50,8 +50,8 @@ export const getLocalStorageBaseQuestions = (key: string): any | null => {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (Array.isArray(data.Questions.QuestionOptions)) {
|
||||
for (const option of data.Questions.QuestionOptions) {
|
||||
if (Array.isArray(data.Questions.answers)) {
|
||||
for (const option of data.Questions.answers) {
|
||||
if (typeof option.answer_image === "string") {
|
||||
option.answer_image = base64StringToFile(option.answer_image);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ export const setLocalStorageQuestions = async (key: string, data: any) => {
|
|||
data.image = await convertFileToBase64(data.image);
|
||||
}
|
||||
|
||||
// Check for QuestionOptions array and convert answer_image if it's a File
|
||||
if (Array.isArray(data.QuestionOptions)) {
|
||||
for (const option of data.QuestionOptions) {
|
||||
// Check for answers array and convert answer_image if it's a File
|
||||
if (Array.isArray(data.answers)) {
|
||||
for (const option of data.answers) {
|
||||
if (option.answer_image instanceof File) {
|
||||
option.answer_image = await convertFileToBase64(option.answer_image);
|
||||
}
|
||||
|
|
@ -23,9 +23,9 @@ export const setLocalStorageQuestions = async (key: string, data: any) => {
|
|||
if (question.image instanceof File) {
|
||||
question.image = await convertFileToBase64(question.image);
|
||||
}
|
||||
// Check for nested QuestionOptions and convert answer_image if it's a File
|
||||
if (Array.isArray(question.QuestionOptions)) {
|
||||
for (const option of question.QuestionOptions) {
|
||||
// Check for nested answers and convert answer_image if it's a File
|
||||
if (Array.isArray(question.answers)) {
|
||||
for (const option of question.answers) {
|
||||
if (option.answer_image instanceof File) {
|
||||
option.answer_image = await convertFileToBase64(
|
||||
option.answer_image,
|
||||
|
|
@ -55,9 +55,9 @@ export const getLocalStorageQuestions = (key: string): any | null => {
|
|||
data.image = base64StringToFile(data.image);
|
||||
}
|
||||
|
||||
// Check for QuestionOptions array and convert answer_image if it's a base64 string
|
||||
if (Array.isArray(data.QuestionOptions)) {
|
||||
for (const option of data.QuestionOptions) {
|
||||
// Check for answers array and convert answer_image if it's a base64 string
|
||||
if (Array.isArray(data.answers)) {
|
||||
for (const option of data.answers) {
|
||||
if (
|
||||
typeof option.answer_image === "string" &&
|
||||
option.answer_image.length > 0
|
||||
|
|
@ -73,9 +73,9 @@ export const getLocalStorageQuestions = (key: string): any | null => {
|
|||
if (typeof question.image === "string" && question.image.length > 0) {
|
||||
question.image = base64StringToFile(question.image);
|
||||
}
|
||||
// Check for nested QuestionOptions and convert answer_image if it's a base64 string
|
||||
if (Array.isArray(question.QuestionOptions)) {
|
||||
for (const option of question.QuestionOptions) {
|
||||
// Check for nested answers and convert answer_image if it's a base64 string
|
||||
if (Array.isArray(question.answers)) {
|
||||
for (const option of question.answers) {
|
||||
if (
|
||||
typeof option.answer_image === "string" &&
|
||||
option.answer_image.length > 0
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user