-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDeleteFileDialog.tsx
More file actions
81 lines (75 loc) · 2.08 KB
/
Copy pathDeleteFileDialog.tsx
File metadata and controls
81 lines (75 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"use client";
import {
Dialog,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger
} from "../ui/dialog";
import { toast } from "sonner";
import { Button } from "../ui/button";
import { deleteFile } from "@/api/files";
import { useRouter } from "next/navigation";
import { Trash2 } from "lucide-react";
interface DeleteFileDialogProps {
fileId: number;
scanReportId: number;
fileName: string;
isOpen?: boolean;
setOpen?: (isOpen: boolean) => void;
needTrigger?: boolean;
}
const DeleteFileDialog = ({
fileId,
scanReportId,
fileName,
isOpen,
setOpen = () => {},
needTrigger = false
}: DeleteFileDialogProps) => {
const router = useRouter();
const handleDelete = async () => {
const response = await deleteFile(scanReportId, fileId);
if (response.success) {
toast.success(`File "${fileName}" deleted successfully`);
router.refresh();
} else {
toast.error(
`Failed to delete file: ${response.errorMessage || "Unknown error"}`
);
}
setOpen(false);
};
return (
<Dialog open={isOpen} onOpenChange={() => setOpen(false)}>
{needTrigger && (
<DialogTrigger asChild>
<Button variant="destructive" size="sm">
<Trash2 className="h-4 w-4" />
</Button>
</DialogTrigger>
)}
<DialogContent>
<DialogHeader className="text-start">
<DialogTitle>Delete File</DialogTitle>
<DialogDescription>
Are you sure you want to delete "{fileName}"? This action cannot be
undone and will permanently remove the file from storage.
</DialogDescription>
</DialogHeader>
<DialogFooter className="flex-col space-y-2 sm:space-y-0 sm:space-x-2">
<Button variant="destructive" onClick={handleDelete}>
Delete
</Button>
<DialogClose asChild>
<Button variant="outline">Cancel</Button>
</DialogClose>
</DialogFooter>
</DialogContent>
</Dialog>
);
};
export default DeleteFileDialog;