From 1e39ccb1e3d3b928521c2d36dfc0192eb7204436 Mon Sep 17 00:00:00 2001 From: anfbermudezme Date: Tue, 12 Dec 2023 20:13:53 +0100 Subject: [PATCH] fix: show all courses for Global Admin and filtered courses for IA. --- src/features/Courses/CoursesPage/index.jsx | 8 +++----- src/features/Instructors/InstructorsFilters/index.jsx | 8 +++----- src/features/Students/StudentsFilters/index.jsx | 8 +++----- src/features/Students/data/api.js | 4 +++- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/features/Courses/CoursesPage/index.jsx b/src/features/Courses/CoursesPage/index.jsx index c9175f84..9574bd81 100644 --- a/src/features/Courses/CoursesPage/index.jsx +++ b/src/features/Courses/CoursesPage/index.jsx @@ -34,8 +34,8 @@ const CoursesPage = () => { const [currentPage, setCurrentPage] = useState(1); const [filters, setFilters] = useState({}); - let id = 0; - if (stateInstitution.length > 0) { + let id = ''; + if (stateInstitution.length === 1) { id = stateInstitution[0].id; } @@ -52,9 +52,7 @@ const CoursesPage = () => { }; useEffect(() => { - if (id > 0) { - fetchData(filters); - } + fetchData(filters); }, [currentPage, id, filters]); // eslint-disable-line react-hooks/exhaustive-deps const handlePagination = (targetPage) => { diff --git a/src/features/Instructors/InstructorsFilters/index.jsx b/src/features/Instructors/InstructorsFilters/index.jsx index 6d7c7adc..d3f13455 100644 --- a/src/features/Instructors/InstructorsFilters/index.jsx +++ b/src/features/Instructors/InstructorsFilters/index.jsx @@ -34,8 +34,8 @@ const InstructorsFilters = ({ fetchData, resetPagination, setFilters }) => { const [instructorEmail, setInstructorEmail] = useState(''); const [courseSelected, setCourseSelected] = useState(null); // check this after implementation of selector institution - let id = 0; - if (stateInstitution.length > 0) { + let id = ''; + if (stateInstitution.length === 1) { id = stateInstitution[0].id; } @@ -74,9 +74,7 @@ const InstructorsFilters = ({ fetchData, resetPagination, setFilters }) => { }; useEffect(() => { - if (id > 0) { - fetchCoursesData(); - } // eslint-disable-next-line react-hooks/exhaustive-deps + fetchCoursesData(); // eslint-disable-next-line react-hooks/exhaustive-deps }, [id]); useEffect(() => { diff --git a/src/features/Students/StudentsFilters/index.jsx b/src/features/Students/StudentsFilters/index.jsx index 300d398b..fd9d0384 100644 --- a/src/features/Students/StudentsFilters/index.jsx +++ b/src/features/Students/StudentsFilters/index.jsx @@ -45,8 +45,8 @@ const StudentsFilters = ({ resetPagination, fetchData, setFilters }) => { const [statusSelected, setStatusSelected] = useState(null); const [examSelected, setExamSelected] = useState(null); // check this after implementation of selector institution - let id = 0; - if (stateInstitution.length > 0) { + let id = ''; + if (stateInstitution.length === 1) { id = stateInstitution[0].id; } @@ -87,9 +87,7 @@ const StudentsFilters = ({ resetPagination, fetchData, setFilters }) => { }; useEffect(() => { - if (id > 0) { - fetchCoursesData(); - } // eslint-disable-next-line react-hooks/exhaustive-deps + fetchCoursesData(); // eslint-disable-next-line react-hooks/exhaustive-deps }, [id]); useEffect(() => { diff --git a/src/features/Students/data/api.js b/src/features/Students/data/api.js index df1f7397..6a8ad2d0 100644 --- a/src/features/Students/data/api.js +++ b/src/features/Students/data/api.js @@ -24,9 +24,11 @@ function handleEnrollments(data, courseId) { } function getClassesByInstitution(institutionId, courseName) { + const encodedCourseName = encodeURIComponent(courseName); + return getAuthenticatedHttpClient().get( `${getConfig().COURSE_OPERATIONS_API_V2_BASE_URL}/classes` - + `/?limit=false&institution_id=${institutionId}&course_name=${courseName}`, + + `/?limit=false&institution_id=${institutionId}&course_name=${encodedCourseName}`, ); }