diff --git a/src/features/Instructors/AssignInstructors/AssignTable.jsx b/src/features/Instructors/AssignInstructors/AssignTable.jsx deleted file mode 100644 index 4f8ad50b..00000000 --- a/src/features/Instructors/AssignInstructors/AssignTable.jsx +++ /dev/null @@ -1,47 +0,0 @@ -import React, { useMemo } from 'react'; -import { useSelector } from 'react-redux'; - -import { - Row, - Col, - DataTable, -} from '@edx/paragon'; -import ControlledSelect from 'features/Instructors/ManageInstructors/ControlledSelect'; - -import { columns } from 'features/Instructors/AssignInstructors/columns'; - -const AssignTable = () => { - const stateInstructors = useSelector((state) => state.instructors.table); - const COLUMNS = useMemo(() => columns(), []); - - const selectColumn = { - id: 'selection', - Header: <>, // eslint-disable-line react/jsx-no-useless-fragment - Cell: ControlledSelect, - disableSortBy: true, - }; - - return ( - - - row.instructorUsername, - }} - > - - - - - - ); -}; - -export default AssignTable; diff --git a/src/features/Instructors/AssignInstructors/_test_/index.test.jsx b/src/features/Instructors/AssignInstructors/_test_/index.test.jsx deleted file mode 100644 index d4e3df83..00000000 --- a/src/features/Instructors/AssignInstructors/_test_/index.test.jsx +++ /dev/null @@ -1,74 +0,0 @@ -import React from 'react'; -import { waitFor, fireEvent } from '@testing-library/react'; -import AssignInstructors from 'features/Instructors/AssignInstructors'; -import '@testing-library/jest-dom/extend-expect'; -import { renderWithProviders } from 'test-utils'; -import { RequestStatus } from 'features/constants'; - -jest.mock('@edx/frontend-platform/logging', () => ({ - logError: jest.fn(), -})); - -const mockStore = { - instructors: { - table: { - data: [ - { - instructorUsername: 'Instructor1', - instructorName: 'Instructor 1', - instructorEmail: 'instructor1@example.com', - ccxId: 'CCX1', - ccxName: 'CCX 1', - }, - { - instructorUsername: 'Instructor2', - instructorName: 'Instructor 2', - instructorEmail: 'instructor2@example.com', - ccxId: 'CCX2', - ccxName: 'CCX 2', - }, - ], - count: 2, - num_pages: 1, - current_page: 1, - }, - classes: { - data: [], - }, - courses: { - data: [], - }, - filters: { - }, - rowsSelected: [], - classSelected: '', - assignInstructors: { - status: RequestStatus.LOADING, - error: null, - data: [], - }, - }, -}; - -describe('Assign instructors modal', () => { - test('render assing instructors modal', () => { - const { getByText, getAllByRole, getByTestId } = renderWithProviders( - {}} />, - { preloadedState: mockStore }, - ); - - waitFor(() => { - expect(getByText('Instructor')).toBeInTheDocument(); - expect(getByText('Instructor1')).toBeInTheDocument(); - expect(getByText('Instructor2')).toBeInTheDocument(); - expect(getByText('Last seen')).toBeInTheDocument(); - expect(getByText('Courses taught')).toBeInTheDocument(); - }); - - const checkboxFields = getAllByRole('checkbox'); - fireEvent.click(checkboxFields[0]); - - const assignButton = getByTestId('assignButton'); - fireEvent.click(assignButton); - }); -}); diff --git a/src/features/Instructors/AssignInstructors/columns.jsx b/src/features/Instructors/AssignInstructors/columns.jsx deleted file mode 100644 index cd198ad1..00000000 --- a/src/features/Instructors/AssignInstructors/columns.jsx +++ /dev/null @@ -1,41 +0,0 @@ -/* eslint-disable react/prop-types, no-nested-ternary */ -import { differenceInHours, differenceInDays, differenceInWeeks } from 'date-fns'; - -import { daysWeek, hoursDay } from 'features/constants'; - -const columns = () => [ - { - Header: 'Instructor', - accessor: 'instructorName', - }, - { - Header: 'Last seen', - accessor: 'lastAccess', - Cell: ({ row }) => { - if (!row.values.lastAccess) { - return -; - } - - const currentDate = Date.now(); - const lastDate = new Date(row.values.lastAccess); - const diffHours = differenceInHours(currentDate, lastDate); - const diffDays = differenceInDays(currentDate, lastDate); - const diffWeeks = differenceInWeeks(currentDate, lastDate); - return ( - {diffHours < hoursDay - ? 'Today' - : diffDays < daysWeek - ? `${diffDays} days ago` - : `${diffWeeks} wks ago`} - - ); - }, - }, - { - Header: 'Courses Taught', - accessor: 'classes', - disableSortBy: true, - }, -]; - -export { columns }; diff --git a/src/features/Instructors/AssignInstructors/index.jsx b/src/features/Instructors/AssignInstructors/index.jsx deleted file mode 100644 index 0105b66a..00000000 --- a/src/features/Instructors/AssignInstructors/index.jsx +++ /dev/null @@ -1,130 +0,0 @@ -// THIS FOLDER WILL BE REMOVED AFTER INTEGRATE ALL SECTIONS WITH NEW MANAGE INSTRUCTORS PAGE -import React, { useState, useEffect } from 'react'; -import { useDispatch, useSelector } from 'react-redux'; -import PropTypes from 'prop-types'; - -import { ModalDialog, ModalCloseButton, Pagination } from '@edx/paragon'; -import { Button } from 'react-paragon-topaz'; -import InstructorsFilters from 'features/Instructors/InstructorsFilters'; -import AssignTable from 'features/Instructors/AssignInstructors/AssignTable'; - -import { fetchClassesData as fetchClassesDataHome } from 'features/Dashboard/data'; -import { fetchInstructorsData, assignInstructors } from 'features/Instructors/data'; -import { - updateCurrentPage, - updateFilters, - updateClassSelected, - resetRowSelect, -} from 'features/Instructors/data/slice'; - -import { initialPage } from 'features/constants'; -import 'features/Instructors/AssignInstructors/index.scss'; - -const AssignInstructors = ({ isOpen, close, getClasses }) => { - const dispatch = useDispatch(); - const selectedInstitution = useSelector((state) => state.main.selectedInstitution); - const stateInstructors = useSelector((state) => state.instructors); - 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); - }; - - const handlePagination = (targetPage) => { - setCurrentPage(targetPage); - dispatch(updateCurrentPage(targetPage)); - }; - - const handleAssignInstructors = async () => { - try { - const dispatchPromises = rowsSelected.map(row => { - const enrollmentData = new FormData(); - enrollmentData.append('unique_student_identifier', row); - enrollmentData.append('rolename', 'staff'); - enrollmentData.append('action', 'allow'); - enrollmentData.append('class_id', classId); - return dispatch(assignInstructors(enrollmentData)); - }); - - await Promise.all(dispatchPromises); - - if (getClasses) { - dispatch(fetchClassesDataHome(selectedInstitution.id)); - } - } finally { - close(); - } - }; - - useEffect(() => { - if (Object.keys(selectedInstitution).length > 0 && isOpen) { - const instructorFilters = stateInstructors.filters; - dispatch(fetchInstructorsData(selectedInstitution.id, currentPage, instructorFilters)); - } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [currentPage, selectedInstitution, dispatch, isOpen]); - - useEffect(() => { - if (!isOpen) { - dispatch(updateFilters({})); - dispatch(updateClassSelected('')); - dispatch(resetRowSelect()); - } - }, [isOpen, dispatch]); - - return ( - - - - Assign instructor - - - - - - {stateInstructors.table.numPages > 1 && ( - - )} -
- Cancel - -
-
-
- ); -}; - -AssignInstructors.propTypes = { - isOpen: PropTypes.bool.isRequired, - close: PropTypes.func.isRequired, - getClasses: PropTypes.bool, -}; - -AssignInstructors.defaultProps = { - getClasses: true, -}; - -export default AssignInstructors; diff --git a/src/features/Instructors/AssignInstructors/index.scss b/src/features/Instructors/AssignInstructors/index.scss deleted file mode 100644 index 1e7655f1..00000000 --- a/src/features/Instructors/AssignInstructors/index.scss +++ /dev/null @@ -1,13 +0,0 @@ -@import "assets/colors.scss"; - -.pgn__modal-close-button.btn-icon.btn-icon-primary { - color: $gray-70; - - &:hover, - &:active, - &:focus { - color: $gray-70; - background-color: $gray-20; - box-shadow: none; - } -} diff --git a/src/features/Instructors/data/_test_/redux.test.js b/src/features/Instructors/data/_test_/redux.test.js index 347a02ae..e4e0a1ef 100644 --- a/src/features/Instructors/data/_test_/redux.test.js +++ b/src/features/Instructors/data/_test_/redux.test.js @@ -7,7 +7,6 @@ import { import { updateCurrentPage, updateFilters, - updateClassSelected, addRowSelect, deleteRowSelect, resetRowSelect, @@ -119,14 +118,6 @@ describe('Instructors redux tests', () => { expect(store.getState().instructors.filters).toEqual(expectState); }); - test('update classSelected', () => { - const classSelected = 'ccx1'; - const expectState = classSelected; - - store.dispatch(updateClassSelected(classSelected)); - expect(store.getState().instructors.classSelected).toEqual(expectState); - }); - test('Add rowsSelected', () => { const rowSelected = 'Instructor01'; const expectState = rowSelected; diff --git a/src/features/Instructors/data/slice.js b/src/features/Instructors/data/slice.js index 409d320d..303e4d86 100644 --- a/src/features/Instructors/data/slice.js +++ b/src/features/Instructors/data/slice.js @@ -54,9 +54,6 @@ export const instructorsSlice = createSlice({ updateFilters: (state, { payload }) => { state.filters = payload; }, - updateClassSelected: (state, { payload }) => { - state.classSelected = payload; - }, assignInstructorsRequest: (state) => { state.assignInstructors.status = RequestStatus.LOADING; }, @@ -109,7 +106,6 @@ export const { fetchInstructorsDataSuccess, fetchInstructorsDataFailed, updateFilters, - updateClassSelected, assignInstructorsRequest, assignInstructorsSuccess, assignInstructorsFailed,