From 2e94efcea5dddd3ab220703e7519b508a46f3b15 Mon Sep 17 00:00:00 2001 From: Aura Alba Date: Thu, 22 Feb 2024 16:05:10 -0500 Subject: [PATCH] fix: assign instructors list --- .../Instructors/AssignInstructors/index.jsx | 15 +++++++++++++-- .../Instructors/data/_test_/redux.test.js | 14 +++++++++++++- src/features/Instructors/data/slice.js | 4 ++++ src/features/Instructors/data/thunks.js | 2 ++ 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/features/Instructors/AssignInstructors/index.jsx b/src/features/Instructors/AssignInstructors/index.jsx index 6fee3333..71fc9a51 100644 --- a/src/features/Instructors/AssignInstructors/index.jsx +++ b/src/features/Instructors/AssignInstructors/index.jsx @@ -9,7 +9,10 @@ import AssignTable from 'features/Instructors/AssignInstructors/AssignTable'; import { fetchInstructorsData, assignInstructors } from 'features/Instructors/data'; import { - updateCurrentPage, updateFilters, updateClassSelected, + updateCurrentPage, + updateFilters, + updateClassSelected, + resetRowSelect, } from 'features/Instructors/data/slice'; import { initialPage } from 'features/constants'; @@ -22,6 +25,7 @@ const AssignInstructors = ({ isOpen, close }) => { const rowsSelected = useSelector((state) => state.instructors.rowsSelected); const classId = useSelector((state) => state.instructors.classSelected); const [currentPage, setCurrentPage] = useState(initialPage); + const isButtonDisabled = rowsSelected.length === 0; const resetPagination = () => { setCurrentPage(initialPage); @@ -54,6 +58,7 @@ const AssignInstructors = ({ isOpen, close }) => { if (!isOpen) { dispatch(updateFilters({})); dispatch(updateClassSelected('')); + dispatch(resetRowSelect()); } }, [isOpen, dispatch]); @@ -86,7 +91,13 @@ const AssignInstructors = ({ isOpen, close }) => { )}
Cancel - +
diff --git a/src/features/Instructors/data/_test_/redux.test.js b/src/features/Instructors/data/_test_/redux.test.js index 06565ae3..57e88d5e 100644 --- a/src/features/Instructors/data/_test_/redux.test.js +++ b/src/features/Instructors/data/_test_/redux.test.js @@ -5,7 +5,12 @@ import { fetchInstructorsData, fetchCoursesData, addInstructor, } from 'features/Instructors/data/thunks'; import { - updateCurrentPage, updateFilters, updateClassSelected, addRowSelect, deleteRowSelect, + updateCurrentPage, + updateFilters, + updateClassSelected, + addRowSelect, + deleteRowSelect, + resetRowSelect, } from 'features/Instructors/data/slice'; import { executeThunk } from 'test-utils'; import { initializeStore } from 'store'; @@ -222,4 +227,11 @@ describe('Instructors redux tests', () => { expect(store.getState().instructors.addInstructor.status) .toEqual('error'); }); + + test('Reset rowsSelected', () => { + const expectState = []; + + store.dispatch(resetRowSelect()); + expect(store.getState().instructors.rowsSelected).toEqual(expectState); + }); }); diff --git a/src/features/Instructors/data/slice.js b/src/features/Instructors/data/slice.js index f29667a4..e6eb1265 100644 --- a/src/features/Instructors/data/slice.js +++ b/src/features/Instructors/data/slice.js @@ -82,6 +82,9 @@ export const instructorsSlice = createSlice({ deleteRowSelect: (state, { payload }) => { state.rowsSelected = state.rowsSelected.filter(row => row !== payload); }, + resetRowSelect: (state) => { + state.rowsSelected = []; + }, addInstructorRequest: (state) => { state.addInstructor.status = RequestStatus.LOADING; }, @@ -110,6 +113,7 @@ export const { assingInstructorsFailed, addRowSelect, deleteRowSelect, + resetRowSelect, addInstructorRequest, addInstructorSuccess, addInstructorFailed, diff --git a/src/features/Instructors/data/thunks.js b/src/features/Instructors/data/thunks.js index a6198aa1..ab9f8e82 100644 --- a/src/features/Instructors/data/thunks.js +++ b/src/features/Instructors/data/thunks.js @@ -15,6 +15,7 @@ import { addInstructorRequest, addInstructorSuccess, addInstructorFailed, + resetRowSelect, } from 'features/Instructors/data/slice'; import { fetchClassesData as fetchClassesDataHome } from 'features/Dashboard/data'; import { initialPage } from 'features/constants'; @@ -63,6 +64,7 @@ function assignInstructors(data, classId, institutionId) { logError(error); } finally { dispatch(fetchClassesDataHome(institutionId, false)); + dispatch(resetRowSelect()); } }; }