diff --git a/src/features/Instructors/AddInstructors/_test_/index.test.jsx b/src/features/Instructors/AddInstructors/_test_/index.test.jsx
index 3cace2a7..823f08d9 100644
--- a/src/features/Instructors/AddInstructors/_test_/index.test.jsx
+++ b/src/features/Instructors/AddInstructors/_test_/index.test.jsx
@@ -41,5 +41,11 @@ describe('Add instructor component', () => {
const ccxSelect = getByText('Select Class Name');
expect(instructorInfoInput).toBeInTheDocument();
expect(ccxSelect).toBeInTheDocument();
+
+ fireEvent.change(instructorInfoInput, { target: { value: 'Name' } });
+ const submitButton = getByText('Add');
+ await act(async () => {
+ fireEvent.click(submitButton);
+ });
});
});
diff --git a/src/features/Instructors/AddInstructors/index.jsx b/src/features/Instructors/AddInstructors/index.jsx
index 939ed3e9..77216a45 100644
--- a/src/features/Instructors/AddInstructors/index.jsx
+++ b/src/features/Instructors/AddInstructors/index.jsx
@@ -2,7 +2,7 @@ import React, { useState, useReducer, useEffect } from 'react';
import {
Button, FormGroup, ModalDialog, useToggle, Form,
} from '@edx/paragon';
-import { getCCXList } from 'features/Instructors/data/api';
+import { getCCXList, handleInstructorsEnrollment } from 'features/Instructors/data/api';
import reducer from 'features/Instructors/AddInstructors/reducer';
import { logError } from '@edx/frontend-platform/logging';
import { camelCaseObject } from '@edx/frontend-platform';
@@ -26,6 +26,8 @@ const AddInstructors = () => {
const [state, dispatch] = useReducer(reducer, initialState);
const [isOpen, open, close] = useToggle(false);
const [addInstructorInfo, setAddInstructorInfo] = useState(addInstructorState);
+ const [isNoUser, setIsNoUser] = useState(false);
+ const enrollmentData = new FormData();
const fetchData = async () => {
dispatch({ type: FETCH_CCX_LIST_REQUEST });
@@ -46,6 +48,17 @@ const AddInstructors = () => {
});
};
+ // Set default value
+ useEffect(() => {
+ if (state.data.length > 0) {
+ setAddInstructorInfo((prevState) => ({
+ ...prevState,
+ ccxId: state.data[0].classId,
+ ccxName: state.data[0].className,
+ }));
+ }
+ }, [state.data]);
+
const handleCcxSelect = (e) => {
const select = e.target;
setAddInstructorInfo({
@@ -55,6 +68,24 @@ const AddInstructors = () => {
});
};
+ const handleAddInstructors = async () => {
+ try {
+ enrollmentData.append('unique_student_identifier', addInstructorInfo.instructorInfo);
+ enrollmentData.append('rolename', 'staff');
+ enrollmentData.append('action', 'allow');
+ const response = await handleInstructorsEnrollment(enrollmentData, addInstructorInfo.ccxId);
+ if (response.data?.userDoesNotExist) {
+ setIsNoUser(true);
+ } else {
+ fetchData();
+ close();
+ setIsNoUser(false);
+ }
+ } catch (error) {
+ logError(error);
+ }
+ };
+
useEffect(() => {
fetchData();
}, []);
@@ -83,9 +114,12 @@ const AddInstructors = () => {
className="my-4 mr-0"
onChange={handleCcxSelect}
id="selectCcx"
+ value={addInstructorInfo.ccxId}
>
{state.data.map((ccx) => )}
+
+