2025-03-07 11:36:43 -05:00
|
|
|
import React, { useEffect, useState } from 'react';
|
2024-03-29 20:08:34 -04:00
|
|
|
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;
|
2025-03-07 11:36:43 -05:00
|
|
|
handleOnSubmitAnswer?: (answer: string | number | boolean) => void;
|
2024-03-29 20:08:34 -04:00
|
|
|
showAnswer?: boolean;
|
2025-03-07 11:36:43 -05:00
|
|
|
passedAnswer?: string | number | boolean;
|
|
|
|
|
|
2024-03-29 20:08:34 -04:00
|
|
|
}
|
|
|
|
|
|
2025-01-24 14:51:58 -05:00
|
|
|
const ShortAnswerQuestionDisplay: React.FC<Props> = (props) => {
|
2025-03-07 12:42:56 -05:00
|
|
|
|
2025-03-07 11:36:43 -05:00
|
|
|
const { question, showAnswer, handleOnSubmitAnswer, passedAnswer } = props;
|
2025-03-07 12:42:56 -05:00
|
|
|
const [answer, setAnswer] = useState<string | number | boolean>(passedAnswer || '');
|
2025-03-07 11:36:43 -05:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (passedAnswer !== undefined) {
|
|
|
|
|
setAnswer(passedAnswer);
|
|
|
|
|
}
|
|
|
|
|
}, [passedAnswer]);
|
2025-03-07 12:42:56 -05:00
|
|
|
console.log("Answer" , answer);
|
|
|
|
|
|
2024-03-29 20:08:34 -04:00
|
|
|
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-03-07 11:36:43 -05:00
|
|
|
<span>
|
|
|
|
|
<strong>La bonne réponse est: </strong>
|
|
|
|
|
|
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
|
|
|
))}
|
2025-03-07 11:36:43 -05:00
|
|
|
</span>
|
|
|
|
|
<span>
|
|
|
|
|
<strong>Votre réponse est: </strong>{answer}
|
|
|
|
|
</span>
|
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)
|
|
|
|
|
}
|
2025-03-07 11:36:43 -05:00
|
|
|
disabled={answer === null || answer === ''}
|
2024-03-29 20:08:34 -04:00
|
|
|
>
|
|
|
|
|
Répondre
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2025-01-24 14:51:58 -05:00
|
|
|
export default ShortAnswerQuestionDisplay;
|