Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 1651 | Rev 2800 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1650 stevensc 1
import React, { useEffect } from 'react'
2
import { useForm } from 'react-hook-form'
3
import { useSelector } from 'react-redux'
2152 stevensc 4
import { IconButton } from '@mui/material'
1650 stevensc 5
import { Send } from '@mui/icons-material'
6
 
7
import { StyledCommentForm } from './comments-ui'
8
import Input from '@app/components/UI/Input'
9
 
1651 stevensc 10
export default function CommentForm({ onSubmit = () => null }) {
1650 stevensc 11
  const labels = useSelector(({ intl }) => intl.labels)
12
  const { register, handleSubmit, errors, setValue, watch } = useForm({
13
    defaultValues: {
14
      comment: ''
15
    }
16
  })
17
  const currentComment = watch('comment')
18
 
19
  const submitHandler = handleSubmit(({ comment }) => {
20
    onSubmit(comment)
21
    setValue('comment', '')
22
  })
23
 
24
  useEffect(() => {
25
    register('comment', { required: true })
26
  }, [])
27
 
28
  return (
29
    <StyledCommentForm onSubmit={submitHandler} autoComplete='off'>
1651 stevensc 30
      {/* {image && (
1650 stevensc 31
        <Avatar
1651 stevensc 32
          src={}
1650 stevensc 33
          alt='Profile image'
34
          sx={{ width: '45px', height: '45px' }}
35
        />
1651 stevensc 36
      )} */}
1650 stevensc 37
 
38
      <Input
39
        type='text'
40
        name='comment'
41
        placeholder={labels.write_a_comment}
42
        primary={false}
43
        onChange={(e) => setValue('comment', e.target.value)}
44
        value={currentComment}
45
        error={errors.comment?.message}
46
        sx={{ flex: '1 1 50%' }}
47
      />
48
 
49
      <IconButton type='submit'>
50
        <Send />
51
      </IconButton>
52
    </StyledCommentForm>
53
  )
54
}