Skip to content

Commit

Permalink
Merge pull request #1117 from navgurukul/confirm-student-deletion
Browse files Browse the repository at this point in the history
Fixed the errors in the studedata table
  • Loading branch information
komalahire authored Jun 27, 2024
2 parents 911773e + ed02a5b commit 518e120
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 5 deletions.
69 changes: 64 additions & 5 deletions src/components/Dashboard/StudentData/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
CardContent,
Card,
} from "@mui/material";
import { Stack, Dialog, DialogTitle, DialogActions } from "@mui/material";

// const { createSliderWithTooltip } = Slider;
// const Range = createSliderWithTooltip(Slider.Range);
Expand Down Expand Up @@ -59,6 +60,8 @@ function StudentData() {
const [stupassword, setStupassword] = useState();
const [studentEmail, setStudentEmail] = useState();
const [csvUpdatedTime, setCSVUpdatedTime] = useState([]);
const [showModal, setShowModal] = useState(false);
const [selectedStudentId, setSelectedStudentId] = useState(null);

const [triggerdGet, setTriggerdGet] = useState(false);
const loginUser = user.data.user.id;
Expand Down Expand Up @@ -313,7 +316,18 @@ function StudentData() {
// setDisabled(false);
// };

const handleClickOpen = (id) => {
setSelectedStudentId(id);
setShowModal(true);
};

const handleClose = () => {
setShowModal(false);
setSelectedStudentId(null);
};

const removeStudent = (id) => {
setShowModal(!showModal);
return axios({
url: `${process.env.REACT_APP_MERAKI_URL}/partners/${id}/user`,
method: METHODS.DELETE,
Expand Down Expand Up @@ -834,11 +848,56 @@ function StudentData() {
}}
/>
{loginUser == item.id ? null : (
<i
style={{ marginLeft: "20px" }}
className="class-card-action-icon fa fa-trash"
onClick={() => removeStudent(item.id)}
/>
<>
<i
style={{ marginLeft: "20px" }}
className="class-card-action-icon fa fa-trash"
onClick={() => handleClickOpen(item.id)}
/>
{/* dialog box for delete button */}

<Dialog
open={showModal}
BackdropProps={{
style: {
backgroundColor: "rgba(0, 0, 0, 0.2)",
}, // Adjust the opacity here
}}
aria-labelledby="alert-dialog-title"
aria-describedby="alert-dialog-description"
>
<DialogTitle>
<Typography variant="h6" align="center">
Are you sure you want to delete this student?
</Typography>
</DialogTitle>
<Stack alignItems="center">
<DialogActions>
<Box sx={{ display: "flex", mb: 2 }}>
<Button
onClick={(e) => {
e.stopPropagation();
return removeStudent(selectedStudentId); // Ensure this function gets the correct student ID
}}
color="error"
variant="contained"
sx={{ mr: "15px", width: "100px" }}
>
Yes
</Button>
<Button
onClick={handleClose}
color="grey"
variant="contained"
sx={{ width: "100px" }}
>
No
</Button>
</Box>
</DialogActions>
</Stack>
</Dialog>
</>
)}
</td>
)}
Expand Down
1 change: 1 addition & 0 deletions src/pages/AddStudent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ function AddStudent({
return !prev;
});
clearFormAndErrors();
setOpenForm(false);
})
.catch((e) => {
if (e.erorrCode === 2005) {
Expand Down

0 comments on commit 518e120

Please sign in to comment.