From d39848af24bc257688c0a8235726c37d207c59bb Mon Sep 17 00:00:00 2001 From: Kunaldevxxx Date: Thu, 12 Dec 2024 13:06:44 +0530 Subject: [PATCH 1/6] feat: Create Display Delete API Integrated --- src/app/platform/keys/create/page.tsx | 81 ++++++---- src/app/platform/keys/list/page.tsx | 205 ++++++++++++++++---------- 2 files changed, 182 insertions(+), 104 deletions(-) diff --git a/src/app/platform/keys/create/page.tsx b/src/app/platform/keys/create/page.tsx index 7c102f1..a5b1ba1 100644 --- a/src/app/platform/keys/create/page.tsx +++ b/src/app/platform/keys/create/page.tsx @@ -5,10 +5,11 @@ import { KeyIcon, ClipboardCopyIcon, CheckIcon } from "lucide-react"; import MainHeader from "../../components/header"; import Sidebar from "../../components/sidebar"; import { ApiKeyNavigations } from "../navigations"; + const Page = () => { const [name, setName] = useState(""); const [description, setDescription] = useState(""); - const [expiry, setExpiry] = useState(""); + const [expiryDays, setExpiry] = useState(""); const [apiKey, setApiKey] = useState(""); const [notification, setNotification] = useState(""); const [copied, setCopied] = useState(false); @@ -16,13 +17,25 @@ const Page = () => { const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); try { - const response = await new Promise<{ apiKey: string }>((resolve) => - setTimeout(() => resolve({ apiKey: "12345-ABCDE" }), 1000) - ); - setApiKey(response.apiKey); + const response = await fetch("/api/platform/keys", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ name, description, expiryDays: parseInt(expiryDays, 10) }), + }); + + if (!response.ok) { + const errorData = await response.json(); + throw new Error(errorData.message || "Failed to create API key."); + } + + const data = await response.json(); + setApiKey(data.apiKey); setNotification("success"); - } catch { + } catch (err) { setNotification("error"); + console.error("Error creating API key:", err); } }; @@ -41,14 +54,21 @@ const Page = () => {
- Create New API Key + + Manage API Keys + -
+
- + {
- +