Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PADV-973 feat: add instructor modal #40

Merged
merged 1 commit into from
Feb 22, 2024
Merged

PADV-973 feat: add instructor modal #40

merged 1 commit into from
Feb 22, 2024

Conversation

AuraAlba
Copy link
Contributor

Ticket

https://agile-jira.pearson.com/browse/PADV-973

Description

Add instructor modal

Changes made

Update add instructor modal
Remove classes fetch used in the past component
Update tests

Screenshots

Screenshot from 2024-02-21 13-03-30

How to test

Clone the Institution Portal MFE
Run npm install.
Run npm run start
Go to http://localhost:1980/instructors

@anfbermudezme anfbermudezme self-requested a review February 21, 2024 20:56
@AuraAlba AuraAlba requested a review from 01001110J February 21, 2024 20:57
describe('Add instructor modal', () => {
test('Render add insctructor modal', async () => {
const { getByText, getByPlaceholderText } = renderWithProviders(
<AddInstructors isOpen close={() => { }} />,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<AddInstructors isOpen close={() => { }} />,
<AddInstructors isOpen close={() => {}} />,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

setIsNoUser(false);
}
dispatch(addInstructor(selectedInstitution.id, formJson.instructorEmail));
close();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We won't add confirmations at the end? @AuraAlba

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not part of the scope but I added the success message

</FormGroup>
<div className="d-flex justify-content-end">
<ModalCloseButton className="btntpz btn-text btn-tertiary">Cancel</ModalCloseButton>
<Button type="submit">Send invite</Button>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<Button type="submit">Send invite</Button>
<Button type="submit">Send invitation</Button>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how is in the figma, should I change it?


expect(httpClientMock.post).toHaveBeenCalledTimes(1);
expect(httpClientMock.post).toHaveBeenCalledWith(
'http://localhost:18000/pearson_course_operation/api/v2/instructors/[email protected]&institution_id=1',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line too long. @AuraAlba

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -1,5 +1,5 @@
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
import { getInstructorData, handleInstructorsEnrollment } from 'features/Instructors/data/api';
import { getInstructorData, handleInstructorsEnrollment, handleNewInstructor } from 'features/Instructors/data/api';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line too long. @AuraAlba

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

</FormGroup>
<div className="d-flex justify-content-end">
<ModalCloseButton className="btntpz btn-text btn-tertiary">Cancel</ModalCloseButton>
<Button type="submit">Send invite</Button>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure if it would fit within the scope of this issue, but currently, the button remains enabled even if the required input field is empty. While I see that the input field has the 'required' attribute, I'm concerned that users could potentially bypass this by manipulating the HTML using browser dev tools. To strengthen the feature, would it be feasible to add client-side validation to ensure that the input field is filled before sending any requests? And of course the back can check if the email is being provided, if not throw and error, but my point of all of this is avoid just spamming the "send" button with a bunch of request.

What are your thoughts on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have problem with this, is not a complex implementation. I added

Comment on lines +85 to 95
addInstructorRequest: (state) => {
state.addInstructor.status = RequestStatus.LOADING;
},
addInstructorSuccess: (state, { payload }) => {
state.addInstructor.status = RequestStatus.SUCCESS;
state.addInstructor.data = payload;
},
addInstructorFailed: (state) => {
state.addInstructor.status = RequestStatus.ERROR;
},
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this names, there aren't clear, maybe:

Suggested change
addInstructorRequest: (state) => {
state.addInstructor.status = RequestStatus.LOADING;
},
addInstructorSuccess: (state, { payload }) => {
state.addInstructor.status = RequestStatus.SUCCESS;
state.addInstructor.data = payload;
},
addInstructorFailed: (state) => {
state.addInstructor.status = RequestStatus.ERROR;
},
},
setInstructorLoading: (state) => {
state.addInstructor.status = RequestStatus.LOADING;
},
setInstructorSuccessRequest: (state, { payload }) => {
state.addInstructor.status = RequestStatus.SUCCESS;
state.addInstructor.data = payload;
},
setInstructorErrorRequest: (state) => {
state.addInstructor.status = RequestStatus.ERROR;
},
},

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually when we defined a reducer is not a good practice write the name as a setter, I will find a name more descriptive

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not modify this, for me it is quite clear to describe the actions that the reducer performs and adding the request word does not contribute to this description

@@ -44,37 +44,37 @@ function fetchCoursesData(id) {
};
}

function fetchClassesData() {
function assignInstructors(data, classId, institutionId) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it could be a good addition to use jsdocs for documentation purposes:

Suggested change
function assignInstructors(data, classId, institutionId) {
/**
* Assign instructors to a class.
*
* @param {Object} data - The data containing information about the instructors to be assigned.
* @param {string} classId - The ID of the class to which the instructors will be assigned.
* @param {string} institutionId - The ID of the institution associated with the class.
* @returns {Promise<void>} - A promise that resolves after dispatching appropriate actions.
*/
function assignInstructors(data, classId, institutionId) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
};
}

function assignInstructors(data, classId, institutionId) {
function addInstructor(institutionId, instructorEmail) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment about docs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

const stateInstructors = useSelector((state) => state.instructors.classes);
import { addInstructor } from 'features/Instructors/data/thunks';

const AddInstructors = ({ isOpen, close }) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think close is not clear enough, maybe handleOnClose or onClose could be more descriptive.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -16,6 +17,7 @@ const InstructorsPage = () => {
const selectedInstitution = useSelector((state) => state.main.selectedInstitution);
const dispatch = useDispatch();
const [currentPage, setCurrentPage] = useState(initialPage);
const [isOpen, open, close] = useToggle(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This names does not explain itself what's supposed to should do, maybe:

Suggested change
const [isOpen, open, close] = useToggle(false);
const [isOpen, openMolda, closeModal] = useToggle(false);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@AuraAlba AuraAlba merged commit 389a2ed into master Feb 22, 2024
2 checks passed
@AuraAlba AuraAlba deleted the vue/PADV-973 branch February 22, 2024 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants