File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import { questions } from "./Questions";
8
8
9
9
function App ( ) {
10
10
const [ index , setIndex ] = useState ( 1 ) ;
11
+ const [ submitted , setSubmitted ] = useState ( false ) ;
11
12
const totalPagesCount = questions ?. length || 0 ;
12
13
// numbered by pages. for exampe { 1: [{"key" : "value"}], 2:["key": "value"], 3: [] }
13
14
const [ pagesAnswers , setPagesAnswers ] = useState ( { } ) ;
@@ -21,13 +22,22 @@ function App() {
21
22
const nextButton = ( ) => {
22
23
if ( index - 3 ) {
23
24
setIndex ( prevIndex => prevIndex + 1 ) ;
25
+ } else {
26
+ // clear the form on submit
27
+ setPagesAnswers ( { } ) ;
28
+ setSubmitted ( true ) ;
24
29
}
25
30
}
26
31
27
32
const onPageAnswerUpdate = ( step , answersObj ) => {
28
33
setPagesAnswers ( { ...pagesAnswers , [ step ] : answersObj } ) ;
29
34
}
30
35
36
+ const handleStart = ( ) => {
37
+ setIndex ( 1 ) ;
38
+ setSubmitted ( false ) ;
39
+ }
40
+
31
41
return (
32
42
< div className = "App" >
33
43
< Container className = "h-100" >
@@ -39,6 +49,16 @@ function App() {
39
49
</ Col >
40
50
</ Row >
41
51
< Row >
52
+ {
53
+ submitted ?
54
+ < Card >
55
+ < Card . Body >
56
+ < p > Your answers have been submitted!</ p >
57
+ </ Card . Body >
58
+ < Card . Footer >
59
+ < Button onClick = { handleStart } > Start Over</ Button >
60
+ </ Card . Footer >
61
+ </ Card > :
42
62
< Card >
43
63
< Card . Body >
44
64
< MultiStepForm
@@ -53,6 +73,7 @@ function App() {
53
73
< Button onClick = { nextButton } > { index == totalPagesCount ? 'Submit' : 'Next' } </ Button >
54
74
</ Card . Footer >
55
75
</ Card >
76
+ }
56
77
</ Row >
57
78
</ Container >
58
79
</ div >
You can’t perform that action at this time.
0 commit comments