From dc6e0eab70421749faaa9a802d66c1901f3e9b50 Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Sun, 31 Mar 2024 16:34:52 +0100 Subject: feature: Add support deleting tags --- .../components/dashboard/tags/DeleteTagButton.tsx | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 apps/web/components/dashboard/tags/DeleteTagButton.tsx (limited to 'apps/web/components') diff --git a/apps/web/components/dashboard/tags/DeleteTagButton.tsx b/apps/web/components/dashboard/tags/DeleteTagButton.tsx new file mode 100644 index 00000000..4cff1680 --- /dev/null +++ b/apps/web/components/dashboard/tags/DeleteTagButton.tsx @@ -0,0 +1,59 @@ +"use client"; + +import { useRouter } from "next/navigation"; +import { ActionButton } from "@/components/ui/action-button"; +import ActionConfirmingDialog from "@/components/ui/action-confirming-dialog"; +import { Button } from "@/components/ui/button"; +import { toast } from "@/components/ui/use-toast"; +import { api } from "@/lib/trpc"; +import { Trash2 } from "lucide-react"; + +export default function DeleteTagButton({ + tagName, + tagId, +}: { + tagName: string; + tagId: string; +}) { + const router = useRouter(); + + const apiUtils = api.useUtils(); + + const { mutate: deleteTag, isPending } = api.tags.delete.useMutation({ + onSuccess: () => { + apiUtils.tags.list.invalidate(); + apiUtils.bookmarks.getBookmark.invalidate(); + toast({ + description: `Tag "${tagName}" has been deleted!`, + }); + router.push("/"); + }, + onError: () => { + toast({ + variant: "destructive", + description: `Something went wrong`, + }); + }, + }); + return ( + ( + deleteTag({ tagId: tagId })} + > + Delete + + )} + > + + + ); +} -- cgit v1.2.3-70-g09d2