blob: bf1969bf1d4e2aa5750dad3c348146e3195618e5 (
plain) (
blame)
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
|
import { usePathname, useRouter } from "next/navigation";
import { ActionButton } from "@/components/ui/action-button";
import ActionConfirmingDialog from "@/components/ui/action-confirming-dialog";
import { toast } from "@/components/ui/use-toast";
import type { ZBookmarkList } from "@hoarder/shared/types/lists";
import { useDeleteBookmarkList } from "@hoarder/shared-react/hooks/lists";
export default function DeleteListConfirmationDialog({
list,
children,
open,
setOpen,
}: {
list: ZBookmarkList;
children?: React.ReactNode;
open: boolean;
setOpen: (v: boolean) => void;
}) {
const currentPath = usePathname();
const router = useRouter();
const { mutate: deleteList, isPending } = useDeleteBookmarkList({
onSuccess: () => {
toast({
description: `List "${list.icon} ${list.name}" is deleted!`,
});
setOpen(false);
if (currentPath.includes(list.id)) {
router.push("/dashboard/lists");
}
},
onError: () => {
toast({
variant: "destructive",
description: `Something went wrong`,
});
},
});
return (
<ActionConfirmingDialog
open={open}
setOpen={setOpen}
title={`Delete ${list.icon} ${list.name}?`}
description={`Are you sure you want to delete ${list.icon} ${list.name}?`}
actionButton={() => (
<ActionButton
type="button"
variant="destructive"
loading={isPending}
onClick={() => deleteList({ listId: list.id })}
>
Delete
</ActionButton>
)}
>
{children}
</ActionConfirmingDialog>
);
}
|