@@ -11,7 +11,7 @@ import './CreateDirectoryDialog.scss';
11
11
12
12
const b = cn ( 'ydb-schema-create-directory-dialog' ) ;
13
13
14
- const relativePathInputName = 'relativePath' ;
14
+ const relativePathInputId = 'relativePath' ;
15
15
16
16
interface SchemaTreeProps {
17
17
open : boolean ;
@@ -28,14 +28,13 @@ function validateRelativePath(value: string) {
28
28
}
29
29
30
30
export function CreateDirectoryDialog ( { open, onClose, parentPath, onSuccess} : SchemaTreeProps ) {
31
- const [ showResponseError , setShowResponseError ] = React . useState ( false ) ;
32
31
const [ validationError , setValidationError ] = React . useState ( '' ) ;
33
32
const [ relativePath , setRelativePath ] = React . useState ( '' ) ;
34
33
const [ create , response ] = schemaApi . useCreateDirectoryMutation ( ) ;
35
34
36
35
const resetErrors = ( ) => {
37
36
setValidationError ( '' ) ;
38
- setShowResponseError ( false ) ;
37
+ response . reset ( ) ;
39
38
} ;
40
39
41
40
const handleUpdate = ( updated : string ) => {
@@ -50,7 +49,6 @@ export function CreateDirectoryDialog({open, onClose, parentPath, onSuccess}: Sc
50
49
} ;
51
50
52
51
const handleSubmit = ( ) => {
53
- setShowResponseError ( true ) ;
54
52
const path = `${ parentPath } /${ relativePath } ` ;
55
53
create ( {
56
54
database : parentPath ,
@@ -63,8 +61,6 @@ export function CreateDirectoryDialog({open, onClose, parentPath, onSuccess}: Sc
63
61
} ) ;
64
62
} ;
65
63
66
- const hasValidationError = Boolean ( validationError ) ;
67
-
68
64
return (
69
65
< Dialog open = { open } onClose = { handleClose } size = "s" >
70
66
< Dialog . Header caption = { i18n ( 'schema.tree.dialog.header' ) } />
@@ -79,27 +75,27 @@ export function CreateDirectoryDialog({open, onClose, parentPath, onSuccess}: Sc
79
75
} }
80
76
>
81
77
< Dialog . Body >
82
- < label htmlFor = { relativePathInputName } className = { b ( 'label' ) } >
78
+ < label htmlFor = { relativePathInputId } className = { b ( 'label' ) } >
83
79
< span className = { b ( 'description' ) } >
84
80
{ i18n ( 'schema.tree.dialog.description' ) }
85
81
</ span >
86
82
{ `${ parentPath } /` }
87
83
</ label >
88
- < TextInput
89
- placeholder = { i18n ( 'schema.tree.dialog.placeholder' ) }
90
- value = { relativePath }
91
- onUpdate = { handleUpdate }
92
- autoFocus
93
- hasClear
94
- autoComplete = { false }
95
- disabled = { response . isLoading }
96
- validationState = { validationError ? 'invalid' : undefined }
97
- name = { relativePathInputName }
98
- />
99
- < div className = { b ( 'error-wrapper' ) } >
100
- { hasValidationError && < ResponseError error = { validationError } /> }
84
+ < div className = { b ( 'input-wrapper' ) } >
85
+ < TextInput
86
+ placeholder = { i18n ( 'schema.tree.dialog.placeholder' ) }
87
+ value = { relativePath }
88
+ onUpdate = { handleUpdate }
89
+ autoFocus
90
+ hasClear
91
+ autoComplete = { false }
92
+ disabled = { response . isLoading }
93
+ validationState = { validationError ? 'invalid' : undefined }
94
+ id = { relativePathInputId }
95
+ errorMessage = { validationError }
96
+ />
101
97
</ div >
102
- { showResponseError && response . isError && (
98
+ { response . isError && (
103
99
< ResponseError
104
100
error = { response . error }
105
101
defaultMessage = { i18n ( 'schema.tree.dialog.invalid' ) }
0 commit comments