aboutsummaryrefslogtreecommitdiffstats
path: root/packages/web/app/dashboard/settings/components/DeleteApiKey.tsx
diff options
context:
space:
mode:
authorMohamedBassem <me@mbassem.com>2024-02-12 14:52:00 +0000
committerMohamedBassem <me@mbassem.com>2024-02-12 14:55:00 +0000
commit6aacc0c7a86e36c52a3c2c1d26fe58cefcd3bec4 (patch)
treebad306e872d6bfcc2c67f00caa3880c8aa56070f /packages/web/app/dashboard/settings/components/DeleteApiKey.tsx
parent230cafb6dfc8d3bad57d84ef13c3669f5bf5331a (diff)
downloadkarakeep-6aacc0c7a86e36c52a3c2c1d26fe58cefcd3bec4.tar.zst
feature: Add support for managing API keys
Diffstat (limited to 'packages/web/app/dashboard/settings/components/DeleteApiKey.tsx')
-rw-r--r--packages/web/app/dashboard/settings/components/DeleteApiKey.tsx65
1 files changed, 65 insertions, 0 deletions
diff --git a/packages/web/app/dashboard/settings/components/DeleteApiKey.tsx b/packages/web/app/dashboard/settings/components/DeleteApiKey.tsx
new file mode 100644
index 00000000..715b7a2c
--- /dev/null
+++ b/packages/web/app/dashboard/settings/components/DeleteApiKey.tsx
@@ -0,0 +1,65 @@
+"use client";
+
+import { Button } from "@/components/ui/button";
+import { Trash } from "lucide-react";
+
+import {
+ Dialog,
+ DialogClose,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+ DialogTrigger,
+} from "@/components/ui/dialog";
+import { api } from "@/lib/trpc";
+import { useRouter } from "next/navigation";
+import { toast } from "@/components/ui/use-toast";
+
+export default function DeleteApiKey({
+ name,
+ id,
+}: {
+ name: string;
+ id: string;
+}) {
+ const router = useRouter();
+ const deleteKey = async () => {
+ await api.apiKeys.revoke.mutate({ id });
+ toast({
+ description: "Key was successfully deleted",
+ });
+ router.refresh();
+ };
+ return (
+ <Dialog>
+ <DialogTrigger asChild>
+ <Button variant="destructive">
+ <Trash className="size-5" />
+ </Button>
+ </DialogTrigger>
+ <DialogContent>
+ <DialogHeader>
+ <DialogTitle>Delete API Key</DialogTitle>
+ <DialogDescription>
+ Are you sure you want to delete the API key &quot;{name}&quot;? Any
+ service using this API key will lose access.
+ </DialogDescription>
+ </DialogHeader>
+ <DialogFooter className="sm:justify-end">
+ <DialogClose asChild>
+ <Button type="button" variant="secondary">
+ Close
+ </Button>
+ </DialogClose>
+ <DialogClose asChild>
+ <Button type="button" variant="destructive" onClick={deleteKey}>
+ Delete
+ </Button>
+ </DialogClose>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+ );
+}