File tree Expand file tree Collapse file tree 1 file changed +20
-11
lines changed
frontend/components/questions Expand file tree Collapse file tree 1 file changed +20
-11
lines changed Original file line number Diff line number Diff line change @@ -30,14 +30,16 @@ interface QuestionFormModalProps {
30
30
}
31
31
32
32
const QuestionFormModal : React . FC < QuestionFormModalProps > = ( { ...props } ) => {
33
+ const initialQuestionState : Question = {
34
+ id : "" ,
35
+ title : "" ,
36
+ category : "" ,
37
+ complexity : "easy" ,
38
+ description : "" ,
39
+ } ;
40
+
33
41
const [ question , setQuestion ] = useState < Question > (
34
- props . initialData || {
35
- id : "" ,
36
- title : "" ,
37
- category : "" ,
38
- complexity : "easy" ,
39
- description : "" ,
40
- }
42
+ props . initialData || initialQuestionState
41
43
) ;
42
44
43
45
useEffect ( ( ) => {
@@ -50,6 +52,16 @@ const QuestionFormModal: React.FC<QuestionFormModalProps> = ({ ...props }) => {
50
52
e . preventDefault ( ) ;
51
53
52
54
props . handleSubmit ( question ) ;
55
+ setQuestion ( initialQuestionState ) ;
56
+ } ;
57
+
58
+ const handleExit = ( ) => {
59
+ if ( props . initialData ) {
60
+ setQuestion ( props . initialData ) ;
61
+ } else {
62
+ setQuestion ( initialQuestionState ) ;
63
+ }
64
+ props . setShowModal ( false ) ;
53
65
} ;
54
66
55
67
return (
@@ -136,10 +148,7 @@ const QuestionFormModal: React.FC<QuestionFormModalProps> = ({ ...props }) => {
136
148
{ props . isAdmin && (
137
149
< Button type = "submit" > { props . submitButtonText } </ Button >
138
150
) }
139
- < Button
140
- variant = "destructive"
141
- onClick = { ( ) => props . setShowModal ( false ) }
142
- >
151
+ < Button variant = "destructive" onClick = { handleExit } >
143
152
Exit
144
153
</ Button >
145
154
</ DialogFooter >
You can’t perform that action at this time.
0 commit comments