8
8
} from '@material-ui/core' ;
9
9
import { useState } from 'react' ;
10
10
import styled from 'styled-components' ;
11
- import { Formik } from 'formik' ;
11
+ import { Formik , Form } from 'formik' ;
12
12
import { useMutation } from '@apollo/client' ;
13
13
import { withAuthenticator } from '@aws-amplify/ui-react' ;
14
14
import { SAVE_COURSE } from '../../queries/course-queries' ;
@@ -19,6 +19,17 @@ const LargeTextField = styled(TextField)`
19
19
font-size: 20px;
20
20
}
21
21
` ;
22
+ const SmallTextField = styled ( TextField ) `
23
+ input {
24
+ height: 30px;
25
+ font-size: 20px;
26
+ }
27
+ ` ;
28
+
29
+ const Container = styled . div `
30
+ text-align: center;
31
+ fontfamily: 'Poppins', sans-serif;
32
+ ` ;
22
33
23
34
function CreateCourseDialog ( ) {
24
35
const [ open , setOpen ] = useState ( false ) ;
@@ -33,88 +44,111 @@ function CreateCourseDialog() {
33
44
} ;
34
45
35
46
return (
36
- < div >
37
- < Button
38
- variant = "contained"
39
- color = "primary"
40
- onClick = { handleClickOpen }
41
- data-testid = "create-btn"
42
- >
43
- Create New Course
44
- </ Button >
45
- < Dialog
46
- open = { open }
47
- fullWidth
48
- onClose = { handleClose }
49
- aria-labelledby = "form-dialog-title"
50
- maxWidth = "sm"
51
- data-testid = "create-dialog"
52
- >
53
- < DialogTitle id = "form-dialog-title" > New Course</ DialogTitle >
54
- < DialogContent >
55
- < Formik
56
- initialValues = { {
57
- courseTitle : '' ,
58
- courseDescription : '' ,
59
- instructor : 'currentUser' ,
60
- } }
61
- onSubmit = { ( values , { setSubmitting } ) => {
62
- setTimeout ( ( ) => {
63
- setSubmitting ( false ) ;
64
- handleClose ( ) ;
65
- addCourse ( {
66
- variables : {
67
- course : {
68
- name : values . courseTitle ,
69
- description : values . courseDescription ,
70
- instructor : 'Mr. Butcher' ,
71
- missions : [ ] ,
72
- } ,
73
- } ,
74
- } ) . catch ( ( error ) => console . log ( error ) ) ;
75
- } , 400 ) ;
76
- } }
47
+ < Container >
48
+ < div >
49
+ < Button
50
+ style = { {
51
+ width : 200 ,
52
+ marginTop : 20 ,
53
+ backgroundColor : '#4274F3' ,
54
+ color : 'white' ,
55
+ } }
56
+ onClick = { handleClickOpen }
57
+ data-testid = "create-btn"
58
+ >
59
+ Create New Course
60
+ </ Button >
61
+ < Dialog
62
+ open = { open }
63
+ fullWidth
64
+ onClose = { handleClose }
65
+ aria-labelledby = "form-dialog-title"
66
+ maxWidth = "sm"
67
+ data-testid = "create-dialog"
68
+ >
69
+ < DialogTitle
70
+ style = { { backgroundColor : '#4274F3' , color : 'white' } }
71
+ id = "form-dialog-title"
77
72
>
78
- { ( { values, handleChange, handleBlur, handleSubmit, isSubmitting } ) => (
79
- < form onSubmit = { handleSubmit } >
80
- < LargeTextField
81
- id = "courseTitle"
82
- label = "Course Title"
83
- type = "text"
84
- fullWidth
85
- variant = "outlined"
86
- margin = "dense"
87
- value = { values . courseTitle }
88
- onChange = { handleChange }
89
- onBlur = { handleBlur }
90
- />
91
-
92
- < LargeTextField
93
- id = "courseDescription"
94
- label = "Description"
95
- type = "text"
96
- fullWidth
97
- variant = "outlined"
98
- margin = "dense"
99
- value = { values . courseDescription }
100
- onChange = { handleChange }
101
- onBlur = { handleBlur }
102
- />
73
+ New Course
74
+ </ DialogTitle >
75
+ < DialogContent >
76
+ < Formik
77
+ initialValues = { {
78
+ courseTitle : '' ,
79
+ courseDescription : '' ,
80
+ courseInstructor : 'Mr. Butcher' , // stay hardcoded since dashboard uses this
81
+ } }
82
+ onSubmit = { ( values , { setSubmitting } ) => {
83
+ setTimeout ( ( ) => {
84
+ setSubmitting ( false ) ;
85
+ handleClose ( ) ;
86
+ addCourse ( {
87
+ variables : {
88
+ course : {
89
+ course : values . courseTitle ,
90
+ description : values . courseDescription ,
91
+ instructor : values . courseInstructor ,
92
+ } ,
93
+ } ,
94
+ } ) . catch ( ( error ) => console . log ( error ) ) ;
95
+ } , 400 ) ;
96
+ } }
97
+ >
98
+ { ( { values, handleChange, handleBlur, handleSubmit, isSubmitting } ) => (
99
+ < Form onSubmit = { handleSubmit } >
100
+ < LargeTextField
101
+ required
102
+ id = "courseTitle"
103
+ label = "Course Title"
104
+ type = "text"
105
+ fullWidth
106
+ variant = "outlined"
107
+ margin = "dense"
108
+ value = { values . courseTitle }
109
+ onChange = { handleChange }
110
+ onBlur = { handleBlur }
111
+ />
103
112
104
- < DialogActions >
105
- < Button onClick = { handleClose } color = "primary" >
106
- Cancel
107
- </ Button >
108
- < Button type = "submit" disabled = { isSubmitting } color = "primary" >
109
- Create
110
- </ Button >
111
- </ DialogActions >
112
- </ form >
113
- ) }
114
- </ Formik >
115
- </ DialogContent >
116
- </ Dialog >
117
- </ div >
113
+ < LargeTextField
114
+ required
115
+ id = "courseDescription"
116
+ label = "Description"
117
+ type = "text"
118
+ fullWidth
119
+ variant = "outlined"
120
+ margin = "dense"
121
+ value = { values . courseDescription }
122
+ onChange = { handleChange }
123
+ onBlur = { handleBlur }
124
+ />
125
+ < SmallTextField
126
+ required
127
+ id = "courseInstructor"
128
+ label = "Instructor"
129
+ type = "text"
130
+ fullWidth
131
+ variant = "outlined"
132
+ margin = "dense"
133
+ value = { values . courseInstructor }
134
+ onChange = { handleChange }
135
+ onBlur = { handleBlur }
136
+ />
137
+ < DialogActions >
138
+ < Button onClick = { handleClose } color = "primary" >
139
+ Cancel
140
+ </ Button >
141
+ < Button type = "submit" disabled = { isSubmitting } color = "primary" >
142
+ Create
143
+ </ Button >
144
+ </ DialogActions >
145
+ </ Form >
146
+ ) }
147
+ </ Formik >
148
+ </ DialogContent >
149
+ </ Dialog >
150
+ </ div >
151
+ </ Container >
118
152
) ;
119
153
}
120
154
0 commit comments