Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3530 | | 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 { useSelector } from 'react-redux';
4
import { Box, Button } from '@mui/material';
5
 
6
import Input from '@components/UI/inputs/Input';
7
import Form from '@components/common/form';
8
 
9
export default function CommentForm({ onSubmit = () => {} }) {
10
  const labels = useSelector(({ intl }) => intl.labels);
11
 
12
  const {
13
    control,
14
    handleSubmit,
15
    reset,
16
    formState: { errors }
17
  } = useForm({
18
    defaultValues: {
19
      comment: ''
20
    }
21
  });
22
 
23
  const submitHandler = handleSubmit(({ comment }) => {
24
    onSubmit(comment);
25
    reset();
26
  });
27
 
28
  return (
29
    <Form onSubmit={submitHandler}>
30
      <Box
31
        sx={{
32
          display: 'flex',
33
          gap: ({ spacing }) => spacing(0.5),
34
          alignItems: 'center'
35
        }}
36
      >
37
        <Input
38
          name='comment'
39
          placeholder={labels.write_a_comment}
40
          control={control}
41
          error={errors.comment?.message}
42
          rules={{ required: 'Este campo es requerido' }}
43
          variant='search'
44
          autoComplete='off'
45
        />
46
        <Button color='primary' type='submit'>
47
          Publicar
48
        </Button>
49
      </Box>
50
    </Form>
51
  );
52
}