aboutsummaryrefslogtreecommitdiffstats
path: root/apps/web/components/dashboard/lists/DeleteListConfirmationDialog.tsx
diff options
context:
space:
mode:
authorMohamed Bassem <me@mbassem.com>2024-04-19 00:09:27 +0100
committerGitHub <noreply@github.com>2024-04-19 00:09:27 +0100
commite0999f701cd1834c3d940113cd8dd5247c5fe95f (patch)
treec4169a564ecd3f933e711bcc8ef7db20532174ea /apps/web/components/dashboard/lists/DeleteListConfirmationDialog.tsx
parentdeba31ee010f785a9739fd4df8a64a3056c9593d (diff)
downloadkarakeep-e0999f701cd1834c3d940113cd8dd5247c5fe95f.tar.zst
feature: Nested lists (#110). Fixes #62
* feature: Add support for nested lists * prevent moving the parent to a subtree
Diffstat (limited to 'apps/web/components/dashboard/lists/DeleteListConfirmationDialog.tsx')
-rw-r--r--apps/web/components/dashboard/lists/DeleteListConfirmationDialog.tsx61
1 files changed, 61 insertions, 0 deletions
diff --git a/apps/web/components/dashboard/lists/DeleteListConfirmationDialog.tsx b/apps/web/components/dashboard/lists/DeleteListConfirmationDialog.tsx
new file mode 100644
index 00000000..bf1969bf
--- /dev/null
+++ b/apps/web/components/dashboard/lists/DeleteListConfirmationDialog.tsx
@@ -0,0 +1,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>
+ );
+}