@@ -14,6 +14,8 @@ import CreateApiKeyModal from "./CreateApiKeyModal";
14
14
import { fetchApiKeysAction } from "redux/reduxActions/userActions" ;
15
15
import UserApi from "@lowcoder-ee/api/userApi" ;
16
16
import { validateResponse } from "@lowcoder-ee/api/apiUtils" ;
17
+ import Alert from "antd/es/alert" ;
18
+ import { CopyOutlined } from "@ant-design/icons" ;
17
19
18
20
const TableStyled = styled ( Table ) `
19
21
.ant-table-tbody > tr > td {
@@ -37,10 +39,16 @@ const CreateButton = styled(TacoButton)`
37
39
box-shadow: none;
38
40
` ;
39
41
42
+ export type ApiKeyType = {
43
+ id : string ;
44
+ token : string ;
45
+ }
46
+
40
47
export default function UserApiKeysCard ( ) {
41
48
const dispatch = useDispatch ( ) ;
42
49
const apiKeys = useSelector ( getApiKeys ) ;
43
50
const [ modalVisible , setModalVisible ] = useState ( false ) ;
51
+ const [ newApiKey , setNewApiKey ] = useState < ApiKeyType > ( ) ;
44
52
45
53
const handleCopy = ( value : string ) => {
46
54
navigator . clipboard . writeText ( value ) . then ( ( ) => {
@@ -66,13 +74,11 @@ export default function UserApiKeysCard() {
66
74
{ trans ( "profile.createApiKey" ) }
67
75
</ CreateButton >
68
76
</ Flex >
77
+ { Boolean ( newApiKey ) && < Alert message = { trans ( "profile.apiKeyInfo" ) } type = "info" style = { { marginBottom : '16px' } } /> }
69
78
< TableStyled
70
79
tableLayout = { "auto" }
71
80
scroll = { { x : "100%" } }
72
81
pagination = { false }
73
- onRow = { ( record ) => ( {
74
-
75
- } ) }
76
82
columns = { [
77
83
{
78
84
title : trans ( "profile.apiKeyName" ) ,
@@ -95,16 +101,19 @@ export default function UserApiKeysCard() {
95
101
title : trans ( "profile.apiKey" ) ,
96
102
dataIndex : "token" ,
97
103
ellipsis : true ,
98
- render : ( value : string ) => {
99
- const startToken = value . substring ( 0 , 6 ) ;
100
- const endToken = value . substring ( value . length - 6 ) ;
101
- return (
102
- < Tooltip placement = "topLeft" title = { trans ( "profile.apiKeyCopy" ) } >
103
- < div onClick = { ( ) => handleCopy ( value ) } style = { { cursor : 'pointer' } } >
104
- { `${ startToken } ********************${ endToken } ` }
105
- </ div >
106
- </ Tooltip >
107
- )
104
+ render : ( value : string , record : any ) => {
105
+ if ( newApiKey ?. id === record . id ) {
106
+ return (
107
+ < Tooltip placement = "topLeft" title = { trans ( "profile.apiKeyCopy" ) } >
108
+ < div onClick = { ( ) => handleCopy ( newApiKey ?. token ! ) } style = { { cursor : 'pointer' } } >
109
+ { value }
110
+
111
+ < CopyOutlined />
112
+ </ div >
113
+ </ Tooltip >
114
+ )
115
+ }
116
+ return < div > { value } </ div >
108
117
}
109
118
} ,
110
119
{ title : " " , dataIndex : "operation" , width : "208px" } ,
@@ -145,8 +154,9 @@ export default function UserApiKeysCard() {
145
154
< CreateApiKeyModal
146
155
modalVisible = { modalVisible }
147
156
closeModal = { ( ) => setModalVisible ( false ) }
148
- onConfigCreate = { ( ) => {
157
+ onConfigCreate = { ( apiKey ?: ApiKeyType ) => {
149
158
setModalVisible ( false ) ;
159
+ setNewApiKey ( apiKey ) ;
150
160
dispatch ( fetchApiKeysAction ( ) ) ;
151
161
} }
152
162
/>
0 commit comments