Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev Autor Línea Nro. Línea
16666 stevensc 1
import React, { useState } from 'react'
2
import { axios } from '../../utils'
3
 
16669 stevensc 4
import styles from './comments.module.scss'
5
 
16666 stevensc 6
const CommentForm = ({ image, profileUrl, sendUrl, onSubmit }) => {
7
  const [comment, setComment] = useState('')
8
 
9
  const handleSubmit = (e) => {
10
    e.preventDefault()
11
 
12
    const formData = new FormData()
13
    formData.append('comment', comment)
14
 
15
    axios
16
      .post(sendUrl, formData)
17
      .then(({ data }) => {
18
        if (!data.success) {
19
          return console.log('Error de envio')
20
        }
21
 
22
        onSubmit(data)
23
        setComment('')
24
      })
25
      .catch((err) => console.log(err))
26
  }
27
 
28
  const handleInputChange = ({ target }) => {
29
    setComment(target.value)
30
  }
31
 
32
  return (
16669 stevensc 33
    <form className={styles.comment_form} onSubmit={handleSubmit}>
16666 stevensc 34
      <a href={profileUrl}>
16669 stevensc 35
        <img src={image} alt="User image" />
16666 stevensc 36
      </a>
37
      <input
38
        type="text"
39
        className="form-control"
40
        placeholder="Escribe un comentario"
41
        onChange={handleInputChange}
42
        value={comment}
43
      />
44
      <button type="submit" className="btn btn-primary">
45
        Comentar
46
      </button>
47
    </form>
48
  )
49
}
50
export default CommentForm