Skip to content

Commit

Permalink
fix: pat can not be copied (#5274)
Browse files Browse the repository at this point in the history
#### What type of PR is this?

/area console
/kind bug
/milestone 2.12.x

#### What this PR does / why we need it:

修复创建 PAT 之后,点击复制按钮无法复制 token 的问题。

#### Which issue(s) this PR fixes:

Fixes #5273 

#### Special notes for your reviewer:

测试步骤:

1. 构建生产环境的 UC。
2. 创建 PAT,点击复制按钮,观察是否能够正常复制。

#### Does this PR introduce a user-facing change?

```release-note
修复创建 PAT 之后,点击复制按钮无法复制 token 的问题。
```
  • Loading branch information
ruibaby committed Jan 29, 2024
1 parent 47a1aa7 commit e8a9f06
Showing 1 changed file with 9 additions and 15 deletions.
Expand Up @@ -7,7 +7,6 @@ import { Dialog, Toast, VButton, VModal, VSpace } from "@halo-dev/components";
import { useMutation, useQueryClient } from "@tanstack/vue-query";
import { useClipboard } from "@vueuse/core";
import type { PatSpec, PersonalAccessToken } from "@halo-dev/api-client";
import { computed } from "vue";
import { ref } from "vue";
import { useRoleTemplateSelection } from "@/composables/use-role";
import { useRoleStore } from "@/stores/role";
Expand Down Expand Up @@ -49,11 +48,11 @@ const { permissions } = useRoleStore();
const { roleTemplateGroups, handleRoleTemplateSelect, selectedRoleTemplates } =
useRoleTemplateSelection(toRefs(permissions).permissions);
const {
mutate,
isLoading,
data: token,
} = useMutation({
const { copy } = useClipboard({
legacy: true,
});
const { mutate, isLoading } = useMutation({
mutationKey: ["pat-creation"],
mutationFn: async () => {
if (formState.value.spec?.expiresAt) {
Expand All @@ -74,28 +73,23 @@ const {
queryClient.invalidateQueries({ queryKey: ["personal-access-tokens"] });
emit("close");
const token = data.metadata.annotations?.[patAnnotations.ACCESS_TOKEN];
setTimeout(() => {
Dialog.info({
title: t("core.uc_profile.pat.operations.copy.title"),
description: data.metadata.annotations?.[patAnnotations.ACCESS_TOKEN],
description: token,
confirmType: "secondary",
confirmText: t("core.common.buttons.copy"),
showCancel: false,
onConfirm: () => {
copy();
copy(token || "");
Toast.success(t("core.common.toast.copy_success"));
},
});
});
},
});
const { copy } = useClipboard({
source: computed(
() => token.value?.metadata.annotations?.[patAnnotations.ACCESS_TOKEN] || ""
),
legacy: true,
});
</script>

<template>
Expand Down

0 comments on commit e8a9f06

Please sign in to comment.