forked from fac18/safe-space
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
filter questions in form for each page and return, so that each repor…
…t page endpoint serves the relevant questions
- Loading branch information
Showing
4 changed files
with
43 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,6 @@ function App() { | |
render={() => ( | ||
<> | ||
<Home></Home> | ||
<Link to='/report/0'>Start</Link> | ||
</> | ||
)} | ||
/> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,44 @@ | ||
import React from 'react'; | ||
import { useLocation } from 'react-router-dom'; | ||
|
||
const Form = ({ questions }) => { | ||
const questionArray = questions | ||
? questions.map(question => { | ||
return ( | ||
<> | ||
<p> {question.question}</p> | ||
{question.content ? ( | ||
question.content.map(answer => { | ||
return ( | ||
<> | ||
<input | ||
type={question.type} | ||
value={answer} | ||
id={answer + ' ' + question.questionNumber} | ||
/> | ||
<label htmlFor={answer}>{answer}</label> | ||
</> | ||
); | ||
}) | ||
) : ( | ||
<input type={question.type} /> | ||
)} | ||
</> | ||
); | ||
}) | ||
const path = useLocation().pathname; | ||
|
||
// page question from URL path | ||
const page = parseInt(path.match(/report\/(\d+)$/i)[1]); | ||
|
||
console.log({ page }); | ||
|
||
|
||
const pageQuestions = questions ? questions | ||
.filter(question => { | ||
return question.page === page | ||
}) | ||
.map(question => { | ||
return ( | ||
<> | ||
<p> {question.question}</p> | ||
{question.content ? ( | ||
question.content.map(answer => { | ||
return ( | ||
<> | ||
<input | ||
type={question.type} | ||
value={answer} | ||
id={answer + ' ' + question.questionNumber} | ||
/> | ||
<label htmlFor={answer}>{answer}</label> | ||
</> | ||
); | ||
}) | ||
) : ( | ||
<input type={question.type} /> | ||
)} | ||
</> | ||
); | ||
}) | ||
: null; | ||
return <form>{questionArray}</form>; | ||
return <form>{pageQuestions}</form>; | ||
}; | ||
|
||
export default Form; |