Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3481 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
3719 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' } }}>{parse(question.text)}</Box>
30
 
31
      {question.answers.map(({ uuid, text }) => (
32
        <Box
33
          key={uuid}
34
          sx={{ display: 'flex', justifyContent: 'space-between', gap: 2 }}
35
          component='label'
36
          htmlFor={uuid}
37
        >
38
          {parse(text)}
39
 
40
          <Checkbox
41
            control={control}
42
            name={question.uuid}
43
            value={uuid}
44
            rules={{ required: true }}
45
          />
46
        </Box>
47
      ))}
48
 
49
      {errors[question.uuid] && (
50
        <FormErrorFeedback>Por favor, seleccione al menos una respuesta</FormErrorFeedback>
51
      )}
52
 
53
      <Button color='primary' onClick={handleConfirm} styles={{ marginTop: '1rem' }}>
54
        {buttonLabel}
55
      </Button>
56
    </Box>
57
  );
58
}
59
 
60
export default QuizMultipleQuestion;