diff --git a/frontend/package.json b/frontend/package.json index 1d0615863b..c6d400d79f 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -53,6 +53,7 @@ "@welldone-software/why-did-you-render": "6.2.1", "array-move": "3.0.1", "classnames": "2.3.1", + "copy-to-clipboard": "^3.3.1", "craco": "0.0.3", "css-loader": "6.4.0", "cypress": "8.6.0", diff --git a/frontend/src/component/api-token/ApiTokenList/ApiTokenList.tsx b/frontend/src/component/api-token/ApiTokenList/ApiTokenList.tsx index 152ee21a7b..39c30642b4 100644 --- a/frontend/src/component/api-token/ApiTokenList/ApiTokenList.tsx +++ b/frontend/src/component/api-token/ApiTokenList/ApiTokenList.tsx @@ -33,6 +33,7 @@ import ApiTokenCreate from '../ApiTokenCreate/ApiTokenCreate'; import Dialogue from '../../common/Dialogue'; import { CREATE_API_TOKEN_BUTTON } from '../../../testIds'; import { Alert } from '@material-ui/lab'; +import copy from 'copy-to-clipboard'; interface IApiToken { createdAt: Date; @@ -88,12 +89,13 @@ const ApiTokenList = ({ location }: IApiTokenList) => { }); }; const copyToken = (value: string) => { - navigator.clipboard.writeText(value); - setToastData({ - type: 'success', - show: true, - text: `Token is copied to clipboard`, - }); + if (copy(value)) { + setToastData({ + type: 'success', + show: true, + text: `Token is copied to clipboard`, + }); + } }; const onDeleteToken = async () => { diff --git a/frontend/yarn.lock b/frontend/yarn.lock index f710c73bac..abe0470939 100644 --- a/frontend/yarn.lock +++ b/frontend/yarn.lock @@ -4144,6 +4144,13 @@ copy-descriptor@^0.1.0: resolved "https://registry.npmjs.org/copy-descriptor/-/copy-descriptor-0.1.1.tgz" integrity sha1-Z29us8OZl8LuGsOpJP1hJHSPV40= +copy-to-clipboard@^3.3.1: + version "3.3.1" + resolved "https://registry.yarnpkg.com/copy-to-clipboard/-/copy-to-clipboard-3.3.1.tgz#115aa1a9998ffab6196f93076ad6da3b913662ae" + integrity sha512-i13qo6kIHTTpCm8/Wup+0b1mVWETvu2kIMzKoK8FpkLkFxlt0znUAHcMzox+T8sPlqtZXq3CulEjQHsYiGFJUw== + dependencies: + toggle-selection "^1.0.6" + core-js-compat@^3.6.2, core-js-compat@^3.8.1, core-js-compat@^3.9.0: version "3.10.0" resolved "https://registry.npmjs.org/core-js-compat/-/core-js-compat-3.10.0.tgz" @@ -12272,6 +12279,11 @@ to-regex@^3.0.1, to-regex@^3.0.2: regex-not "^1.0.2" safe-regex "^1.1.0" +toggle-selection@^1.0.6: + version "1.0.6" + resolved "https://registry.yarnpkg.com/toggle-selection/-/toggle-selection-1.0.6.tgz#6e45b1263f2017fa0acc7d89d78b15b8bf77da32" + integrity sha1-bkWxJj8gF/oKzH2J14sVuL932jI= + toidentifier@1.0.0: version "1.0.0" resolved "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz"