@@ -4,45 +4,53 @@ import {
4
4
Card ,
5
5
CardBody ,
6
6
CardFooter ,
7
+ Form ,
7
8
Input ,
8
9
Label ,
9
10
LinkButton ,
10
11
TextField ,
11
12
} from "@stacklok/ui-kit" ;
12
- import { useState } from "react" ;
13
+ import { FormEvent , useState } from "react" ;
13
14
14
15
export function WorkspaceCreation ( ) {
15
16
const [ workspaceName , setWorkspaceName ] = useState ( "" ) ;
16
17
const { mutate, isPending, error } = useCreateWorkspace ( ) ;
17
18
const errorMsg = error ?. detail ? `${ error ?. detail } ` : "" ;
18
19
19
- const handleCreateWorkspace = ( ) => {
20
+ const handleSubmit = ( e : FormEvent < HTMLFormElement > ) => {
21
+ e . preventDefault ( ) ;
20
22
mutate ( { body : { name : workspaceName } } ) ;
21
23
} ;
22
24
23
25
return (
24
- < Card >
25
- < CardBody className = "w-full" >
26
- < TextField
27
- aria-label = "Workspace name"
28
- validationBehavior = "aria"
29
- isRequired
30
- onChange = { setWorkspaceName }
31
- >
32
- < Label > Name</ Label >
33
- < Input value = { workspaceName } />
34
- { errorMsg && < div className = "p-1 text-red-700" > { errorMsg } </ div > }
35
- </ TextField >
36
- </ CardBody >
37
- < CardFooter className = "justify-end gap-2" >
38
- < LinkButton variant = "secondary" > Cancel</ LinkButton >
39
- < Button
40
- isDisabled = { isPending || workspaceName === "" }
41
- onPress = { ( ) => handleCreateWorkspace ( ) }
42
- >
43
- Create
44
- </ Button >
45
- </ CardFooter >
46
- </ Card >
26
+ < Form onSubmit = { handleSubmit } validationBehavior = "aria" >
27
+ < Card >
28
+ < CardBody className = "w-full" >
29
+ < TextField
30
+ aria-label = "Workspace name"
31
+ name = "Workspace name"
32
+ validationBehavior = "aria"
33
+ isRequired
34
+ onChange = { setWorkspaceName }
35
+ >
36
+ < Label > Name</ Label >
37
+ < Input value = { workspaceName } />
38
+ { errorMsg && < div className = "p-1 text-red-700" > { errorMsg } </ div > }
39
+ </ TextField >
40
+ </ CardBody >
41
+ < CardFooter className = "justify-end gap-2" >
42
+ < LinkButton variant = "secondary" href = "/workspaces" >
43
+ Cancel
44
+ </ LinkButton >
45
+ < Button
46
+ isDisabled = { workspaceName === "" }
47
+ isPending = { isPending }
48
+ type = "submit"
49
+ >
50
+ Create
51
+ </ Button >
52
+ </ CardFooter >
53
+ </ Card >
54
+ </ Form >
47
55
) ;
48
56
}
0 commit comments