-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathAlertsActionsPanel.tsx
More file actions
59 lines (52 loc) · 1.71 KB
/
Copy pathAlertsActionsPanel.tsx
File metadata and controls
59 lines (52 loc) · 1.71 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
import React, { useCallback, useRef, useState } from "react";
import { Trash } from "lucide-react";
import { Button } from "@/ui/button";
import { Alert } from "@/types/alerts";
import useAlertsBatchDeleteMutation from "@/api/alerts/useAlertsBatchDeleteMutation";
import ConfirmDialog from "@/shared/ConfirmDialog/ConfirmDialog";
import TooltipWrapper from "@/shared/TooltipWrapper/TooltipWrapper";
type AlertsActionsPanelsProps = {
alerts: Alert[];
};
const AlertsActionsPanel: React.FunctionComponent<AlertsActionsPanelsProps> = ({
alerts,
}) => {
const resetKeyRef = useRef(0);
const [open, setOpen] = useState<boolean>(false);
const disabled = !alerts?.length;
const { mutate } = useAlertsBatchDeleteMutation();
const deleteAlertsHandler = useCallback(() => {
mutate({
ids: alerts.map((a) => a.id!),
});
}, [alerts, mutate]);
return (
<div className="flex items-center gap-2">
<ConfirmDialog
key={`delete-${resetKeyRef.current}`}
open={open}
setOpen={setOpen}
onConfirm={deleteAlertsHandler}
title="Delete alerts"
description="Are you sure you want to delete these alerts? This action cannot be undone."
confirmText="Delete alerts"
confirmButtonVariant="destructive"
/>
<TooltipWrapper content="Delete">
<Button
variant="outline"
size="icon-sm"
data-testid="alerts-bulk-delete-button"
onClick={() => {
setOpen(true);
resetKeyRef.current = resetKeyRef.current + 1;
}}
disabled={disabled}
>
<Trash className="size-4" />
</Button>
</TooltipWrapper>
</div>
);
};
export default AlertsActionsPanel;