diff --git a/src/features/Classes/ClassesPage/index.jsx b/src/features/Classes/ClassesPage/index.jsx
index e180a1a0..e8e4d7c9 100644
--- a/src/features/Classes/ClassesPage/index.jsx
+++ b/src/features/Classes/ClassesPage/index.jsx
@@ -25,28 +25,18 @@ const ClassesPage = () => {
useEffect(() => {
if (Object.keys(selectedInstitution).length > 0) {
if (queryNotInstructors === 'null' && !resetFiltersRef.current) {
- dispatch(fetchClassesData(selectedInstitution.id, initialPage, '', instructorsNull));
+ dispatch(fetchClassesData(selectedInstitution.id, currentPage, '', instructorsNull));
} else if (queryNotInstructors === 'null' && resetFiltersRef.current) {
- dispatch(fetchClassesData(selectedInstitution.id, initialPage, '', stateClasses.filters));
+ dispatch(fetchClassesData(selectedInstitution.id, currentPage, '', stateClasses.filters));
} else {
- dispatch(fetchClassesData(selectedInstitution.id, initialPage, '', stateClasses.filters));
+ dispatch(fetchClassesData(selectedInstitution.id, currentPage, '', stateClasses.filters));
}
}
return () => {
dispatch(resetClassesTable());
};
- }, [selectedInstitution, dispatch]); // eslint-disable-line react-hooks/exhaustive-deps
-
- useEffect(() => {
- if (queryNotInstructors === 'null' && !resetFiltersRef.current) {
- dispatch(fetchClassesData(selectedInstitution.id, currentPage, '', instructorsNull));
- } else if (queryNotInstructors === 'null' && resetFiltersRef.current) {
- dispatch(fetchClassesData(selectedInstitution.id, currentPage, '', stateClasses.filters));
- } else {
- dispatch(fetchClassesData(selectedInstitution.id, currentPage, '', stateClasses.filters));
- }
- }, [currentPage]); // eslint-disable-line react-hooks/exhaustive-deps
+ }, [selectedInstitution, dispatch, currentPage]); // eslint-disable-line react-hooks/exhaustive-deps
const handlePagination = (targetPage) => {
setCurrentPage(targetPage);
diff --git a/src/features/Courses/CoursesDetailPage/__test__/index.test.jsx b/src/features/Courses/CoursesDetailPage/__test__/index.test.jsx
index 5b78aae9..5169b7ef 100644
--- a/src/features/Courses/CoursesDetailPage/__test__/index.test.jsx
+++ b/src/features/Courses/CoursesDetailPage/__test__/index.test.jsx
@@ -51,6 +51,22 @@ const mockStore = {
num_pages: 1,
current_page: 1,
},
+ selectOptions: [
+ {
+ masterCourseName: 'Demo Course 1',
+ numberOfClasses: 3,
+ missingClassesForInstructor: 0,
+ numberOfStudents: 3,
+ numberOfPendingStudents: 0,
+ },
+ {
+ masterCourseName: 'Demo Course 2',
+ numberOfClasses: 3,
+ missingClassesForInstructor: 0,
+ numberOfStudents: 3,
+ numberOfPendingStudents: 0,
+ },
+ ],
},
classes: {
table: {
diff --git a/src/features/Courses/CoursesDetailPage/index.jsx b/src/features/Courses/CoursesDetailPage/index.jsx
index 460a649b..f44b0119 100644
--- a/src/features/Courses/CoursesDetailPage/index.jsx
+++ b/src/features/Courses/CoursesDetailPage/index.jsx
@@ -12,7 +12,7 @@ import LinkWithQuery from 'features/Main/LinkWithQuery';
import CourseDetailTable from 'features/Courses/CourseDetailTable';
import { fetchClassesData } from 'features/Classes/data/thunks';
-import { fetchCoursesData } from 'features/Courses/data/thunks';
+import { fetchCoursesOptionsData } from 'features/Courses/data/thunks';
import { fetchClassesDataSuccess, updateCurrentPage as updateClassesCurrentPage } from 'features/Classes/data/slice';
import { fetchCoursesDataSuccess, updateCurrentPage } from 'features/Courses/data/slice';
@@ -38,22 +38,13 @@ const CoursesDetailPage = () => {
numberOfPendingStudents: '-',
masterCourseId: '-',
}), []);
-
- const courseInfo = useSelector((state) => state.courses.table.data)
+ const institution = useSelector((state) => state.main.selectedInstitution);
+ const courseInfo = useSelector((state) => state.courses.selectOptions)
.find((course) => course?.masterCourseId === courseIdDecoded) || defaultCourseInfo;
- const lastCourseInfoRef = useRef(courseInfo);
-
- useEffect(() => {
- if (courseInfo !== defaultCourseInfo) {
- lastCourseInfoRef.current = courseInfo;
- }
- }, [courseInfo, defaultCourseInfo]);
- const nextCourseInfo = lastCourseInfoRef.current;
- const institution = useSelector((state) => state.main.selectedInstitution);
const classes = useSelector((state) => state.classes.table);
- const totalStudents = nextCourseInfo.numberOfStudents + nextCourseInfo.numberOfPendingStudents;
- const courseDetailsLink = `${getConfig().LEARNING_MICROFRONTEND_URL}/course/${nextCourseInfo.masterCourseId}/home`;
+ const totalStudents = courseInfo.numberOfStudents + courseInfo.numberOfPendingStudents;
+ const courseDetailsLink = `${getConfig().LEARNING_MICROFRONTEND_URL}/course/${courseInfo.masterCourseId}/home`;
const handlePagination = (targetPage) => {
setCurrentPage(targetPage);
@@ -69,7 +60,7 @@ const CoursesDetailPage = () => {
if (institution.id) {
dispatch(fetchClassesData(institution.id, initialPage, courseIdDecoded));
- dispatch(fetchCoursesData(institution.id, initialPage, null));
+ dispatch(fetchCoursesOptionsData(institution.id));
}
return () => {
@@ -79,7 +70,9 @@ const CoursesDetailPage = () => {
}, [dispatch, institution.id, courseIdDecoded]);
useEffect(() => {
- dispatch(fetchClassesData(institution.id, currentPage, courseIdDecoded));
+ if (institution.id) {
+ dispatch(fetchClassesData(institution.id, currentPage, courseIdDecoded));
+ }
}, [currentPage]); // eslint-disable-line react-hooks/exhaustive-deps
useEffect(() => {
@@ -105,14 +98,14 @@ const CoursesDetailPage = () => {
Students enrolled
- {nextCourseInfo.numberOfStudents} + {courseInfo.numberOfStudents} {' / '} {totalStudents} @@ -141,7 +134,7 @@ const CoursesDetailPage = () => {