From f476fca758bb039f9605488b61ba35fc097d6cfc Mon Sep 17 00:00:00 2001 From: Nicole Li <40200356+lexafaxine@users.noreply.github.com> Date: Tue, 31 Dec 2024 19:33:41 +0900 Subject: feat: Add delete bookmark confirmation dialog. Fixes #776 (#787) --- .../bookmarks/DeleteBookmarkConfirmationDialog.tsx | 63 ++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 apps/web/components/dashboard/bookmarks/DeleteBookmarkConfirmationDialog.tsx (limited to 'apps/web/components/dashboard/bookmarks/DeleteBookmarkConfirmationDialog.tsx') diff --git a/apps/web/components/dashboard/bookmarks/DeleteBookmarkConfirmationDialog.tsx b/apps/web/components/dashboard/bookmarks/DeleteBookmarkConfirmationDialog.tsx new file mode 100644 index 00000000..4a69e3d0 --- /dev/null +++ b/apps/web/components/dashboard/bookmarks/DeleteBookmarkConfirmationDialog.tsx @@ -0,0 +1,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 "@hoarder/shared-react/hooks//bookmarks"; +import { ZBookmark } from "@hoarder/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 ( + ( + deleteBoomark({ bookmarkId: bookmark.id })} + > + Delete + + )} + > + {children} + + ); +} -- cgit v1.2.3-70-g09d2