aboutsummaryrefslogtreecommitdiffstats
path: root/apps/web/components/dashboard/bookmarks/DeleteBookmarkConfirmationDialog.tsx
blob: 7e6807065cd04c50d5deb07c2f9ed8ef4dbc7f64 (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
62
63
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 { useTranslation } from "@/lib/i18n/client";

import { useDeleteBookmark } from "@karakeep/shared-react/hooks//bookmarks";
import { ZBookmark } from "@karakeep/shared/types/bookmarks";

export default function DeleteBookmarkConfirmationDialog({
  bookmark,
  children,
  open,
  setOpen,
}: {
  bookmark: ZBookmark;
  children?: React.ReactNode;
  open: boolean;
  setOpen: (v: boolean) => void;
}) {
  const { t } = useTranslation();
  const currentPath = usePathname();
  const router = useRouter();

  const { mutate: deleteBoomark, isPending } = useDeleteBookmark({
    onSuccess: () => {
      toast({
        description: t("toasts.bookmarks.deleted"),
      });
      setOpen(false);
      if (currentPath.includes(bookmark.id)) {
        router.push("/dashboard/bookmarks");
      }
    },
    onError: () => {
      toast({
        variant: "destructive",
        description: `Something went wrong`,
      });
    },
  });

  return (
    <ActionConfirmingDialog
      open={open}
      setOpen={setOpen}
      title={t("dialogs.bookmarks.delete_confirmation_title")}
      description={t("dialogs.bookmarks.delete_confirmation_description")}
      actionButton={() => (
        <ActionButton
          type="button"
          variant="destructive"
          loading={isPending}
          onClick={() => deleteBoomark({ bookmarkId: bookmark.id })}
        >
          Delete
        </ActionButton>
      )}
    >
      {children}
    </ActionConfirmingDialog>
  );
}