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

E2461: UI for Courses #70

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
27 changes: 16 additions & 11 deletions src/pages/Courses/CourseDelete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import useAPI from "../../hooks/useAPI";
import { ICourseResponse as ICourse } from "../../utils/interfaces";

/**
* @author Atharva Thorve, on December, 2023
* @author Mrityunjay Joshi on December, 2023
* @author Suraj Raghu Kumar, on Oct, 2024
* @author Yuktasree Muppala on Oct, 2024
* @author Harvardhan Patil on Oct, 2024
*/

// DeleteCourse Component: Modal for deleting a course
Expand All @@ -32,18 +33,22 @@ const DeleteCourse: React.FC<IDeleteCourse> = ({ courseData, onClose }) => {
useEffect(() => {
if (courseError) dispatch(alertActions.showAlert({ variant: "danger", message: courseError }));
}, [courseError, dispatch]);


Copy link
Author

Choose a reason for hiding this comment

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

Added this to allow flexibility and adhere to LSP

//Added this method to be called for success and achieve LSP and DRY
const handleDeleteSuccess = () => {
setShow(false);
dispatch(
alertActions.showAlert({
variant: "success",
message: `Course ${courseData.name} deleted successfully!`,
})
);
onClose();
};
// Close modal if course is deleted
useEffect(() => {
if (deletedCourse?.status && deletedCourse?.status >= 200 && deletedCourse?.status < 300) {
setShow(false);
dispatch(
alertActions.showAlert({
variant: "success",
message: `Course ${courseData.name} deleted successfully!`,
})
);
onClose();
handleDeleteSuccess();
}
}, [deletedCourse?.status, dispatch, onClose, courseData.name]);

Expand Down