From 455025b9258dc4358c37d24d041336ddbaf458e2 Mon Sep 17 00:00:00 2001 From: Alex-zReeZ Date: Fri, 5 Jul 2024 11:44:29 +0200 Subject: [PATCH] refactor: added button to show esp jwt token --- .../src/app/ui/dashboard/RenameElement.tsx | 86 +++++++++++++------ 1 file changed, 62 insertions(+), 24 deletions(-) diff --git a/nextjs-interface/src/app/ui/dashboard/RenameElement.tsx b/nextjs-interface/src/app/ui/dashboard/RenameElement.tsx index e3a0546..c61e38b 100644 --- a/nextjs-interface/src/app/ui/dashboard/RenameElement.tsx +++ b/nextjs-interface/src/app/ui/dashboard/RenameElement.tsx @@ -12,6 +12,9 @@ import { export default function RenameElement({ id }: { id: string }) { const [newName, setNewName] = useState(""); const [confirm, setConfirm] = React.useState(false); + const [showToken, setShowToken] = useState(false); + const token = getToken(); + const updateEspName = async (newName: string) => { const url = `/postgrest/esp?id=eq.${id}`; const response = await fetch(url, { @@ -30,40 +33,75 @@ export default function RenameElement({ id }: { id: string }) { } else { } }; + + const copyToClipboard = (text: string) => { + navigator.clipboard + .writeText(text) + .then(() => { + console.log("Token copied to clipboard"); + }) + .catch((err) => { + console.error("Failed to copy token: ", err); + }); + }; + + const toggleAndCopyToken = () => { + setShowToken(!showToken); + if (!showToken && token) { + copyToClipboard(token); + } else { + return null; + } + }; + return (
- - { - setNewName(e.target.value); - setConfirm(true); - }} - /> - {confirm ? ( - + )} +
+
+ - ) : ( - "" - )} + {showToken && ( +
+ Token copier !:
+ {token} +
+ )} +