@@ -6,9 +6,10 @@ import {useHistory, useLocation} from 'react-router-dom';
6
6
7
7
import { parseQuery } from '../../routes' ;
8
8
import { authenticationApi } from '../../store/reducers/authentication/authentication' ;
9
+ import { useLoginWithDatabase } from '../../store/reducers/capabilities/hooks' ;
9
10
import { cn } from '../../utils/cn' ;
10
11
11
- import { isPasswordError , isUserError } from './utils' ;
12
+ import { isDatabaseError , isPasswordError , isUserError } from './utils' ;
12
13
13
14
import ydbLogoIcon from '../../assets/icons/ydb.svg' ;
14
15
@@ -24,28 +25,36 @@ function Authentication({closable = false}: AuthenticationProps) {
24
25
const history = useHistory ( ) ;
25
26
const location = useLocation ( ) ;
26
27
28
+ const needDatabase = useLoginWithDatabase ( ) ;
29
+
27
30
const [ authenticate , { isLoading} ] = authenticationApi . useAuthenticateMutation ( undefined ) ;
28
31
29
- const { returnUrl} = parseQuery ( location ) ;
32
+ const { returnUrl, database : databaseFromQuery } = parseQuery ( location ) ;
30
33
31
34
const [ login , setLogin ] = React . useState ( '' ) ;
35
+ const [ database , setDatabase ] = React . useState ( databaseFromQuery ?. toString ( ) ?? '' ) ;
32
36
const [ password , setPass ] = React . useState ( '' ) ;
33
37
const [ loginError , setLoginError ] = React . useState ( '' ) ;
34
38
const [ passwordError , setPasswordError ] = React . useState ( '' ) ;
39
+ const [ databaseError , setDatabaseError ] = React . useState ( '' ) ;
35
40
const [ showPassword , setShowPassword ] = React . useState ( false ) ;
36
41
37
42
const onLoginUpdate = ( value : string ) => {
38
43
setLogin ( value ) ;
39
44
setLoginError ( '' ) ;
40
45
} ;
46
+ const onDatabaseUpdate = ( value : string ) => {
47
+ setDatabase ( value ) ;
48
+ setDatabaseError ( '' ) ;
49
+ } ;
41
50
42
51
const onPassUpdate = ( value : string ) => {
43
52
setPass ( value ) ;
44
53
setPasswordError ( '' ) ;
45
54
} ;
46
55
47
56
const onLoginClick = ( ) => {
48
- authenticate ( { user : login , password} )
57
+ authenticate ( { user : login , password, database } )
49
58
. unwrap ( )
50
59
. then ( ( ) => {
51
60
if ( returnUrl ) {
@@ -66,6 +75,9 @@ function Authentication({closable = false}: AuthenticationProps) {
66
75
if ( isPasswordError ( error ) ) {
67
76
setPasswordError ( error . data . error ) ;
68
77
}
78
+ if ( isDatabaseError ( error ) ) {
79
+ setDatabaseError ( error . data . error ) ;
80
+ }
69
81
} ) ;
70
82
} ;
71
83
@@ -125,6 +137,18 @@ function Authentication({closable = false}: AuthenticationProps) {
125
137
< Icon data = { showPassword ? EyeSlash : Eye } size = { 16 } />
126
138
</ Button >
127
139
</ div >
140
+ { needDatabase && (
141
+ < div className = { b ( 'field-wrapper' ) } >
142
+ < TextInput
143
+ value = { database }
144
+ onUpdate = { onDatabaseUpdate }
145
+ placeholder = { 'Database' }
146
+ error = { databaseError }
147
+ onKeyDown = { onEnterClick }
148
+ size = "l"
149
+ />
150
+ </ div >
151
+ ) }
128
152
< Button
129
153
view = "action"
130
154
onClick = { onLoginClick }
0 commit comments