Skip to content

Commit

Permalink
Merge pull request #105 from AkshataKatwal16/page-issue
Browse files Browse the repository at this point in the history
Issue feat:Await 2 seconds for delete items
  • Loading branch information
itsvick authored Nov 22, 2024
2 parents 4dfc68b + 5c01677 commit 3a50a6b
Showing 1 changed file with 27 additions and 41 deletions.
68 changes: 27 additions & 41 deletions src/components/DeleteConfirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
Typography,
Box,
Divider,
CircularProgress,
} from "@mui/material";
import CloseIcon from "@mui/icons-material/Close";
import { deleteContent } from "@/services/ContentService";
Expand All @@ -27,53 +26,51 @@ const DeleteConfirmation: React.FC<DeleteConfirmationProps> = ({
rowData,
handleClose,
}) => {
const delay = (ms: number) =>
new Promise((resolve) => setTimeout(resolve, ms));
const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));

const [loading, setLoading] = React.useState(false);

const fetchContentAPI = useSharedStore((state: any) => state.fetchContentAPI);
const fetchContentAPI = useSharedStore(
(state: any) => state.fetchContentAPI
);
const setFetchContentAPI = useSharedStore(
(state: any) => state.setFetchContentAPI
);
const handleDelete = async () => {
setLoading(true);
try {
if (rowData?.identifier && rowData?.mimeType) {
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}`);
await delay(1000);
await delay(2000);

// Update the fetchContentAPI state after the delay
setFetchContentAPI(!fetchContentAPI);
} catch (error) {
console.error("Failed to delete content:", error);
}
} catch (error) {
console.error("Failed to delete content:", error);
// setFetchContentAPI(!fetchContentAPI)


}
setLoading(false);
handleClose();
};
return (
<Dialog
open={open}
onClose={(event, reason) => {
if (reason !== "backdropClick") {
handleClose();
}
}}
onClose={handleClose}
aria-labelledby="delete-confirmation-title"
aria-describedby="delete-confirmation-description"
maxWidth="xs"
fullWidth
fullWidth
sx={{
"& .MuiDialog-paper": {
borderRadius: "16px",
},
}}
>
<DialogTitle sx={{ m: 0 }} id="delete-confirmation-title">
<Box sx={{ padding: "10px" }}>
<Typography sx={{ fontWeight: "400", fontSize: "16px" }}>
Are you sure you want to delete this item?
</Typography>
<DialogTitle sx={{ m: 0,}} id="delete-confirmation-title">
<Box sx={{padding:'10px'}}>
<Typography sx={{ fontWeight: "400", fontSize: "16px" }}>Are you sure you want to delete this Resource?</Typography>
</Box>
{/* <IconButton
aria-label="close"
Expand All @@ -89,24 +86,13 @@ const DeleteConfirmation: React.FC<DeleteConfirmationProps> = ({
</IconButton> */}
</DialogTitle>
<Divider />

<DialogActions
sx={{ justifyContent: "end", gap: "10px", padding: "20px" }}
>
<Box
onClick={handleClose}
sx={{ cursor: "pointer", color: "#0D599E", fontSize: "14px" }}
>

<DialogActions sx={{ justifyContent: "end", gap:'10px', padding:'20px' }}>
<Box onClick={handleClose} sx={{ cursor: "pointer", color: "#0D599E", fontSize:'14px', }}>
No, go back
</Box>
<Button
sx={{ background: "#FDBE16", color: "#000", borderRadius: "100px" }}
onClick={handleDelete}
variant="contained"
disabled={loading}
startIcon={loading && <CircularProgress size={20} />}
>
{loading ? "Deleting..." : "Yes"}
<Button sx={{ background:'#FDBE16', color:'#000' , borderRadius:'100px'}} onClick={handleDelete} variant="contained">
yes
</Button>
</DialogActions>
</Dialog>
Expand Down

0 comments on commit 3a50a6b

Please sign in to comment.