2024-03-29 20:08:34 -04:00
|
|
|
import React, { useState } from 'react';
|
|
|
|
|
import '../questionStyle.css';
|
|
|
|
|
import { Button, TextField } from '@mui/material';
|
2025-01-26 09:33:42 -05:00
|
|
|
import { FormattedTextTemplate } from '../../GiftTemplate/templates/TextTypeTemplate';
|
2025-01-24 14:51:58 -05:00
|
|
|
import { ShortAnswerQuestion } from 'gift-pegjs';
|
2024-03-29 20:08:34 -04:00
|
|
|
|
|
|
|
|
interface Props {
|
2025-01-24 14:51:58 -05:00
|
|
|
question: ShortAnswerQuestion;
|
2024-03-29 20:08:34 -04:00
|
|
|
handleOnSubmitAnswer?: (answer: string) => void;
|
|
|
|
|
showAnswer?: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-24 14:51:58 -05:00
|
|
|
const ShortAnswerQuestionDisplay: React.FC<Props> = (props) => {
|
|
|
|
|
const { question, showAnswer, handleOnSubmitAnswer } = props;
|
2024-03-29 20:08:34 -04:00
|
|
|
const [answer, setAnswer] = useState<string>();
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="question-wrapper">
|
2024-04-08 21:37:11 -04:00
|
|
|
<div className="question content">
|
2025-01-26 09:33:42 -05:00
|
|
|
<div dangerouslySetInnerHTML={{ __html: FormattedTextTemplate(question.formattedStem) }} />
|
2024-03-29 20:08:34 -04:00
|
|
|
</div>
|
|
|
|
|
{showAnswer ? (
|
|
|
|
|
<>
|
|
|
|
|
<div className="correct-answer-text mb-1">
|
2025-01-24 14:51:58 -05:00
|
|
|
{question.choices.map((choice) => (
|
|
|
|
|
<div key={choice.text} className="mb-1">
|
|
|
|
|
{choice.text}
|
2025-01-11 02:22:14 -05:00
|
|
|
</div>
|
2024-03-29 20:08:34 -04:00
|
|
|
))}
|
|
|
|
|
</div>
|
2025-01-24 14:51:58 -05:00
|
|
|
{question.formattedGlobalFeedback && <div className="global-feedback mb-2">
|
2025-01-26 09:33:42 -05:00
|
|
|
<div dangerouslySetInnerHTML={{ __html: FormattedTextTemplate(question.formattedGlobalFeedback) }} />
|
2025-01-24 14:51:58 -05:00
|
|
|
</div>}
|
2024-03-29 20:08:34 -04:00
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
|
|
|
|
<div className="answer-wrapper mb-1">
|
|
|
|
|
<TextField
|
|
|
|
|
type="text"
|
2025-01-24 14:51:58 -05:00
|
|
|
id={question.formattedStem.text}
|
|
|
|
|
name={question.formattedStem.text}
|
2024-03-29 20:08:34 -04:00
|
|
|
onChange={(e) => {
|
|
|
|
|
setAnswer(e.target.value);
|
|
|
|
|
}}
|
|
|
|
|
disabled={showAnswer}
|
2025-01-24 14:51:58 -05:00
|
|
|
aria-label="short-answer-input"
|
2024-03-29 20:08:34 -04:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
{handleOnSubmitAnswer && (
|
|
|
|
|
<Button
|
|
|
|
|
variant="contained"
|
|
|
|
|
onClick={() =>
|
|
|
|
|
answer !== undefined &&
|
|
|
|
|
handleOnSubmitAnswer &&
|
|
|
|
|
handleOnSubmitAnswer(answer)
|
|
|
|
|
}
|
|
|
|
|
disabled={answer === undefined || answer === ''}
|
|
|
|
|
>
|
|
|
|
|
Répondre
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2025-01-24 14:51:58 -05:00
|
|
|
export default ShortAnswerQuestionDisplay;
|