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 { useForm } from 'react-hook-form'
3
import { Box } from '@mui/material'
4
 
5
import { parse } from '@app/utils'
6
 
7
import Button from '@app/components/UI/buttons/Buttons'
8
import Checkbox from '@components/UI/inputs/Checkbox'
9
import FormErrorFeedback from '@app/components/UI/form/FormErrorFeedback'
10
 
11
function QuizMultipleQuestion({
12
  question,
13
  onConfirm,
14
  buttonLabel = 'Finalizar',
15
  isCurrent = false
16
}) {
17
  const {
18
    control,
19
    formState: { errors },
20
    handleSubmit
21
  } = useForm()
22
 
23
  const handleConfirm = handleSubmit((data) => {
24
    onConfirm(data[question.uuid])
25
  })
26
 
27
  return (
28
    <Box sx={{ display: isCurrent ? 'initial' : 'none' }}>
29
      <Box sx={{ '& p': { fontWeight: '600', fontSize: '1.5rem' } }}>
30
        {parse(question.text)}
31
      </Box>
32
 
33
      {question.answers.map(({ uuid, text }) => (
34
        <Box
35
          key={uuid}
36
          sx={{ display: 'flex', justifyContent: 'space-between', gap: 2 }}
37
          component='label'
38
          htmlFor={uuid}
39
        >
40
          {parse(text)}
41
 
42
          <Checkbox
43
            control={control}
44
            name={question.uuid}
45
            value={uuid}
46
            rules={{ required: true }}
47
          />
48
        </Box>
49
      ))}
50
 
51
      {errors[question.uuid] && (
52
        <FormErrorFeedback>
53
          Por favor, seleccione al menos una respuesta
54
        </FormErrorFeedback>
55
      )}
56
 
57
      <Button
58
        color='primary'
59
        onClick={handleConfirm}
60
        styles={{ marginTop: '1rem' }}
61
      >
62
        {buttonLabel}
63
      </Button>
64
    </Box>
65
  )
66
}
67
 
68
export default QuizMultipleQuestion