Skip to content

Commit

Permalink
filter questions in form for each page and return, so that each repor…
Browse files Browse the repository at this point in the history
…t page endpoint serves the relevant questions
  • Loading branch information
redahaq committed Feb 14, 2020
1 parent 7e97da5 commit d030e9f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 29 deletions.
7 changes: 6 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ module.exports = {
node: true,
es6: true,
},
extends: ['eslint:recommended', 'plugin:react/recommended'],
extends: [
'eslint:recommended',
'plugin:react/recommended',
'prettier',
'prettier/react',
],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
Expand Down
1 change: 0 additions & 1 deletion src/App/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ function App() {
render={() => (
<>
<Home></Home>
<Link to='/report/0'>Start</Link>
</>
)}
/>
Expand Down
2 changes: 0 additions & 2 deletions src/components/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ const ButtonPrimary = styled(Button)`
border-radius: 1rem;
background: linear-gradient(296.3deg, #7768A6 2.65%, #CA68A4 86.52%);
font-weight: bold;
}
`;

Expand Down
62 changes: 37 additions & 25 deletions src/components/Form/Form.js
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;

0 comments on commit d030e9f

Please sign in to comment.