make fix
This commit is contained in:
parent
ccbebf99a1
commit
865f785112
|
|
@ -1,24 +1,18 @@
|
|||
import { create } from "zustand";
|
||||
|
||||
interface FilterState {
|
||||
filterState: any[];
|
||||
filterState: any;
|
||||
setFilterState: (data: any) => void;
|
||||
clearFilterState: () => void;
|
||||
setWithOldValue: (data: any) => void;
|
||||
setInitialValue: (data: any) => void;
|
||||
}
|
||||
|
||||
export const useFilterState = create<FilterState>((set, get) => ({
|
||||
filterState: [],
|
||||
filterState: {},
|
||||
setFilterState: (data) => set(() => ({ filterState: data })),
|
||||
clearFilterState: () => set(() => ({ filterState: [] })),
|
||||
setWithOldValue: (data) =>
|
||||
set((state) => ({ filterState: [...state.filterState, data] })),
|
||||
setInitialValue: (data) => {
|
||||
if (get().filterState.length < 1) {
|
||||
set(() => ({ filterState: data }));
|
||||
}
|
||||
},
|
||||
}));
|
||||
|
||||
// import { create } from "zustand";
|
||||
|
|
|
|||
|
|
@ -48,8 +48,14 @@ const SearchField = ({
|
|||
}
|
||||
}, [page]);
|
||||
|
||||
const SelectableChange = (value: any) => {
|
||||
formik?.setFieldValue(name, value);
|
||||
const SelectableChange = (value: any,option:any) => {
|
||||
if(isMulti){
|
||||
formik?.setFieldValue(name, option ?? []);
|
||||
}else{
|
||||
|
||||
formik?.setFieldValue(name, option ?? {});
|
||||
}
|
||||
|
||||
const isCleared = value?.length === 0 || !value;
|
||||
|
||||
if (isCleared) {
|
||||
|
|
@ -90,8 +96,8 @@ const SearchField = ({
|
|||
const handleScroll = (event: any) => {
|
||||
const target = event.target;
|
||||
const isAtBottom =
|
||||
target.scrollHeight === target.scrollTop + target.clientHeight;
|
||||
|
||||
target.scrollHeight - 10 <= Math.floor(target.scrollTop + target.clientHeight);
|
||||
|
||||
if (isAtBottom && canChangePage && PageName && page) {
|
||||
console.log("Scrolled to the last option!");
|
||||
let newPage = page + 1;
|
||||
|
|
@ -103,7 +109,11 @@ const SearchField = ({
|
|||
|
||||
console.log(AllPagesOption);
|
||||
console.log(option, "option");
|
||||
|
||||
const value = isMulti ? formik.values[name]?.map((item:any)=>{
|
||||
return item?.name ?? item
|
||||
}) : formik.values[name]?.["name"] ?? ""
|
||||
console.log(value);
|
||||
|
||||
return (
|
||||
<div className="ValidationField w-100">
|
||||
<ValidationFieldLabel
|
||||
|
|
@ -121,8 +131,8 @@ const SearchField = ({
|
|||
options={AllPagesOption}
|
||||
size="large"
|
||||
className={`${className} w-100`}
|
||||
value={formik.values[name]}
|
||||
// loading={isLoading}
|
||||
value={value}
|
||||
loading={isLoading}
|
||||
allowClear
|
||||
{...(isMulti && { mode: "multiple" })}
|
||||
onChange={onChange || SelectableChange}
|
||||
|
|
@ -133,7 +143,7 @@ const SearchField = ({
|
|||
onBlur={handleBlur}
|
||||
id={name}
|
||||
onPopupScroll={handleScroll}
|
||||
fieldNames={{ label: "name", value: "id" }}
|
||||
fieldNames={{ label: "name", value: "name" }}
|
||||
{...props}
|
||||
/>
|
||||
</ValidationFieldContainer>
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import { QueryStatusEnum } from "../../../../enums/QueryStatus";
|
|||
import ModelForm from "./ModelForm";
|
||||
import { useAddCoupon } from "../../../../api/Coupon";
|
||||
import dayjs from "dayjs";
|
||||
import { ConvertArrayToArrayOfIds } from "../../../../utils/ConvertArrayToArrayOfIds";
|
||||
|
||||
const AddModel: React.FC = () => {
|
||||
const { mutate, status } = useAddCoupon();
|
||||
|
|
@ -16,7 +17,10 @@ const AddModel: React.FC = () => {
|
|||
console.log(due_to);
|
||||
mutate({
|
||||
...values,
|
||||
due_to
|
||||
due_to,
|
||||
grade_id:values?.grade_id?.id
|
||||
|
||||
|
||||
});
|
||||
};
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import ModelForm from "./ModelForm";
|
|||
import { QueryStatusEnum } from "../../../../enums/QueryStatus";
|
||||
import { useObjectToEdit } from "../../../../zustand/ObjectToEditState";
|
||||
import { useUpdateCoupon } from "../../../../api/Coupon";
|
||||
import { handelImageState } from "../../../../utils/DataToSendImageState";
|
||||
|
||||
const EditModel: React.FC = () => {
|
||||
const { mutate, status } = useUpdateCoupon();
|
||||
|
|
@ -14,7 +13,7 @@ const EditModel: React.FC = () => {
|
|||
|
||||
const handleSubmit = (values: any) => {
|
||||
const due_to = typeof values?.due_to === "string" ? values?.due_to : values?.due_to.format("YYYY-MM-DD HH:mm:ss")
|
||||
const Data_to_send = { ...values , due_to };
|
||||
const Data_to_send = { ...values , due_to, grade_id:values?.grade_id?.id ?? "" };
|
||||
mutate(Data_to_send);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ const Form = ({Hide = false}:{Hide?:boolean }) => {
|
|||
});
|
||||
const GradeOption = Grade?.data ?? []
|
||||
const canChangeGradePage = !!Grade?.links?.next;
|
||||
const GradePage = Grade?.meta?.currentPage;
|
||||
const GradePage = Grade?.meta?.current_page;
|
||||
return (
|
||||
<Row className="w-100">
|
||||
<Col>
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ export const getInitialValues = (
|
|||
amount: objectToEdit?.amount ?? "",
|
||||
code: objectToEdit?.code ?? "",
|
||||
due_to: objectToEdit?.due_to ? dayjs(objectToEdit?.due_to,"YYYY-MM-DD HH:mm:ss") : "",
|
||||
grade_id: objectToEdit?.grade_id ?? "",
|
||||
grade_id: objectToEdit?.grade ?? "",
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ const AddModel: React.FC = () => {
|
|||
const handleSubmit = (values: any) => {
|
||||
mutate({
|
||||
...values,
|
||||
grade_id:values?.grade_id?.id
|
||||
});
|
||||
};
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ const EditModel: React.FC = () => {
|
|||
const { objectToEdit } = useObjectToEdit((state) => state);
|
||||
|
||||
const handleSubmit = (values: any) => {
|
||||
const Data_to_send = { ...values };
|
||||
const Data_to_send = { ...values, grade_id:values?.grade_id?.id };
|
||||
mutate(Data_to_send);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ const Form = ({ isEdit = false }: { isEdit?: boolean }) => {
|
|||
});
|
||||
const GradeOption = Grade?.data ?? [];
|
||||
const canChangeGradePage = !!Grade?.links?.next;
|
||||
const GradePage = Grade?.meta?.currentPage;
|
||||
const GradePage = Grade?.meta?.current_page;
|
||||
|
||||
const sex = [
|
||||
{ name: "male", id: "male" },
|
||||
|
|
|
|||
|
|
@ -30,8 +30,9 @@ const FilterForm = () => {
|
|||
});
|
||||
const GradeOption = Grade?.data ?? []
|
||||
const canChangeGradePage = !!Grade?.links?.next;
|
||||
const GradePage = Grade?.meta?.currentPage;
|
||||
|
||||
const GradePage = Grade?.meta?.current_page;
|
||||
console.log(Grade?.meta?.current_page);
|
||||
|
||||
|
||||
/// subject_id
|
||||
const { data: Subject, isLoading: isLoadingSubject } = useGetAllSubject({
|
||||
|
|
@ -40,7 +41,7 @@ const FilterForm = () => {
|
|||
});
|
||||
const SubjectOption = Subject?.data ?? []
|
||||
const canChangeSubjectPage = !!Subject?.links?.next;
|
||||
const SubjectPage = Subject?.meta?.currentPage;
|
||||
const SubjectPage = Subject?.meta?.current_page;
|
||||
|
||||
/// unit_id
|
||||
const { data: Unit, isLoading: isLoadingUnit } = useGetAllUnit({
|
||||
|
|
@ -49,7 +50,7 @@ const FilterForm = () => {
|
|||
});
|
||||
const UnitOption = Unit?.data ?? []
|
||||
const canChangeUnitPage = !!Unit?.links?.next;
|
||||
const UnitPage = Unit?.meta?.currentPage;
|
||||
const UnitPage = Unit?.meta?.current_page;
|
||||
|
||||
/// lessonsIds
|
||||
const { data: Lesson, isLoading: isLoadingLesson } = useGetAllLesson({
|
||||
|
|
@ -58,7 +59,7 @@ const FilterForm = () => {
|
|||
});
|
||||
const LessonOption = Lesson?.data ?? []
|
||||
const canChangeLessonPage = !!Lesson?.links?.next;
|
||||
const LessonPage = Lesson?.meta?.currentPage;
|
||||
const LessonPage = Lesson?.meta?.current_page;
|
||||
|
||||
|
||||
/// TagsIds
|
||||
|
|
@ -68,7 +69,7 @@ const FilterForm = () => {
|
|||
});
|
||||
const TagOption = Tag?.data ?? []
|
||||
const canChangeTagPage = !!Tag?.links?.next;
|
||||
const TagPage = Tag?.meta?.currentPage;
|
||||
const TagPage = Tag?.meta?.current_page;
|
||||
|
||||
|
||||
return (
|
||||
|
|
@ -88,6 +89,7 @@ const FilterForm = () => {
|
|||
canChangePage={canChangeGradePage}
|
||||
PageName={"GradeCurrentPage"}
|
||||
page={GradePage}
|
||||
|
||||
|
||||
/>
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import { useDeleteQuestion } from "../../../api/Question";
|
|||
import PageHeader from "../../../Layout/Dashboard/PageHeader";
|
||||
import FilterLayout from "../../../Layout/Dashboard/FilterLayout";
|
||||
import FilterForm from "./Model/FilterForm";
|
||||
import { canAddQuestionBank } from "../../../utils/hasAbilityFn";
|
||||
|
||||
const Table = lazy(() => import("./Table"));
|
||||
const DeleteModalForm = lazy(
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import { useGetAllQuestion } from "../../../api/Question";
|
|||
import { useFilterState } from "../../../Components/Utils/Filter/FilterState";
|
||||
import { useObjectToEdit } from "../../../zustand/ObjectToEditState";
|
||||
import { useFilterStateState } from "../../../zustand/Filter";
|
||||
import { ConvertArrayToArrayOfIds } from "../../../utils/ConvertArrayToArrayOfIds";
|
||||
|
||||
const App: React.FC = () => {
|
||||
const { filterState } = useFilterState();
|
||||
|
|
@ -17,6 +18,11 @@ const App: React.FC = () => {
|
|||
nullable_parent:"null",
|
||||
pagination: true,
|
||||
...filterState,
|
||||
tagsIds:ConvertArrayToArrayOfIds(filterState?.tagsIds) ,
|
||||
grade_id:filterState?.grade_id?.id,
|
||||
subject_id:filterState?.subject_id?.id,
|
||||
unit_id:filterState?.unit_id?.id,
|
||||
lessonsIds:ConvertArrayToArrayOfIds(filterState?.lessonsIds),
|
||||
content:Filter?.content,
|
||||
sort_by,
|
||||
|
||||
|
|
|
|||
|
|
@ -69,19 +69,66 @@ export const useColumns = () => {
|
|||
},
|
||||
ellipsis: true,
|
||||
},
|
||||
|
||||
{
|
||||
title: `${t("columns.hint")}`,
|
||||
dataIndex: "hint",
|
||||
key: "hint",
|
||||
title: `${t("columns.subject")}`,
|
||||
dataIndex: "lessons",
|
||||
key: "lessons",
|
||||
align: "center",
|
||||
render: (text, record) => {
|
||||
const lesson = record?.lessons?.[0] ;
|
||||
const unit = lesson?.unit;
|
||||
const subject = unit?.subject;
|
||||
|
||||
return (
|
||||
<>{record?.hint ?? "_"}</>
|
||||
);
|
||||
<> {subject?.name} </>
|
||||
)
|
||||
},
|
||||
ellipsis: true,
|
||||
},
|
||||
{
|
||||
title: `${t("columns.unit")}`,
|
||||
dataIndex: "lessons",
|
||||
key: "lessons",
|
||||
align: "center",
|
||||
render: (text, record) => {
|
||||
const lesson = record?.lessons?.[0] ;
|
||||
const unit = lesson?.unit;
|
||||
return (
|
||||
<> {unit?.name} </>
|
||||
)
|
||||
},
|
||||
ellipsis: true,
|
||||
},
|
||||
|
||||
{
|
||||
title: `${t("columns.lesson")}`,
|
||||
dataIndex: "lessons",
|
||||
key: "lessons",
|
||||
align: "center",
|
||||
render: (text, record) => {
|
||||
const lesson = record?.lessons?.[0] ;
|
||||
console.log(lesson,"lesson");
|
||||
|
||||
return (
|
||||
<> {lesson?.name} </>
|
||||
)
|
||||
},
|
||||
ellipsis: true,
|
||||
},
|
||||
|
||||
|
||||
// {
|
||||
// title: `${t("columns.hint")}`,
|
||||
// dataIndex: "hint",
|
||||
// key: "hint",
|
||||
// align: "center",
|
||||
// render: (text, record) => {
|
||||
// return (
|
||||
// <>{record?.hint ?? "_"}</>
|
||||
// );
|
||||
// },
|
||||
// ellipsis: true,
|
||||
// },
|
||||
{
|
||||
title: `${t("columns.tags")}`,
|
||||
dataIndex: "tags",
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ const Form = ({ isEdit = false }: { isEdit?: boolean }) => {
|
|||
});
|
||||
const GradeOption = Grade?.data ?? [];
|
||||
const canChangeGradePage = !!Grade?.links?.next;
|
||||
const GradePage = Grade?.meta?.currentPage;
|
||||
const GradePage = Grade?.meta?.current_page;
|
||||
|
||||
const sex = [
|
||||
{ name: "male", id: "male" },
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ const App: React.FC = () => {
|
|||
sort_by,
|
||||
pagination: true,
|
||||
...filterState,
|
||||
grade_id:filterState?.grade_id?.id,
|
||||
});
|
||||
|
||||
return <DataTable response={response} useColumns={useColumns} />;
|
||||
|
|
|
|||
|
|
@ -9,10 +9,7 @@ import { useObjectToEdit } from "../../../zustand/ObjectToEditState";
|
|||
import { Question } from "../../../types/Item";
|
||||
import BaseFormContainer from "./Model/AddForm/BaseForm";
|
||||
import FormContainer from "./Model/AddForm/Form";
|
||||
import { handleValidateBaseQuestion, handleValidateSingleQuestion } from "./Model/AddForm/ValidationFn";
|
||||
import useUnsavedChangesWarning from "../../../Hooks/useUnsavedChangesWarning";
|
||||
import { useFormikContext } from "formik";
|
||||
|
||||
import { handleValidateBaseQuestion, handleValidateSingleQuestion } from "./Model/ValidationFn";
|
||||
const AddPage: React.FC = () => {
|
||||
|
||||
const { mutateAsync, isLoading: LoadingAsync } = useAddQuestionAsync();
|
||||
|
|
|
|||
|
|
@ -19,28 +19,30 @@ import { toast } from "react-toastify";
|
|||
import { deletePathSegments } from "../../../utils/deletePathSegments";
|
||||
import BaseFormContainer from "./Model/EditForm/BaseFormContainer";
|
||||
import FormContainer from "./Model/EditForm/FormContainer";
|
||||
import { handleValidateBaseQuestion, handleValidateSingleQuestion } from "./Model/ValidationFn";
|
||||
|
||||
const EditPage: React.FC = () => {
|
||||
const { subject_id, lesson_id, question_id } = useParams<ParamsEnum>();
|
||||
const { isBseQuestion, setIsBseQuestion, setTagsSearch, DeletedQuestions, ShowHint, setShowHint, ShowLatexOption, setShowLatexOption } =
|
||||
const { isBseQuestion, setIsBseQuestion, setTagsSearch, DeletedQuestions,setObjectToEdit } =
|
||||
useObjectToEdit();
|
||||
|
||||
const { mutate, isSuccess, isLoading } = useUpdateQuestion();
|
||||
const { mutate, isSuccess ,isLoading:isLoadingUpdate } = useUpdateQuestion();
|
||||
const { mutate: DeleteQuestion } = useDeleteQuestion();
|
||||
const { mutate: mutateAdd, isLoading: LoadingAsync } = useAddQuestion();
|
||||
const { mutate: mutateAdd } = useAddQuestion();
|
||||
|
||||
const { data, isLoading: dataLoading } = useGetAllQuestion({
|
||||
const { data, isLoading: dataLoading ,isRefetching } = useGetAllQuestion({
|
||||
show: question_id,
|
||||
});
|
||||
|
||||
const { data: Questions, isLoading: QuestionsDataLoading } =
|
||||
const { data: Questions, isLoading: QuestionsDataLoading,isRefetching:isRefetchingParent } =
|
||||
useGetAllQuestion({
|
||||
parent_id: question_id,
|
||||
isPaginated: false
|
||||
});
|
||||
|
||||
const objectToEdit = { ...data?.data, Questions: Questions?.data };
|
||||
|
||||
console.log(objectToEdit);
|
||||
|
||||
useEffect(() => {
|
||||
if (objectToEdit?.isBase && isBseQuestion !== true) {
|
||||
setIsBseQuestion(true);
|
||||
|
|
@ -175,136 +177,39 @@ const EditPage: React.FC = () => {
|
|||
}
|
||||
};
|
||||
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const handleValidateSingleQuestion = (values: any, isValid: boolean, handleSubmit: 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"));
|
||||
return false;
|
||||
}
|
||||
if (!haveOneAnswerRight) {
|
||||
toast.error(t("validation.it_should_have_more_than_one_correct_answers"));
|
||||
return false;
|
||||
}
|
||||
if (haveImageOrContent) {
|
||||
toast.error(t("validation.one_of_image_and_content_should_be_enter_in_answer"))
|
||||
return false
|
||||
}
|
||||
|
||||
console.log(1);
|
||||
|
||||
if (isValid) {
|
||||
handleSubmit(values)
|
||||
}
|
||||
|
||||
}
|
||||
const handleValidateBaseQuestion = (values: any, isValid: boolean, handleSubmit: any) => {
|
||||
const content = values.content;
|
||||
const content_image = values.content_image;
|
||||
const haveContentOrContentImage = !!content || !!content_image;
|
||||
console.log(2);
|
||||
|
||||
if (!haveContentOrContentImage) {
|
||||
toast.error(`${t("validation.one_of_image_and_content_should_be_enter_in_question")}`);
|
||||
return false;
|
||||
}
|
||||
console.log(1);
|
||||
|
||||
const isValidate = 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;
|
||||
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))
|
||||
|
||||
|
||||
|
||||
|
||||
if (!haveAnswers) {
|
||||
toast.error(t("validation.it_should_have_more_than_one_answers"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!haveMoreThanOneAnswer) {
|
||||
toast.error(t("validation.it_should_have_more_than_one_answers"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!haveOneAnswerRight) {
|
||||
toast.error(t("validation.it_should_have_more_than_one_correct_answers"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (haveImageOrContent) {
|
||||
toast.error(t("validation.one_of_image_and_content_should_be_enter_in_answer"))
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
});
|
||||
|
||||
console.log(1);
|
||||
|
||||
if (isValid && isValidate) {
|
||||
console.log(2);
|
||||
handleSubmit(values)
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
console.log(location.pathname);
|
||||
console.log(deletePathSegments(location.pathname, 2));
|
||||
|
||||
if (isSuccess) {
|
||||
toast.success(t("validation.the_possess_done_successful"));
|
||||
// toast.success(t("validation.the_possess_done_successful"));
|
||||
setObjectToEdit(null)
|
||||
navigate(-1);
|
||||
|
||||
}
|
||||
}, [isSuccess]);
|
||||
|
||||
|
||||
|
||||
|
||||
const Loading = LoadingAsync || isLoading
|
||||
|
||||
if (dataLoading || QuestionsDataLoading) {
|
||||
console.log(objectToEdit);
|
||||
|
||||
|
||||
const Loading = QuestionsDataLoading || dataLoading || isRefetchingParent || isRefetching
|
||||
console.log(Loading);
|
||||
const LoadingButton = isLoadingUpdate
|
||||
if (Loading) {
|
||||
return <SpinContainer />;
|
||||
}
|
||||
if (objectToEdit?.isBase) {
|
||||
return (
|
||||
<BaseFormContainer t={t} Loading={Loading} handleSubmit={handleSubmit} handleValidateBaseQuestion={handleValidateBaseQuestion} objectToEdit={objectToEdit} />
|
||||
<BaseFormContainer t={t} Loading={LoadingButton} handleSubmit={handleSubmit} handleValidateBaseQuestion={handleValidateBaseQuestion} objectToEdit={objectToEdit} />
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<FormContainer t={t} Loading={Loading} handleSubmit={handleSubmit} handleValidateSingleQuestion={handleValidateSingleQuestion} objectToEdit={objectToEdit} />
|
||||
<FormContainer t={t} Loading={LoadingButton} handleSubmit={handleSubmit} handleValidateSingleQuestion={handleValidateSingleQuestion} objectToEdit={objectToEdit} />
|
||||
);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ const FilterForm = () => {
|
|||
});
|
||||
const GradeOption = Grade?.data ?? []
|
||||
const canChangeGradePage = !!Grade?.links?.next;
|
||||
const GradePage = Grade?.meta?.currentPage;
|
||||
const GradePage = Grade?.meta?.current_page;
|
||||
|
||||
|
||||
/// subject_id
|
||||
|
|
@ -38,7 +38,7 @@ const FilterForm = () => {
|
|||
});
|
||||
const SubjectOption = Subject?.data ?? []
|
||||
const canChangeSubjectPage = !!Subject?.links?.next;
|
||||
const SubjectPage = Subject?.meta?.currentPage;
|
||||
const SubjectPage = Subject?.meta?.current_page;
|
||||
|
||||
/// unit_id
|
||||
const { data: Unit, isLoading: isLoadingUnit } = useGetAllUnit({
|
||||
|
|
@ -47,7 +47,7 @@ const FilterForm = () => {
|
|||
});
|
||||
const UnitOption = Unit?.data ?? []
|
||||
const canChangeUnitPage = !!Unit?.links?.next;
|
||||
const UnitPage = Unit?.meta?.currentPage;
|
||||
const UnitPage = Unit?.meta?.current_page;
|
||||
|
||||
/// lessonsIds
|
||||
const { data: Lesson, isLoading: isLoadingLesson } = useGetAllLesson({
|
||||
|
|
@ -56,7 +56,7 @@ const FilterForm = () => {
|
|||
});
|
||||
const LessonOption = Lesson?.data ?? []
|
||||
const canChangeLessonPage = !!Lesson?.links?.next;
|
||||
const LessonPage = Lesson?.meta?.currentPage;
|
||||
const LessonPage = Lesson?.meta?.current_page;
|
||||
|
||||
return (
|
||||
<div>
|
||||
|
|
|
|||
|
|
@ -13,9 +13,10 @@ import ModelForm from "../../Model/Malty/Form";
|
|||
const BaseFormContainer = ({objectToEdit,handleSubmit,Loading,handleValidateBaseQuestion,t}:{objectToEdit:any,handleSubmit:any,Loading:any,handleValidateBaseQuestion:any,t:any}) => {
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
const { ShowHint,setShowHint , ShowLatexOption,setShowLatexOption } =
|
||||
const { ShowHint,setShowHint , ShowLatexOption,setShowLatexOption ,setObjectToEdit} =
|
||||
useObjectToEdit();
|
||||
const handleCancel = () => {
|
||||
setObjectToEdit({})
|
||||
navigate(-1);
|
||||
};
|
||||
const handleNavigateToPage = () => {
|
||||
|
|
@ -84,8 +85,8 @@ const BaseFormContainer = ({objectToEdit,handleSubmit,Loading,handleValidateBase
|
|||
<div className="exercise_add_buttons">
|
||||
<div onClick={handleCancel}>{t("practical.back")}</div>
|
||||
<button disabled={Loading} className={`relative ${dirty ? "" : "disabled"}`} type="button"
|
||||
onClick={()=>{handleValidateBaseQuestion(values,isValid,handleSubmit) }}
|
||||
onSubmit={()=>{handleValidateBaseQuestion(values,isValid,handleSubmit) }}
|
||||
onClick={()=>{handleValidateBaseQuestion(values,isValid,handleSubmit,t) }}
|
||||
onSubmit={()=>{handleValidateBaseQuestion(values,isValid,handleSubmit,t) }}
|
||||
> {t("practical.edit")}
|
||||
|
||||
{Loading && (
|
||||
|
|
|
|||
|
|
@ -13,13 +13,15 @@ import ModelForm from "../../Model/ModelForm";
|
|||
const FormContainer = ({objectToEdit,handleSubmit,Loading,handleValidateSingleQuestion,t}:{objectToEdit:any,handleSubmit:any,Loading:any,handleValidateSingleQuestion:any,t:any}) => {
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
const { ShowHint,setShowHint , ShowLatexOption,setShowLatexOption } =
|
||||
const { ShowHint,setShowHint , ShowLatexOption,setShowLatexOption,setObjectToEdit } =
|
||||
useObjectToEdit();
|
||||
const handleCancel = () => {
|
||||
setObjectToEdit({})
|
||||
navigate(-1);
|
||||
};
|
||||
const handleNavigateToPage = () => {
|
||||
const cleanedUrl = location.pathname.replace(/\/Question\/\d+$/, "");
|
||||
setObjectToEdit({})
|
||||
navigate(cleanedUrl);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,100 +0,0 @@
|
|||
import { toast } from "react-toastify";
|
||||
|
||||
export const handleValidateSingleQuestion = (values:any,isValid:boolean,handleSubmit:any,t: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")) ;
|
||||
return false ;
|
||||
}
|
||||
if(!haveOneAnswerRight){
|
||||
toast.error(t("validation.it_should_have_more_than_one_correct_answers")) ;
|
||||
return false ;
|
||||
}
|
||||
if(haveImageOrContent){
|
||||
toast.error(t("validation.one_of_image_and_content_should_be_enter_in_answer"))
|
||||
return false
|
||||
}
|
||||
|
||||
console.log(1);
|
||||
|
||||
if(isValid){
|
||||
handleSubmit(values)
|
||||
}
|
||||
|
||||
}
|
||||
export const handleValidateBaseQuestion = (values: any,isValid:boolean,handleSubmit:any,t:any) => {
|
||||
const content = values.content ;
|
||||
const content_image = values.content_image ;
|
||||
const haveContentOrContentImage = !!content || !!content_image ;
|
||||
console.log(2);
|
||||
|
||||
if(!haveContentOrContentImage){
|
||||
toast.error(`${t("validation.one_of_image_and_content_should_be_enter_in_question")}`);
|
||||
return false;
|
||||
}
|
||||
console.log(1);
|
||||
|
||||
const isValidate = 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;
|
||||
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) )
|
||||
|
||||
|
||||
|
||||
|
||||
if (!haveAnswers) {
|
||||
toast.error(t("validation.it_should_have_more_than_one_answers"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!haveMoreThanOneAnswer) {
|
||||
toast.error(t("validation.it_should_have_more_than_one_answers"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!haveOneAnswerRight) {
|
||||
toast.error(t("validation.it_should_have_more_than_one_correct_answers"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if(haveImageOrContent){
|
||||
toast.error(t("validation.one_of_image_and_content_should_be_enter_in_answer"))
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
});
|
||||
|
||||
console.log(1);
|
||||
|
||||
if(isValid && isValidate){
|
||||
console.log(2);
|
||||
handleSubmit(values)
|
||||
}
|
||||
|
||||
};
|
||||
|
|
@ -1,9 +1,13 @@
|
|||
import { toast } from "react-toastify";
|
||||
import { hasDuplicateArrayValue } from "../../../../utils/hasDuplicateArrayValue";
|
||||
|
||||
export const handleValidateSingleQuestion = (values:any,isValid:boolean,handleSubmit:any,t: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 haveDuplicatedContent = hasDuplicateArrayValue(values?.answers,"content")
|
||||
|
||||
const content = values.content ;
|
||||
const content_image = values.content_image ;
|
||||
const haveContentOrContentImage = !!content || !!content_image ;
|
||||
|
|
@ -25,8 +29,11 @@ export const handleValidateSingleQuestion = (values:any,isValid:boolean,handleSu
|
|||
toast.error(t("validation.one_of_image_and_content_should_be_enter_in_answer"))
|
||||
return false
|
||||
}
|
||||
if(haveDuplicatedContent){
|
||||
toast.error(t("validation.haveDuplicatedContent"))
|
||||
return false
|
||||
}
|
||||
|
||||
console.log(1);
|
||||
|
||||
if(isValid){
|
||||
handleSubmit(values)
|
||||
|
|
@ -37,12 +44,18 @@ export const handleValidateBaseQuestion = (values: any,isValid:boolean,handleSub
|
|||
const content = values.content ;
|
||||
const content_image = values.content_image ;
|
||||
const haveContentOrContentImage = !!content || !!content_image ;
|
||||
console.log(2);
|
||||
|
||||
const haveDuplicatedContent = hasDuplicateArrayValue(values?.Questions,"content")
|
||||
|
||||
if(!haveContentOrContentImage){
|
||||
toast.error(`${t("validation.one_of_image_and_content_should_be_enter_in_question")}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(haveDuplicatedContent){
|
||||
toast.error(t("validation.haveDuplicatedContent"))
|
||||
return false
|
||||
}
|
||||
|
||||
console.log(1);
|
||||
|
||||
const isValidate = values?.Questions?.every((Question: any, QuestionsIndex: number) => {
|
||||
|
|
@ -51,6 +64,7 @@ export const handleValidateBaseQuestion = (values: any,isValid:boolean,handleSub
|
|||
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;
|
||||
|
|
@ -63,7 +77,10 @@ export const handleValidateBaseQuestion = (values: any,isValid:boolean,handleSub
|
|||
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) )
|
||||
const haveDuplicatedContent = hasDuplicateArrayValue(answers,"content")
|
||||
console.log(haveDuplicatedContent);
|
||||
|
||||
console.log(answers);
|
||||
|
||||
|
||||
|
||||
|
|
@ -87,6 +104,11 @@ export const handleValidateBaseQuestion = (values: any,isValid:boolean,handleSub
|
|||
return false
|
||||
}
|
||||
|
||||
if(haveDuplicatedContent){
|
||||
toast.error(t("validation.haveDuplicatedContent"))
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
});
|
||||
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import { useTranslation } from "react-i18next";
|
||||
import { lazy, Suspense } from "react";
|
||||
import { lazy, Suspense, useEffect } from "react";
|
||||
import { Spin } from "antd";
|
||||
import { useParams } from "react-router-dom";
|
||||
import { ParamsEnum } from "../../../enums/params";
|
||||
|
|
@ -16,6 +16,7 @@ import { ABILITIES_ENUM } from "../../../enums/abilities";
|
|||
import { canAddQuestion } from "../../../utils/hasAbilityFn";
|
||||
import FilterLayout from "../../../Layout/Dashboard/FilterLayout";
|
||||
import FilterForm from "./FilterForm";
|
||||
import { useObjectToEdit } from "../../../zustand/ObjectToEditState";
|
||||
const Table = lazy(() => import("./Table"));
|
||||
|
||||
const TableHeader = () => {
|
||||
|
|
@ -50,7 +51,15 @@ const TableHeader = () => {
|
|||
{name:unitName, path:`unit/${unit_id}`},
|
||||
{name:LessonName, path:`lesson/${lesson_id }`}
|
||||
]);
|
||||
const { objectToEdit,setObjectToEdit } =
|
||||
useObjectToEdit();
|
||||
|
||||
useEffect(() => {
|
||||
if(objectToEdit){
|
||||
setObjectToEdit(null)
|
||||
}
|
||||
}, [])
|
||||
console.log(objectToEdit);
|
||||
|
||||
return (
|
||||
<div className="TableWithHeader">
|
||||
|
|
|
|||
|
|
@ -1,8 +1,13 @@
|
|||
import { HaveDuplicatedArrayValue } from "../../utils/hasDuplicateArrayValue";
|
||||
|
||||
const Dummy = () => {
|
||||
const isDuplicated = HaveDuplicatedArrayValue([{name:"name"},{name:"name3"},{name:"nam"}],"name")
|
||||
console.log(isDuplicated,"isDuplicated");
|
||||
|
||||
return (
|
||||
<div className="DummyHomePage">
|
||||
karim is op
|
||||
<div>asd</div>
|
||||
<div> asd </div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import DataTable from "../../../../Layout/Dashboard/Table/DataTable";
|
|||
import { useColumns } from "./useTableColumns";
|
||||
import useSearchQuery from "../../../../api/utils/useSearchQuery";
|
||||
import { useFilterState } from "../../../../Components/Utils/Filter/FilterState";
|
||||
import { useGetCollection } from "../../../../api/collections";
|
||||
import { useGetAllCollections } from "../../../../api/collections";
|
||||
import { useParams } from "react-router-dom";
|
||||
|
||||
const App: React.FC = () => {
|
||||
|
|
@ -12,7 +12,7 @@ const App: React.FC = () => {
|
|||
const {collection_id}= useParams()
|
||||
console.log(collection_id);
|
||||
|
||||
const response = useGetCollection({
|
||||
const response = useGetAllCollections({
|
||||
name: searchQuery,
|
||||
pagination: true,
|
||||
...filterState,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
.DataTable {
|
||||
width: 100%;
|
||||
border-radius: 0 0 10px 10px;
|
||||
box-shadow: 0px 0px 32px 2px #080F3414;
|
||||
// box-shadow: 0px 0px 32px 2px #080F3414;
|
||||
|
||||
}
|
||||
|
||||
.ant-table-cell {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
.exercise_form_container {
|
||||
display: flex;
|
||||
width: 100% !important;
|
||||
padding-top: 10px;
|
||||
padding-block: 10px 30px;
|
||||
box-shadow: 0px 1px 4px 0px rgba(0, 0, 0, 0.1);
|
||||
margin-right: 0px !important;
|
||||
border-radius: 0 0 10px 10px;
|
||||
|
|
@ -48,6 +48,7 @@
|
|||
// max-height: 84vh;
|
||||
overflow-y: scroll;
|
||||
@include Scrollbar();
|
||||
overflow-x: hidden;
|
||||
}
|
||||
.exercise_add_buttons {
|
||||
display: flex;
|
||||
|
|
@ -59,15 +60,15 @@
|
|||
outline: none;
|
||||
border: none;
|
||||
border-radius: 10px;
|
||||
padding: 0.4vw 0.2vw;
|
||||
padding: 5px 10px;
|
||||
background: var(--primary);
|
||||
color: var(--white);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 5px;
|
||||
font-size: 1vw;
|
||||
width: 10vw;
|
||||
font-size: 16px;
|
||||
min-width: 130px;
|
||||
cursor: pointer;
|
||||
transition: .5s ease-in-out;
|
||||
&:hover{
|
||||
|
|
|
|||
|
|
@ -55,7 +55,8 @@
|
|||
"one_of_image_and_content_should_be_enter_in_answer":"يجب إدخال صورة أو محتوى واحد على الأقل في الاجابة",
|
||||
"one_of_image_and_content_should_be_enter_in_question":"يجب إدخال صورة أو محتوى واحد على الأقل في السؤال",
|
||||
"that_is_not_a_valid_mml":"هذا ليس mml صالح",
|
||||
"Are_you_sure_you_want_to_leave_Your_changes_may_not_be_saved":"هل أنت متأكد من أنك تريد المغادرة ؟ قد لا يتم حفظ التغييرات التي أجريتها"
|
||||
"Are_you_sure_you_want_to_leave_Your_changes_may_not_be_saved":"هل أنت متأكد من أنك تريد المغادرة ؟ قد لا يتم حفظ التغييرات التي أجريتها",
|
||||
"haveDuplicatedContent":"يحتوي عل محتوي مكرر"
|
||||
},
|
||||
"header": {
|
||||
"register_students": "تسجيل الطلاب",
|
||||
|
|
@ -237,7 +238,9 @@
|
|||
"read":"قراءة",
|
||||
"managers":"مدراء",
|
||||
"show":"عرض",
|
||||
"paid_price":"المبلغ المدفوع"
|
||||
"paid_price":"المبلغ المدفوع",
|
||||
"unit":"الوحدة",
|
||||
"lesson":"الدرس"
|
||||
},
|
||||
"practical": {
|
||||
"to_confirm_deletion_please_re_enter": "لتأكيد الحذف، يرجى إعادة الإدخال",
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ export interface InitialValues {
|
|||
amount: string; // URL of the user's amount
|
||||
due_to: any; // URL of the user's amount
|
||||
code: string; // URL of the user's amount
|
||||
grade_id: string; // URL of the user's amount
|
||||
grade_id: any; // URL of the user's amount
|
||||
}
|
||||
export type Coupon = {
|
||||
id: number; // Unique identifier for the user
|
||||
|
|
@ -16,6 +16,6 @@ export type Coupon = {
|
|||
amount: string; // URL of the user's amount
|
||||
due_to: string; // URL of the user's amount
|
||||
code: string; // URL of the user's amount
|
||||
grade_id: string; // URL of the user's amount
|
||||
grade: string; // URL of the user's amount
|
||||
};
|
||||
export type CouponInitialValues = Partial<Nullable<InitialValues>>;
|
||||
|
|
|
|||
8
src/utils/ConvertArrayToArrayOfIds.ts
Normal file
8
src/utils/ConvertArrayToArrayOfIds.ts
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
export const ConvertArrayToArrayOfIds = (data:any[])=>{
|
||||
if(data?.length < 1){
|
||||
return []
|
||||
}
|
||||
return data?.map((item:any)=>{
|
||||
return item?.id ?? item
|
||||
})
|
||||
}
|
||||
22
src/utils/hasDuplicateArrayValue.ts
Normal file
22
src/utils/hasDuplicateArrayValue.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
|
||||
export const hasDuplicateArrayValue = <T>(data: T[], key: keyof T): boolean => {
|
||||
console.log(data);
|
||||
|
||||
if (data.length < 1) {
|
||||
return false; // Early return for empty array
|
||||
}
|
||||
|
||||
const hashMap = new Map<any, boolean>(); // Using 'any' type for flexibility
|
||||
|
||||
for (const item of data) {
|
||||
const value = item[key]; // Accessing the value using the key
|
||||
|
||||
if (hashMap.has(value)) {
|
||||
return true; // Duplicate found
|
||||
} else {
|
||||
hashMap.set(value, true); // Store the value as a key in the map
|
||||
}
|
||||
}
|
||||
|
||||
return false; // No duplicates found
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user