diff options
| author | MohamedBassem <me@mbassem.com> | 2024-03-31 16:34:52 +0100 |
|---|---|---|
| committer | MohamedBassem <me@mbassem.com> | 2024-03-31 19:27:25 +0100 |
| commit | dc6e0eab70421749faaa9a802d66c1901f3e9b50 (patch) | |
| tree | d0f7c5623fc1ce1c11c199f794009c613d5408eb /apps/web/components/dashboard | |
| parent | c0e2bdc01366f4a8878ffb373527d786e163a19b (diff) | |
| download | karakeep-dc6e0eab70421749faaa9a802d66c1901f3e9b50.tar.zst | |
feature: Add support deleting tags
Diffstat (limited to 'apps/web/components/dashboard')
| -rw-r--r-- | apps/web/components/dashboard/tags/DeleteTagButton.tsx | 59 |
1 files changed, 59 insertions, 0 deletions
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 ( + <ActionConfirmingDialog + title={`Delete ${tagName}?`} + description={`Are you sure you want to delete the tag "${tagName}"?`} + actionButton={() => ( + <ActionButton + type="button" + variant="destructive" + loading={isPending} + onClick={() => deleteTag({ tagId: tagId })} + > + Delete + </ActionButton> + )} + > + <Button className="mt-auto flex gap-2" variant="destructiveOutline"> + <Trash2 className="size-5" /> + <span className="hidden md:block">Delete Tag</span> + </Button> + </ActionConfirmingDialog> + ); +} |
