@@ -28,6 +28,7 @@ import {
28
28
useContext ,
29
29
useEffect ,
30
30
useId ,
31
+ useRef ,
31
32
useState ,
32
33
} from "react" ;
33
34
import { getFormHelpers , nameValidator } from "utils/formUtils" ;
@@ -103,6 +104,7 @@ export const CreateWorkspacePageViewExperimental: FC<
103
104
) ;
104
105
const [ showPresetParameters , setShowPresetParameters ] = useState ( false ) ;
105
106
const id = useId ( ) ;
107
+ const workspaceNameInputRef = useRef < HTMLInputElement > ( null ) ;
106
108
const rerollSuggestedName = useCallback ( ( ) => {
107
109
setSuggestedName ( ( ) => generateWorkspaceName ( ) ) ;
108
110
} , [ ] ) ;
@@ -140,10 +142,15 @@ export const CreateWorkspacePageViewExperimental: FC<
140
142
}
141
143
} , [ error ] ) ;
142
144
143
- const getFieldHelpers = getFormHelpers < TypesGen . CreateWorkspaceRequest > (
144
- form ,
145
- error ,
146
- ) ;
145
+ useEffect ( ( ) => {
146
+ if ( form . submitCount > 0 && form . errors ) {
147
+ workspaceNameInputRef . current ?. scrollIntoView ( {
148
+ behavior : "smooth" ,
149
+ block : "center" ,
150
+ } ) ;
151
+ workspaceNameInputRef . current ?. focus ( ) ;
152
+ }
153
+ } , [ form . submitCount , form . errors ] ) ;
147
154
148
155
const [ presetOptions , setPresetOptions ] = useState ( [
149
156
{ label : "None" , value : "" } ,
@@ -333,16 +340,22 @@ export const CreateWorkspacePageViewExperimental: FC<
333
340
< Label className = "text-sm" htmlFor = { `${ id } -workspace-name` } >
334
341
Workspace name
335
342
</ Label >
336
- < div >
343
+ < div className = "flex flex-col" >
337
344
< Input
338
345
id = { `${ id } -workspace-name` }
346
+ ref = { workspaceNameInputRef }
339
347
value = { form . values . name }
340
348
onChange = { ( e ) => {
341
349
form . setFieldValue ( "name" , e . target . value . trim ( ) ) ;
342
350
resetMutation ( ) ;
343
351
} }
344
352
disabled = { creatingWorkspace }
345
353
/>
354
+ { form . touched . name && form . errors . name && (
355
+ < div className = "text-content-destructive text-xs mt-2" >
356
+ { form . errors . name }
357
+ </ div >
358
+ ) }
346
359
< div className = "flex gap-2 text-xs text-content-secondary items-center" >
347
360
Need a suggestion?
348
361
< Button
@@ -477,7 +490,6 @@ export const CreateWorkspacePageViewExperimental: FC<
477
490
478
491
return (
479
492
< DynamicParameter
480
- { ...getFieldHelpers ( parameterInputName ) }
481
493
key = { parameter . name }
482
494
parameter = { parameter }
483
495
onChange = { ( value ) =>
0 commit comments