@@ -6,9 +6,10 @@ import {useHistory, useLocation} from 'react-router-dom';
66
77import { parseQuery } from '../../routes' ;
88import { authenticationApi } from '../../store/reducers/authentication/authentication' ;
9+ import { useLoginWithDatabase } from '../../store/reducers/capabilities/hooks' ;
910import { cn } from '../../utils/cn' ;
1011
11- import { isPasswordError , isUserError } from './utils' ;
12+ import { isDatabaseError , isPasswordError , isUserError } from './utils' ;
1213
1314import ydbLogoIcon from '../../assets/icons/ydb.svg' ;
1415
@@ -24,28 +25,36 @@ function Authentication({closable = false}: AuthenticationProps) {
2425 const history = useHistory ( ) ;
2526 const location = useLocation ( ) ;
2627
28+ const needDatabase = useLoginWithDatabase ( ) ;
29+
2730 const [ authenticate , { isLoading} ] = authenticationApi . useAuthenticateMutation ( undefined ) ;
2831
29- const { returnUrl} = parseQuery ( location ) ;
32+ const { returnUrl, database : databaseFromQuery } = parseQuery ( location ) ;
3033
3134 const [ login , setLogin ] = React . useState ( '' ) ;
35+ const [ database , setDatabase ] = React . useState ( databaseFromQuery ?. toString ( ) ?? '' ) ;
3236 const [ password , setPass ] = React . useState ( '' ) ;
3337 const [ loginError , setLoginError ] = React . useState ( '' ) ;
3438 const [ passwordError , setPasswordError ] = React . useState ( '' ) ;
39+ const [ databaseError , setDatabaseError ] = React . useState ( '' ) ;
3540 const [ showPassword , setShowPassword ] = React . useState ( false ) ;
3641
3742 const onLoginUpdate = ( value : string ) => {
3843 setLogin ( value ) ;
3944 setLoginError ( '' ) ;
4045 } ;
46+ const onDatabaseUpdate = ( value : string ) => {
47+ setDatabase ( value ) ;
48+ setDatabaseError ( '' ) ;
49+ } ;
4150
4251 const onPassUpdate = ( value : string ) => {
4352 setPass ( value ) ;
4453 setPasswordError ( '' ) ;
4554 } ;
4655
4756 const onLoginClick = ( ) => {
48- authenticate ( { user : login , password} )
57+ authenticate ( { user : login , password, database } )
4958 . unwrap ( )
5059 . then ( ( ) => {
5160 if ( returnUrl ) {
@@ -66,6 +75,9 @@ function Authentication({closable = false}: AuthenticationProps) {
6675 if ( isPasswordError ( error ) ) {
6776 setPasswordError ( error . data . error ) ;
6877 }
78+ if ( isDatabaseError ( error ) ) {
79+ setDatabaseError ( error . data . error ) ;
80+ }
6981 } ) ;
7082 } ;
7183
@@ -125,6 +137,18 @@ function Authentication({closable = false}: AuthenticationProps) {
125137 < Icon data = { showPassword ? EyeSlash : Eye } size = { 16 } />
126138 </ Button >
127139 </ 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+ ) }
128152 < Button
129153 view = "action"
130154 onClick = { onLoginClick }
0 commit comments