Proyectos de Subversion LeadersLinked - SPA

Rev

Ir a la última revisión | | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
3481 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({
10
  question,
11
  onConfirm,
12
  buttonLabel = 'Finalizar',
13
  isCurrent = false
14
}) {
15
  const {
16
    register,
17
    handleSubmit,
18
    formState: { errors }
19
  } = useForm()
20
 
21
  const handleConfirm = handleSubmit((data) => {
22
    onConfirm(data[question.uuid])
23
  })
24
 
25
  return (
26
    <Box sx={{ display: isCurrent ? 'initial' : 'none' }}>
27
      <Box sx={{ '& p': { fontWeight: '600', fontSize: '1.5rem' } }}>
28
        {parse(question.text)}
29
      </Box>
30
 
31
      {question.answers.map((answer) => (
32
        <Box
33
          key={answer.uuid}
34
          sx={{ display: 'flex', justifyContent: 'space-between', gap: 2 }}
35
        >
36
          {parse(answer.text)}
37
 
38
          <input
39
            type='radio'
40
            name={question.uuid}
41
            value={answer.uuid}
42
            ref={register({ required: true })}
43
          />
44
        </Box>
45
      ))}
46
 
47
      {errors[question.uuid] && (
48
        <FormErrorFeedback>
49
          Por favor, seleccione una respuesta
50
        </FormErrorFeedback>
51
      )}
52
 
53
      <Button
54
        color='primary'
55
        onClick={() => handleConfirm()}
56
        styles={{ marginTop: '1rem' }}
57
      >
58
        {buttonLabel}
59
      </Button>
60
    </Box>
61
  )
62
}
63
 
64
export default QuizSimpleQuestion