From 6febe13b3f4ad4eff3f205ece445b3577255bf41 Mon Sep 17 00:00:00 2001
From: MohamedBassem <me@mbassem.com>
Date: Fri, 16 Feb 2024 20:33:00 +0000
Subject: Migrating to react query for client side queries

---
 .../dashboard/settings/components/DeleteApiKey.tsx | 24 ++++++++++++++--------
 1 file changed, 15 insertions(+), 9 deletions(-)

(limited to 'packages/web/app/dashboard/settings/components/DeleteApiKey.tsx')

diff --git a/packages/web/app/dashboard/settings/components/DeleteApiKey.tsx b/packages/web/app/dashboard/settings/components/DeleteApiKey.tsx
index 715b7a2c..bc3e3c92 100644
--- a/packages/web/app/dashboard/settings/components/DeleteApiKey.tsx
+++ b/packages/web/app/dashboard/settings/components/DeleteApiKey.tsx
@@ -13,9 +13,9 @@ import {
   DialogTitle,
   DialogTrigger,
 } from "@/components/ui/dialog";
-import { api } from "@/lib/trpc";
 import { useRouter } from "next/navigation";
 import { toast } from "@/components/ui/use-toast";
+import { api } from "@/lib/trpc";
 
 export default function DeleteApiKey({
   name,
@@ -25,13 +25,15 @@ export default function DeleteApiKey({
   id: string;
 }) {
   const router = useRouter();
-  const deleteKey = async () => {
-    await api.apiKeys.revoke.mutate({ id });
-    toast({
-      description: "Key was successfully deleted",
-    });
-    router.refresh();
-  };
+  const mutator = api.apiKeys.revoke.useMutation({
+    onSuccess: () => {
+      toast({
+        description: "Key was successfully deleted",
+      });
+      router.refresh();
+    },
+  });
+
   return (
     <Dialog>
       <DialogTrigger asChild>
@@ -54,7 +56,11 @@ export default function DeleteApiKey({
             </Button>
           </DialogClose>
           <DialogClose asChild>
-            <Button type="button" variant="destructive" onClick={deleteKey}>
+            <Button
+              type="button"
+              variant="destructive"
+              onClick={() => mutator.mutate({ id })}
+            >
               Delete
             </Button>
           </DialogClose>
-- 
cgit v1.2.3-70-g09d2

