Skip to content

Commit

Permalink
fix: assign instructors list
Browse files Browse the repository at this point in the history
  • Loading branch information
AuraAlba committed Feb 23, 2024
1 parent a081a51 commit 2e94efc
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
15 changes: 13 additions & 2 deletions src/features/Instructors/AssignInstructors/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Expand Down Expand Up @@ -54,6 +58,7 @@ const AssignInstructors = ({ isOpen, close }) => {
if (!isOpen) {
dispatch(updateFilters({}));
dispatch(updateClassSelected(''));
dispatch(resetRowSelect());
}
}, [isOpen, dispatch]);

Expand Down Expand Up @@ -86,7 +91,13 @@ const AssignInstructors = ({ isOpen, close }) => {
)}
<div className="d-flex justify-content-end">
<ModalCloseButton className="btntpz btn-text btn-tertiary">Cancel</ModalCloseButton>
<Button onClick={handleAssignInstructors} data-testid="assignButton">Assign instructor</Button>
<Button
onClick={handleAssignInstructors}
data-testid="assignButton"
disabled={isButtonDisabled}
>
Assign instructor
</Button>
</div>
</ModalDialog.Body>
</ModalDialog>
Expand Down
14 changes: 13 additions & 1 deletion src/features/Instructors/data/_test_/redux.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
});
});
4 changes: 4 additions & 0 deletions src/features/Instructors/data/slice.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down Expand Up @@ -110,6 +113,7 @@ export const {
assingInstructorsFailed,
addRowSelect,
deleteRowSelect,
resetRowSelect,
addInstructorRequest,
addInstructorSuccess,
addInstructorFailed,
Expand Down
2 changes: 2 additions & 0 deletions src/features/Instructors/data/thunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -63,6 +64,7 @@ function assignInstructors(data, classId, institutionId) {
logError(error);
} finally {
dispatch(fetchClassesDataHome(institutionId, false));
dispatch(resetRowSelect());
}
};
}
Expand Down

0 comments on commit 2e94efc

Please sign in to comment.