Skip to content

Commit

Permalink
added submit
Browse files Browse the repository at this point in the history
  • Loading branch information
judygab committed May 31, 2022
1 parent 35cca08 commit 8162019
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions react-form/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { questions } from "./Questions";

function App() {
const [index, setIndex] = useState(1);
const [submitted, setSubmitted] = useState(false);
const totalPagesCount = questions?.length || 0;
// numbered by pages. for exampe { 1: [{"key" : "value"}], 2:["key": "value"], 3: []}
const [pagesAnswers, setPagesAnswers] = useState({});
Expand All @@ -21,13 +22,22 @@ function App() {
const nextButton = () => {
if (index - 3) {
setIndex(prevIndex => prevIndex + 1);
} else {
// clear the form on submit
setPagesAnswers({});
setSubmitted(true);
}
}

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

const handleStart = () => {
setIndex(1);
setSubmitted(false);
}

return (
<div className="App">
<Container className="h-100">
Expand All @@ -39,6 +49,16 @@ function App() {
</Col>
</Row>
<Row>
{
submitted ?
<Card>
<Card.Body>
<p>Your answers have been submitted!</p>
</Card.Body>
<Card.Footer>
<Button onClick={handleStart}>Start Over</Button>
</Card.Footer>
</Card> :
<Card>
<Card.Body>
<MultiStepForm
Expand All @@ -53,6 +73,7 @@ function App() {
<Button onClick={nextButton}>{index == totalPagesCount ? 'Submit' : 'Next'}</Button>
</Card.Footer>
</Card>
}
</Row>
</Container>
</div>
Expand Down

0 comments on commit 8162019

Please sign in to comment.