| 3719 |
stevensc |
1 |
import React from 'react';
|
|
|
2 |
import { Box } from '@mui/material';
|
|
|
3 |
import { useForm } from 'react-hook-form';
|
|
|
4 |
import parse from 'html-react-parser';
|
|
|
5 |
|
|
|
6 |
import FormErrorFeedback from '@app/components/UI/form/FormErrorFeedback';
|
|
|
7 |
import Button from '@app/components/UI/buttons/Buttons';
|
|
|
8 |
|
|
|
9 |
function QuizSimpleQuestion({ question, onConfirm, buttonLabel = 'Finalizar', isCurrent = false }) {
|
|
|
10 |
const {
|
|
|
11 |
register,
|
|
|
12 |
handleSubmit,
|
|
|
13 |
formState: { errors }
|
|
|
14 |
} = useForm();
|
|
|
15 |
|
|
|
16 |
const handleConfirm = handleSubmit((data) => {
|
|
|
17 |
onConfirm(data[question.uuid]);
|
|
|
18 |
});
|
|
|
19 |
|
|
|
20 |
return (
|
|
|
21 |
<Box sx={{ display: isCurrent ? 'initial' : 'none' }}>
|
|
|
22 |
<Box sx={{ '& p': { fontWeight: '600', fontSize: '1.5rem' } }}>{parse(question.text)}</Box>
|
|
|
23 |
|
|
|
24 |
{question.answers.map((answer) => (
|
|
|
25 |
<Box key={answer.uuid} sx={{ display: 'flex', justifyContent: 'space-between', gap: 2 }}>
|
|
|
26 |
{parse(answer.text)}
|
|
|
27 |
|
|
|
28 |
<input
|
|
|
29 |
type='radio'
|
|
|
30 |
name={question.uuid}
|
|
|
31 |
value={answer.uuid}
|
|
|
32 |
ref={register({ required: true })}
|
|
|
33 |
/>
|
|
|
34 |
</Box>
|
|
|
35 |
))}
|
|
|
36 |
|
|
|
37 |
{errors[question.uuid] && (
|
|
|
38 |
<FormErrorFeedback>Por favor, seleccione una respuesta</FormErrorFeedback>
|
|
|
39 |
)}
|
|
|
40 |
|
|
|
41 |
<Button color='primary' onClick={() => handleConfirm()} styles={{ marginTop: '1rem' }}>
|
|
|
42 |
{buttonLabel}
|
|
|
43 |
</Button>
|
|
|
44 |
</Box>
|
|
|
45 |
);
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
export default QuizSimpleQuestion;
|