@@ -42,19 +42,22 @@ export const QuestionEdit = ({ q, index, updateQ, setEdit }) => {
42
42
}
43
43
} ;
44
44
45
- const handleSubmit = ( toggleEdit , editQ ) => async e => {
46
- e . preventDefault ( ) ;
45
+ const handleSubmit = async ( toggleEdit , editQ ) => {
46
+ // e.preventDefault();
47
47
if ( isEmpty ( title ) || isEmpty ( difficulty ) || isEmpty ( topic ) || isEmpty ( description ) ) {
48
- setIsMissingField ( true ) ;
48
+ setIsMissingField ( true ) ;
49
49
} else {
50
- setIsMissingField ( false ) ;
51
- const response = await editQ ( q . _id , title , description , difficulty , topic , language ) ;
52
- if ( response . status === 200 ) {
53
- toggleEdit ( false ) ;
54
- } else {
55
- let res = await response . json ( ) ;
56
- setErrorVar ( res . errors )
57
- }
50
+
51
+ setIsMissingField ( false ) ;
52
+
53
+ const response = await editQ ( q . _id , title , description , difficulty , topic , language ) ;
54
+
55
+ if ( response . status === 200 ) {
56
+ toggleEdit ( false ) ;
57
+ } else {
58
+ let res = await response . json ( ) ;
59
+ setErrorVar ( res . errors )
60
+ }
58
61
}
59
62
}
60
63
@@ -94,6 +97,7 @@ export const QuestionEdit = ({ q, index, updateQ, setEdit }) => {
94
97
< div className = "btn-container" >
95
98
< button type = "cancel" className = "cancel-btn" onClick = { ( e ) => { setEdit ( false ) } } > Cancel</ button >
96
99
< button className = "submit-btn" onClick = { ( e ) => {
100
+ e . preventDefault ( ) ;
97
101
handleSubmit ( setEdit , updateQ ) ;
98
102
} } > Submit
99
103
</ button >
0 commit comments