@@ -14,6 +14,8 @@ import CreateApiKeyModal from "./CreateApiKeyModal";
1414import { fetchApiKeysAction } from "redux/reduxActions/userActions" ;
1515import UserApi from "@lowcoder-ee/api/userApi" ;
1616import { validateResponse } from "@lowcoder-ee/api/apiUtils" ;
17+ import Alert from "antd/es/alert" ;
18+ import { CopyOutlined } from "@ant-design/icons" ;
1719
1820const TableStyled = styled ( Table ) `
1921 .ant-table-tbody > tr > td {
@@ -37,10 +39,16 @@ const CreateButton = styled(TacoButton)`
3739 box-shadow: none;
3840` ;
3941
42+ export type ApiKeyType = {
43+ id : string ;
44+ token : string ;
45+ }
46+
4047export default function UserApiKeysCard ( ) {
4148 const dispatch = useDispatch ( ) ;
4249 const apiKeys = useSelector ( getApiKeys ) ;
4350 const [ modalVisible , setModalVisible ] = useState ( false ) ;
51+ const [ newApiKey , setNewApiKey ] = useState < ApiKeyType > ( ) ;
4452
4553 const handleCopy = ( value : string ) => {
4654 navigator . clipboard . writeText ( value ) . then ( ( ) => {
@@ -66,13 +74,11 @@ export default function UserApiKeysCard() {
6674 { trans ( "profile.createApiKey" ) }
6775 </ CreateButton >
6876 </ Flex >
77+ { Boolean ( newApiKey ) && < Alert message = { trans ( "profile.apiKeyInfo" ) } type = "info" style = { { marginBottom : '16px' } } /> }
6978 < TableStyled
7079 tableLayout = { "auto" }
7180 scroll = { { x : "100%" } }
7281 pagination = { false }
73- onRow = { ( record ) => ( {
74-
75- } ) }
7682 columns = { [
7783 {
7884 title : trans ( "profile.apiKeyName" ) ,
@@ -95,16 +101,19 @@ export default function UserApiKeysCard() {
95101 title : trans ( "profile.apiKey" ) ,
96102 dataIndex : "token" ,
97103 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 >
108117 }
109118 } ,
110119 { title : " " , dataIndex : "operation" , width : "208px" } ,
@@ -145,8 +154,9 @@ export default function UserApiKeysCard() {
145154 < CreateApiKeyModal
146155 modalVisible = { modalVisible }
147156 closeModal = { ( ) => setModalVisible ( false ) }
148- onConfigCreate = { ( ) => {
157+ onConfigCreate = { ( apiKey ?: ApiKeyType ) => {
149158 setModalVisible ( false ) ;
159+ setNewApiKey ( apiKey ) ;
150160 dispatch ( fetchApiKeysAction ( ) ) ;
151161 } }
152162 />
0 commit comments