Skip to content

Commit

Permalink
Merge pull request #134 from Pearson-Advance/vue/PADV-1793
Browse files Browse the repository at this point in the history
feat: switch button to get only my courses
  • Loading branch information
01001110J authored Dec 6, 2024
2 parents dfccf17 + 24cefb0 commit a80b269
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/features/Courses/CoursesFilters/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ import { useDispatch, useSelector } from 'react-redux';
import { Col, Form } from '@edx/paragon';
import { Select } from 'react-paragon-topaz';

import { updateFilters, updateCurrentPage } from 'features/Courses/data/slice';
import { updateFilters, updateCurrentPage, updateShowAllCourses } from 'features/Courses/data/slice';
import { fetchCoursesData, fetchCoursesOptionsData } from 'features/Courses/data/thunks';

import { initialPage, styleFirstOption, allResultsOption } from 'features/constants';
import {
initialPage, styleFirstOption, allResultsOption, RequestStatus,
} from 'features/constants';

const CoursesFilters = () => {
const dispatch = useDispatch();
const selectedInstitution = useSelector((state) => state.main.selectedInstitution);
const courses = useSelector((state) => state.courses.selectOptions);
const showAllCourses = useSelector((state) => state.courses.showAllCourses);
const coursesRequest = useSelector((state) => state.courses.table.status);
const [courseOptions, setCourseOptions] = useState([]);
const [courseSelected, setCourseSelected] = useState(null);
const [inputCourse, setInputCourse] = useState('');
Expand All @@ -35,6 +39,8 @@ const CoursesFilters = () => {
}
};

const handleToggleChange = e => dispatch(updateShowAllCourses(e.target.checked));

useEffect(() => {
if (Object.keys(selectedInstitution).length > 0) {
setCourseSelected(null);
Expand All @@ -56,7 +62,9 @@ const CoursesFilters = () => {

useEffect(() => {
if (Object.keys(selectedInstitution).length > 0) {
const params = {};
const params = {
has_classes: showAllCourses,
};

if (courseSelected) {
params.course_name = courseSelected.value === defaultOption.value
Expand All @@ -68,8 +76,11 @@ const CoursesFilters = () => {
dispatch(updateFilters(params));
dispatch(updateCurrentPage(initialPage));
}

// eslint-disable-next-line react-hooks/exhaustive-deps
}, [courseSelected, selectedInstitution]);
}, [courseSelected, selectedInstitution, showAllCourses]);

const isLoading = coursesRequest === RequestStatus.LOADING;

return (
<div className="filter-container justify-content-center row">
Expand All @@ -95,6 +106,16 @@ const CoursesFilters = () => {
/>
</Form.Group>
</Form.Row>
<Form.Row className="w-100 mt-2">
<Form.Switch
checked={showAllCourses}
onChange={handleToggleChange}
className="ml-3"
disabled={isLoading}
>
Show my courses
</Form.Switch>
</Form.Row>
</Form>
</div>
</div>
Expand Down
5 changes: 5 additions & 0 deletions src/features/Courses/data/slice.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const initialState = {
data: null,
},
notificationMessage: '',
showAllCourses: false,
};

export const coursesSlice = createSlice({
Expand Down Expand Up @@ -67,6 +68,9 @@ export const coursesSlice = createSlice({
updateNotificationMsg: (state, { payload }) => {
state.notificationMessage = payload;
},
updateShowAllCourses: (state, { payload }) => {
state.showAllCourses = payload;
},
},
});

Expand All @@ -83,6 +87,7 @@ export const {
newClassFailed,
resetClassState,
updateNotificationMsg,
updateShowAllCourses,
} = coursesSlice.actions;

export const { reducer } = coursesSlice;

0 comments on commit a80b269

Please sign in to comment.