Skip to content

Commit 8162019

Browse files
committed
added submit
1 parent 35cca08 commit 8162019

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

react-form/src/App.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { questions } from "./Questions";
88

99
function App() {
1010
const [index, setIndex] = useState(1);
11+
const [submitted, setSubmitted] = useState(false);
1112
const totalPagesCount = questions?.length || 0;
1213
// numbered by pages. for exampe { 1: [{"key" : "value"}], 2:["key": "value"], 3: []}
1314
const [pagesAnswers, setPagesAnswers] = useState({});
@@ -21,13 +22,22 @@ function App() {
2122
const nextButton = () => {
2223
if (index - 3) {
2324
setIndex(prevIndex => prevIndex + 1);
25+
} else {
26+
// clear the form on submit
27+
setPagesAnswers({});
28+
setSubmitted(true);
2429
}
2530
}
2631

2732
const onPageAnswerUpdate = (step, answersObj) => {
2833
setPagesAnswers({...pagesAnswers, [step]: answersObj});
2934
}
3035

36+
const handleStart = () => {
37+
setIndex(1);
38+
setSubmitted(false);
39+
}
40+
3141
return (
3242
<div className="App">
3343
<Container className="h-100">
@@ -39,6 +49,16 @@ function App() {
3949
</Col>
4050
</Row>
4151
<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> :
4262
<Card>
4363
<Card.Body>
4464
<MultiStepForm
@@ -53,6 +73,7 @@ function App() {
5373
<Button onClick={nextButton}>{index == totalPagesCount ? 'Submit' : 'Next'}</Button>
5474
</Card.Footer>
5575
</Card>
76+
}
5677
</Row>
5778
</Container>
5879
</div>

0 commit comments

Comments
 (0)