Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 2152 | Rev 2843 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

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