-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #94 from AkshataKatwal16/page-issue
Issue feat:Modify delete functionality and optimise code
- Loading branch information
Showing
8 changed files
with
194 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React, { useState } from "react"; | ||
import { Box, Typography, Tooltip, useTheme } from "@mui/material"; | ||
import DeleteConfirmation from "./DeleteConfirmation"; | ||
|
||
interface ActionCellProps { | ||
rowData?: any; | ||
} | ||
|
||
const ActionIcon: React.FC<ActionCellProps> = ({ | ||
rowData, | ||
// onEdit, | ||
}) => { | ||
const theme = useTheme<any>(); | ||
const [open, setOpen] = useState(false); | ||
const handleClose = () => { | ||
setOpen(false); | ||
}; | ||
const handleOpen = () => { | ||
setOpen(true); | ||
}; | ||
return ( | ||
<Box | ||
sx={{ | ||
display: "flex", | ||
flexDirection: "row", | ||
gap: "20px", | ||
alignItems: "center", | ||
}} | ||
> | ||
<Tooltip title={"COMMON.DELETE"}> | ||
<Box | ||
onClick={() => { | ||
console.log(rowData); | ||
|
||
handleOpen(); | ||
}} | ||
sx={{ | ||
display: "flex", | ||
flexDirection: "column", | ||
alignItems: "center", | ||
cursor: "pointer", | ||
backgroundColor: "#F8EFE7", | ||
p: "10px", | ||
}} | ||
> | ||
<img src={"/delete.png"} height="20px" alt="Image" /> | ||
</Box> | ||
</Tooltip> | ||
|
||
<DeleteConfirmation | ||
open={open} | ||
handleClose={handleClose} | ||
rowData={rowData} | ||
/> | ||
</Box> | ||
); | ||
}; | ||
|
||
export default ActionIcon; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import React from "react"; | ||
import { | ||
Dialog, | ||
DialogActions, | ||
DialogContent, | ||
DialogContentText, | ||
DialogTitle, | ||
Button, | ||
IconButton, | ||
Typography, | ||
} from "@mui/material"; | ||
import CloseIcon from "@mui/icons-material/Close"; | ||
import { deleteContent } from "@/services/ContentService"; | ||
|
||
interface DeleteConfirmationProps { | ||
open: boolean; | ||
handleClose: any; | ||
rowData?: any; | ||
} | ||
|
||
const DeleteConfirmation: React.FC<DeleteConfirmationProps> = ({ | ||
open, | ||
rowData, | ||
handleClose, | ||
}) => { | ||
const handleDelete = async (content?: any) => { | ||
console.log(`Deleting item at index`, rowData); | ||
|
||
if (rowData?.identifier && rowData?.mimeType) { | ||
try { | ||
await deleteContent(rowData?.identifier, rowData?.mimeType); | ||
console.log(`Deleted item with identifier - ${rowData?.identifier}`); | ||
// setContentDeleted((prev) => !prev); | ||
} catch (error) { | ||
console.error("Failed to delete content:", error); | ||
} | ||
} | ||
handleClose(); | ||
}; | ||
return ( | ||
<Dialog | ||
open={open} | ||
onClose={handleClose} | ||
aria-labelledby="delete-confirmation-title" | ||
aria-describedby="delete-confirmation-description" | ||
maxWidth="xs" | ||
fullWidth | ||
> | ||
<DialogTitle sx={{ m: 0, p: 2 }} id="delete-confirmation-title"> | ||
<Typography variant="h6">Confirm Deletion</Typography> | ||
<IconButton | ||
aria-label="close" | ||
onClick={handleClose} | ||
sx={{ | ||
position: "absolute", | ||
right: 8, | ||
top: 8, | ||
color: (theme) => theme.palette.grey[500], | ||
}} | ||
> | ||
<CloseIcon /> | ||
</IconButton> | ||
</DialogTitle> | ||
<DialogContent dividers> | ||
<DialogContentText | ||
id="delete-confirmation-description" | ||
sx={{ textAlign: "center", mt: 1 }} | ||
> | ||
Are you sure you want to delete this item? | ||
</DialogContentText> | ||
</DialogContent> | ||
<DialogActions sx={{ justifyContent: "center", pb: 2 }}> | ||
<Button onClick={handleClose} variant="outlined"> | ||
Cancel | ||
</Button> | ||
<Button onClick={handleDelete} variant="contained"> | ||
Delete | ||
</Button> | ||
</DialogActions> | ||
</Dialog> | ||
); | ||
}; | ||
|
||
export default DeleteConfirmation; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.