Skip to content

Commit

Permalink
feat(user): add copy to clipboard for tokens (#4210)
Browse files Browse the repository at this point in the history
  • Loading branch information
chinook25 authored Sep 13, 2024
1 parent 2c5879c commit 2923727
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions apps/molgenis-components/src/components/account/TokenManager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,22 @@
</div>
<MessageSuccess v-if="successMessage">
{{ successMessage }}.
<div v-if="lastTokenValue">
<label><b>New token. Please copy for use</b></label>
<pre>{{ lastTokenValue }}</pre>
<div v-if="lastTokenValue" style="cursor: pointer">
<label>
<b>
New token. Please copy for use:
<Tooltip
value="Click to copy to clipboard"
placement="top"
@click.prevent="copyToClipboard(lastTokenValue)"
>
<i id="copy-icon" class="fa fa-clipboard" />
</Tooltip>
</b>
</label>
<pre @click.prevent="copyToClipboard(lastTokenValue)">
{{ lastTokenValue }}
</pre>
</div>
</MessageSuccess>
<MessageError v-if="errorMessage">{{ errorMessage }}</MessageError>
Expand All @@ -38,16 +51,17 @@
</template>

<script lang="ts">
import { ISetting } from "metadata-utils";
import { defineComponent } from "vue";
import { request } from "../../client/client.js";
import { IError } from "../../Interfaces/IError";
import { ISetting } from "metadata-utils";
import ButtonAction from "../forms/ButtonAction.vue";
import IconDanger from "../forms/IconDanger.vue";
import InputString from "../forms/InputString.vue";
import MessageError from "../forms/MessageError.vue";
import MessageSuccess from "../forms/MessageSuccess.vue";
import { ISession, IResponse } from "./Interfaces";
import { IResponse, ISession } from "./Interfaces";
import Tooltip from "../forms/Tooltip.vue";
const query = `{_session { email, token, settings{key,value}}}`;
const changeMutation = `mutation change($users:[UsersInput]){
Expand All @@ -67,6 +81,7 @@ export default defineComponent({
IconDanger,
MessageSuccess,
MessageError,
Tooltip,
},
data() {
return {
Expand All @@ -75,7 +90,6 @@ export default defineComponent({
lastTokenValue: "",
errorMessage: "",
successMessage: "",
duplicateNameMessage: "",
};
},
computed: {
Expand All @@ -90,13 +104,11 @@ export default defineComponent({
.filter((value: string): boolean => value !== "")
: [];
},
},
watch: {
tokenName() {
duplicateNameMessage(): string {
if (this.accessTokens.includes(this.tokenName)) {
this.duplicateNameMessage = "Duplicate token name";
return "Duplicate token name";
} else {
this.duplicateNameMessage = "";
return "";
}
},
},
Expand Down Expand Up @@ -153,6 +165,9 @@ export default defineComponent({
this.errorMessage = error.message;
});
},
copyToClipboard(token: string) {
navigator.clipboard.writeText(token);
},
},
mounted() {
this.fetchSession();
Expand Down

0 comments on commit 2923727

Please sign in to comment.