From 0d2352aa9329162707a200f8de38da15e2dfd6d6 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 3 Oct 2024 05:06:11 +0530 Subject: [PATCH] fix: get back actions --- src/components/organisms/ApiKey.tsx | 116 +++++++++++++++------------- 1 file changed, 63 insertions(+), 53 deletions(-) diff --git a/src/components/organisms/ApiKey.tsx b/src/components/organisms/ApiKey.tsx index b76a4551..8fa9707e 100644 --- a/src/components/organisms/ApiKey.tsx +++ b/src/components/organisms/ApiKey.tsx @@ -2,14 +2,18 @@ import React, { useState, useEffect } from 'react'; import { Box, Button, - TextField, Typography, IconButton, - InputAdornment, - Tooltip, CircularProgress, + Table, + TableBody, + TableCell, + TableContainer, + TableHead, + TableRow, + Tooltip, } from '@mui/material'; -import { ContentCopy } from '@mui/icons-material'; +import { ContentCopy, Visibility, Delete } from '@mui/icons-material'; import styled from 'styled-components'; import axios from 'axios'; import { useGlobalInfoStore } from '../../context/globalInfo'; @@ -21,28 +25,12 @@ const Container = styled(Box)` margin-top: 50px; `; -const ApiKeyField = styled(TextField)` - width: 400px; - margin: 20px 0; -`; - -const HiddenText = styled(Typography)` - color: #888; - font-style: italic; -`; - -const CenteredContent = styled(Box)` - display: flex; - flex-direction: column; - align-items: center; - margin-top: 20px; -`; - const ApiKeyManager = () => { const [apiKey, setApiKey] = useState(null); + const [apiKeyName, setApiKeyName] = useState('Maxun API Key'); const [loading, setLoading] = useState(true); + const [showKey, setShowKey] = useState(false); const [copySuccess, setCopySuccess] = useState(false); - const { notify } = useGlobalInfoStore(); useEffect(() => { @@ -73,6 +61,19 @@ const ApiKeyManager = () => { } }; + const deleteApiKey = async () => { + setLoading(true); + try { + await axios.delete('http://localhost:8080/auth/delete-api-key'); + setApiKey(null); + notify('success', 'API Key deleted successfully'); + } catch (error) { + console.error('Error deleting API key', error); + } finally { + setLoading(false); + } + }; + const copyToClipboard = () => { if (apiKey) { navigator.clipboard.writeText(apiKey); @@ -88,43 +89,52 @@ const ApiKeyManager = () => { Manage Your API Key {apiKey ? ( - <> - - - - - - ), - }} - /> - + + + + + API Key Name + API Key + Actions + + + + + {apiKeyName} + {showKey ? apiKey : '****************'} + + + + + + + + setShowKey(!showKey)}> + + + + + + + + + + + +
{copySuccess && ( - - - Copied to Clipboard - - + + Copied to Clipboard + )} - +
) : ( - + <> You haven't generated an API key yet. - - + )} );