diff --git a/dashboard/src/components/EnvComponents/JWTConfiguration.tsx b/dashboard/src/components/EnvComponents/JWTConfiguration.tsx index 4424725..a7c8b89 100644 --- a/dashboard/src/components/EnvComponents/JWTConfiguration.tsx +++ b/dashboard/src/components/EnvComponents/JWTConfiguration.tsx @@ -1,154 +1,202 @@ -import React from "react"; -import { Flex, Stack, Center, Text, useMediaQuery } from "@chakra-ui/react"; +import React from 'react'; import { - HiddenInputType, - TextInputType, - TextAreaInputType, -} from "../../constants"; -import GenerateKeysModal from "../GenerateKeysModal"; -import InputField from "../InputField"; + Flex, + Stack, + Center, + Text, + useMediaQuery, + Button, + useToast, +} from '@chakra-ui/react'; +import { + HiddenInputType, + TextInputType, + TextAreaInputType, +} from '../../constants'; +import GenerateKeysModal from '../GenerateKeysModal'; +import InputField from '../InputField'; +import { copyTextToClipboard } from '../../utils'; const JSTConfigurations = ({ - variables, - setVariables, - fieldVisibility, - setFieldVisibility, - SelectInputType, - getData, - HMACEncryptionType, - RSAEncryptionType, - ECDSAEncryptionType, + variables, + setVariables, + fieldVisibility, + setFieldVisibility, + SelectInputType, + getData, + HMACEncryptionType, + RSAEncryptionType, + ECDSAEncryptionType, }: any) => { - const [isNotSmallerScreen] = useMediaQuery("(min-width:600px)"); + const [isNotSmallerScreen] = useMediaQuery('(min-width:600px)'); + const toast = useToast(); - return ( -
- {" "} - - - JWT (JSON Web Tokens) Configurations - - - - - - - - - JWT Type: - - - - - - {Object.values(HMACEncryptionType).includes(variables.JWT_TYPE) ? ( - - - JWT Secret - -
- -
-
- ) : ( - <> - - - Public Key - -
- -
-
- - - Private Key - -
- -
-
- - )} - - - - JWT Role Claim: - - -
- -
-
-
-
- ); + const copyJSON = async () => { + console.log(variables); + try { + await copyTextToClipboard( + JSON.stringify({ + type: variables.JWT_TYPE, + key: variables.JWT_PUBLIC_KEY || variables.JWT_SECRET, + }) + ); + toast({ + title: `JWT config copied successfully`, + isClosable: true, + status: 'success', + position: 'bottom-right', + }); + } catch (err) { + console.error({ + message: `Failed to copy JWT config`, + error: err, + }); + toast({ + title: `Failed to copy JWT config`, + isClosable: true, + status: 'error', + position: 'bottom-right', + }); + } + }; + + return ( +
+ {' '} + + + JWT (JSON Web Tokens) Configurations + + + + + + + + + + JWT Type: + + + + + + {Object.values(HMACEncryptionType).includes(variables.JWT_TYPE) ? ( + + + JWT Secret + +
+ +
+
+ ) : ( + <> + + + Public Key + +
+ +
+
+ + + Private Key + +
+ +
+
+ + )} + + + + JWT Role Claim: + + +
+ +
+
+
+
+ ); }; -export default JSTConfigurations; \ No newline at end of file +export default JSTConfigurations; diff --git a/dashboard/src/utils/index.ts b/dashboard/src/utils/index.ts index eccc7a8..0146d31 100644 --- a/dashboard/src/utils/index.ts +++ b/dashboard/src/utils/index.ts @@ -29,19 +29,16 @@ const fallbackCopyTextToClipboard = (text: string) => { document.body.removeChild(textArea); }; -export const copyTextToClipboard = (text: string) => { +export const copyTextToClipboard = async (text: string) => { if (!navigator.clipboard) { fallbackCopyTextToClipboard(text); return; } - navigator.clipboard.writeText(text).then( - () => { - console.log('Async: Copying to clipboard was successful!'); - }, - (err) => { - console.error('Async: Could not copy text: ', err); - } - ); + try { + navigator.clipboard.writeText(text); + } catch (err) { + throw err; + } }; export const getObjectDiff = (obj1: any, obj2: any) => {