@@ -7,12 +7,19 @@ import {
7
7
DialogContent ,
8
8
DialogContentText ,
9
9
DialogTitle ,
10
- TextField ,
10
+ FormControl ,
11
+ FormHelperText ,
12
+ IconButton ,
13
+ InputAdornment ,
14
+ InputLabel ,
15
+ OutlinedInput ,
16
+ // TextField,
11
17
} from "@mui/material" ;
12
18
import Checkbox from "@mui/material/Checkbox" ;
13
19
import FormControlLabel from "@mui/material/FormControlLabel" ;
14
20
import React from "react" ;
15
21
import { StorageType , validateAndStoreAccessToken } from "../../utils/GitHubUtils" ;
22
+ import { Visibility , VisibilityOff } from "@mui/icons-material" ;
16
23
17
24
enum TokenValidationStatus {
18
25
Init = "init" ,
@@ -31,6 +38,7 @@ export default function GitHubAuthForm({ open, onClose }: GitHubAuthFormProps) {
31
38
TokenValidationStatus . Init ,
32
39
) ;
33
40
const [ storageType , setStorageType ] = React . useState < StorageType > ( StorageType . SessionStorage ) ;
41
+ const [ showAccessToken , setShowAccessToken ] = React . useState ( false ) ;
34
42
35
43
const handleStorageTypeCheckChanged = ( event : React . ChangeEvent < HTMLInputElement > ) => {
36
44
setStorageType ( event . target . checked ? StorageType . LocalStorage : StorageType . SessionStorage ) ;
@@ -60,6 +68,8 @@ export default function GitHubAuthForm({ open, onClose }: GitHubAuthFormProps) {
60
68
: "These credentials aren't stored in any server." ;
61
69
} ;
62
70
71
+ const handleClickShowAccessToken = ( ) => setShowAccessToken ( ( show ) => ! show ) ;
72
+
63
73
React . useEffect ( ( ) => {
64
74
if ( accessTokenValid === TokenValidationStatus . Valid ) {
65
75
handleClose ( ) ;
@@ -98,21 +108,34 @@ export default function GitHubAuthForm({ open, onClose }: GitHubAuthFormProps) {
98
108
</ a >
99
109
.
100
110
</ DialogContentText >
101
- < TextField
102
- autoFocus
103
- margin = "dense"
104
- id = "name"
105
- label = "GitHub Access Token"
106
- value = { accessTokenValue || "" }
107
- fullWidth
108
- variant = "standard"
109
- required
110
- error = { accessTokenValid === TokenValidationStatus . Invalid }
111
- helperText = { textFieldHelperText ( ) }
112
- onChange = { ( e ) => {
113
- setAccessTokenValue ( e . target . value ) ;
114
- } }
115
- />
111
+ < FormControl sx = { { marginTop : 2 } } fullWidth required variant = "outlined" >
112
+ < InputLabel htmlFor = "access-token-input" > GitHub Access Token</ InputLabel >
113
+ < OutlinedInput
114
+ autoFocus
115
+ margin = "dense"
116
+ id = "access-token-input"
117
+ data-testid = "access-token-input"
118
+ label = "GitHub Access Token"
119
+ type = { showAccessToken ? "text" : "password" }
120
+ value = { accessTokenValue || "" }
121
+ error = { accessTokenValid === TokenValidationStatus . Invalid }
122
+ onChange = { ( e ) => {
123
+ setAccessTokenValue ( e . target . value ) ;
124
+ } }
125
+ endAdornment = {
126
+ < InputAdornment position = "end" >
127
+ < IconButton
128
+ onClick = { handleClickShowAccessToken }
129
+ aria-label = { showAccessToken ? "Access token shown" : "Access token hidden" }
130
+ edge = "end"
131
+ >
132
+ { showAccessToken ? < VisibilityOff /> : < Visibility /> }
133
+ </ IconButton >
134
+ </ InputAdornment >
135
+ }
136
+ />
137
+ < FormHelperText id = "access-token-input" > { textFieldHelperText ( ) } </ FormHelperText >
138
+ </ FormControl >
116
139
< FormControlLabel
117
140
control = { < Checkbox onChange = { handleStorageTypeCheckChanged } /> }
118
141
label = "Save access token in local storage"
0 commit comments