Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | 1x 1x 1x 4x 4x 1x 4x | import React from 'react';
import styles from '@/styles/survey.module.css';
import type { Question } from '@/constants/survey';
type Props = {
question: Question;
index: number;
currentQuestionNum: number;
answers: Array<{ answer: string }>;
handleAnswerOptionClick: (payload: {
question: string;
answer: string;
isCorrect: boolean;
questionNum: number;
}) => void;
};
const QuestionBlock = ({ question, index, currentQuestionNum, answers, handleAnswerOptionClick }: Props) => {
if (currentQuestionNum !== index) return null;
return (
<div data-testid="question-block" className={styles.question}>
<div>{question.questionContent}</div>
{question.answerOptions?.map((answerOption) => (
<label htmlFor={answerOption.answerText} key={answerOption.answerText}>
<input
onChange={(e) =>
handleAnswerOptionClick({
question: question.questionText || '',
answer: e.target.value,
isCorrect: answerOption.isCorrect,
questionNum: index,
})
}
type="radio"
id={answerOption.answerText}
name={String(index)}
value={answerOption.answerText}
checked={answers[index]?.answer === answerOption.answerText}
/>
{answerOption.answerText}
</label>
))}
</div>
);
};
export default QuestionBlock;
|