Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 2845 Rev 2846
Línea 1... Línea -...
1
import React, { useEffect, useState } from 'react'
-
 
2
import { useDispatch } from 'react-redux'
1
import React from 'react'
3
 
-
 
4
import { axios } from '@app/utils'
-
 
5
import { addNotification } from '@app/redux/notification/notification.actions'
-
 
6
import { showReportModal } from '@app/redux/report/report.actions'
-
 
Línea 7... Línea 2...
7
 
2
 
8
import CommentItem from './comment-item'
-
 
9
import ConfirmModal from '@app/components/modals/ConfirmModal'
3
import CommentItem from './comment-item'
Línea 10... Línea 4...
10
import EmptySection from '@components/UI/EmptySection'
4
import EmptySection from '@components/UI/EmptySection'
11
 
-
 
12
export default function CommentsList({ comments: defaultComments = [] }) {
-
 
13
  const [comments, setComments] = useState(defaultComments)
-
 
14
  const [currentComment, setCurrentComment] = useState(null)
-
 
15
  const [showConfirm, setShowConfirm] = useState(false)
-
 
16
  const dispatch = useDispatch()
-
 
17
 
-
 
18
  const handleDelete = (comment) => {
-
 
19
    setCurrentComment(comment)
-
 
20
    setShowConfirm(true)
-
 
21
  }
-
 
22
 
-
 
23
  const removeComment = () => {
-
 
24
    setComments((prev) =>
-
 
25
      prev.filter((comment) => comment.unique !== currentComment.unique)
-
 
26
    )
-
 
27
  }
-
 
28
 
-
 
29
  const onCloseConfirm = () => {
-
 
30
    setShowConfirm(false)
-
 
31
    setCurrentComment(null)
-
 
32
  }
-
 
33
 
-
 
34
  const reportComment = (reportUrl) =>
-
 
35
    dispatch(
-
 
36
      showReportModal({
-
 
37
        reportUrl,
-
 
38
        type: 'Comentario',
-
 
39
        onComplete: () => removeComment()
-
 
40
      })
-
 
41
    )
-
 
42
 
-
 
43
  const deleteComment = () => {
-
 
44
    axios
-
 
45
      .post(currentComment.link_delete)
-
 
46
      .then((response) => {
-
 
47
        const { success, data } = response.data
-
 
48
 
-
 
49
        if (!success) {
-
 
50
          throw new Error(
-
 
51
            'Error al eliminar un comentario, por favor intente más tarde'
-
 
52
          )
-
 
53
        }
-
 
54
 
-
 
55
        dispatch(addNotification({ style: 'success', msg: data }))
-
 
56
        removeComment()
-
 
57
        onCloseConfirm()
-
 
58
      })
-
 
59
      .catch((error) => {
-
 
60
        dispatch(addNotification({ style: 'danger', msg: error.message }))
-
 
61
      })
-
 
62
  }
-
 
63
 
-
 
64
  useEffect(() => setComments(defaultComments), [defaultComments])
5
 
65
 
6
export default function CommentsList({ comments = [], onDelete, onReport }) {
66
  if (!comments.length) {
7
  if (!comments.length) {
Línea 67... Línea -...
67
    return <EmptySection message='No hay comentarios' />
-
 
68
  }
-
 
69
 
8
    return <EmptySection message='No hay comentarios' />
70
  return (
9
  }
71
    <>
10
 
72
      {comments.map((comment) => (
11
  return comments.map((comment) => (
73
        <CommentItem
12
    <CommentItem
74
          key={comment.unique}
13
      key={comment.unique}
75
          comment={comment}
-
 
76
          onDelete={handleDelete}
-
 
77
          onReport={reportComment}
-
 
78
        />
-
 
79
      ))}
-
 
80
      <ConfirmModal
-
 
81
        show={showConfirm}
-
 
82
        onClose={onCloseConfirm}
14
      comment={comment}
83
        onAccept={deleteComment}
15
      onDelete={onDelete}
84
      />
16
      onReport={onReport}