@@ -12,23 +12,17 @@ import {
12
12
DropdownItem ,
13
13
} from "../components/Form"
14
14
15
- import { Organization , Provisioner } from "./../api"
16
-
17
- export interface CreateProjectRequest {
18
- provisionerId : string
19
- organizationId : string
20
- name : string
21
- }
15
+ import { Organization , Project , Provisioner , CreateProjectRequest } from "./../api"
22
16
23
17
export interface CreateProjectFormProps {
24
18
provisioners : Provisioner [ ]
25
19
organizations : Organization [ ]
26
- onSubmit : ( request : CreateProjectRequest ) => Promise < void >
20
+ onSubmit : ( request : CreateProjectRequest ) => Promise < Project >
27
21
onCancel : ( ) => void
28
22
}
29
23
30
24
const validationSchema = Yup . object ( {
31
- provisionerId : Yup . string ( ) . required ( "Email is required." ) ,
25
+ provisioner : Yup . string ( ) . required ( "Provisioner is required." ) ,
32
26
organizationId : Yup . string ( ) . required ( "Organization is required." ) ,
33
27
name : Yup . string ( ) . required ( "Name is required" ) ,
34
28
} )
@@ -46,18 +40,20 @@ export const CreateProjectForm: React.FC<CreateProjectFormProps> = ({
46
40
47
41
const form = useFormik < CreateProjectRequest > ( {
48
42
initialValues : {
49
- provisionerId : provisioners [ 0 ] . id ,
50
- organizationId : organizations [ 0 ] . id ,
43
+ provisioner : provisioners [ 0 ] . id ,
44
+ organizationId : organizations [ 0 ] . name ,
51
45
name : "" ,
52
46
} ,
53
47
enableReinitialize : true ,
54
48
validationSchema : validationSchema ,
55
- onSubmit : onSubmit ,
49
+ onSubmit : ( req ) => {
50
+ return onSubmit ( req )
51
+ } ,
56
52
} )
57
53
58
54
const organizationDropDownItems : DropdownItem [ ] = organizations . map ( ( org ) => {
59
55
return {
60
- value : org . id ,
56
+ value : org . name ,
61
57
name : org . name ,
62
58
}
63
59
} )
@@ -100,7 +96,7 @@ export const CreateProjectForm: React.FC<CreateProjectFormProps> = ({
100
96
< FormSection title = "Provider" >
101
97
< FormDropdownField
102
98
form = { form }
103
- formFieldName = { "provisionerId " }
99
+ formFieldName = { "provisioner " }
104
100
helperText = "The backing provisioner for this project."
105
101
items = { provisionerDropDownItems }
106
102
fullWidth
@@ -113,7 +109,16 @@ export const CreateProjectForm: React.FC<CreateProjectFormProps> = ({
113
109
< Button className = { styles . button } onClick = { onCancel } variant = "outlined" >
114
110
Cancel
115
111
</ Button >
116
- < Button className = { styles . button } onClick = { form . submitForm } variant = "contained" color = "primary" type = "submit" >
112
+ < Button
113
+ className = { styles . button }
114
+ onClick = { ( ) => {
115
+ console . log ( "submit clicked: " + JSON . stringify ( form . values ) )
116
+ form . submitForm ( )
117
+ } }
118
+ variant = "contained"
119
+ color = "primary"
120
+ type = "submit"
121
+ >
117
122
Submit
118
123
</ Button >
119
124
</ div >
0 commit comments