// MultipleChoiceQuestionDisplay.tsx import React, { useEffect, useState } from 'react'; import '../questionStyle.css'; import { Button } from '@mui/material'; import { FormattedTextTemplate } from '../../GiftTemplate/templates/TextTypeTemplate'; import { MultipleChoiceQuestion } from 'gift-pegjs'; interface Props { question: MultipleChoiceQuestion; handleOnSubmitAnswer?: (answer: string) => void; showAnswer?: boolean; } const MultipleChoiceQuestionDisplay: React.FC = (props) => { const { question, showAnswer, handleOnSubmitAnswer } = props; const [answer, setAnswer] = useState(); useEffect(() => { setAnswer(undefined); }, [question]); const handleOnClickAnswer = (choice: string) => { setAnswer(choice); }; const alpha = Array.from(Array(26)).map((_e, i) => i + 65); const alphabet = alpha.map((x) => String.fromCharCode(x)); return (
{question.choices.map((choice, i) => { const selected = answer === choice.formattedText.text ? 'selected' : ''; return (
); })}
{question.formattedGlobalFeedback && showAnswer && (
)} {!showAnswer && handleOnSubmitAnswer && ( )}
); }; export default MultipleChoiceQuestionDisplay;