Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 7226 Rev 7229
Línea 1... Línea 1...
1
import React, { useEffect, useState } from 'react'
1
import React, { useState } from 'react'
2
import { axios } from '../../utils'
2
import { axios } from '../../utils'
3
import { Link } from 'react-router-dom'
3
import { Link } from 'react-router-dom'
4
import { Avatar } from '@mui/material'
4
import { Avatar } from '@mui/material'
5
import { addNotification } from '../../redux/notification/notification.actions'
5
import { addNotification } from '../../redux/notification/notification.actions'
6
import { useDispatch, useSelector } from 'react-redux'
6
import { useDispatch, useSelector } from 'react-redux'
Línea 43... Línea 43...
43
  link_add_comment = '',
43
  link_add_comment = '',
44
  onEdit = () => {},
44
  onEdit = () => {},
45
  onDelete = () => {},
45
  onDelete = () => {},
46
  updateComments = () => {},
46
  updateComments = () => {},
47
}) => {
47
}) => {
48
  const [comments, setComments] = useState([])
48
  const [comments, setComments] = useState(defaultComments)
49
  const [totalComments, setTotalComments] = useState(0)
49
  const [totalComments, setTotalComments] = useState(total_comments)
50
  const labels = useSelector(({ intl }) => intl.labels)
50
  const labels = useSelector(({ intl }) => intl.labels)
51
  const dispatch = useDispatch()
51
  const dispatch = useDispatch()
Línea 52... Línea 52...
52
 
52
 
53
  const addComment = ({ comment }) => {
53
  const addComment = ({ comment }) => {
54
    const formData = new FormData()
54
    const formData = new FormData()
Línea 55... Línea 55...
55
    formData.append('comment', comment)
55
    formData.append('comment', comment)
56
 
56
 
57
    axios
57
    axios
58
      .post(link_add_comment, formData)
-
 
59
      .then((response) => {
-
 
60
        const {
-
 
61
          success,
-
 
62
          data,
-
 
63
          total_comments_answer,
58
      .post(link_add_comment, formData)
Línea 64... Línea 59...
64
          total_comments_question,
59
      .then((response) => {
65
        } = response.data
60
        const { success, data } = response.data
66
 
61
 
67
        if (!success) {
62
        if (!success) {
Línea 72... Línea 67...
72
          dispatch(addNotification({ style: 'danger', msg: errorMessage }))
67
          dispatch(addNotification({ style: 'danger', msg: errorMessage }))
73
          return
68
          return
74
        }
69
        }
Línea 75... Línea 70...
75
 
70
 
76
        setComments([...comments, data.item])
71
        setComments([...comments, data.item])
77
        updateComments(total_comments_question)
72
        updateComments(data.total_comments_question)
78
        setTotalComments(total_comments_answer)
73
        setTotalComments(data.total_comments_answer)
79
      })
74
      })
80
      .catch((error) => {
75
      .catch((error) => {
81
        dispatch(
76
        dispatch(
82
          addNotification({
77
          addNotification({
Línea 90... Línea 85...
90
 
85
 
91
  const deleteComment = (commentUnique, deleteCommentUrl) => {
86
  const deleteComment = (commentUnique, deleteCommentUrl) => {
92
    axios
87
    axios
93
      .post(deleteCommentUrl)
88
      .post(deleteCommentUrl)
94
      .then((response) => {
-
 
95
        const {
-
 
96
          success,
-
 
97
          data,
-
 
98
          total_comments_answer,
-
 
99
          total_comments_question,
89
      .then((response) => {
Línea 100... Línea 90...
100
        } = response.data
90
        const { success, data } = response.data
101
 
91
 
102
        if (!success) {
92
        if (!success) {
103
          const errorMessage =
93
          const errorMessage =
Línea 114... Línea 104...
114
        )
104
        )
Línea 115... Línea 105...
115
 
105
 
Línea 116... Línea 106...
116
        dispatch(addNotification({ style: 'success', msg: data.message }))
106
        dispatch(addNotification({ style: 'success', msg: data.message }))
117
 
107
 
118
        setComments(newComments)
108
        setComments(newComments)
119
        updateComments(total_comments_question)
109
        updateComments(data.total_comments_question)
120
        setTotalComments(total_comments_answer)
110
        setTotalComments(data.total_comments_answer)
121
      })
111
      })
122
      .catch((error) => {
112
      .catch((error) => {
123
        dispatch(
113
        dispatch(
Línea 128... Línea 118...
128
        )
118
        )
129
        throw new Error(error)
119
        throw new Error(error)
130
      })
120
      })
131
  }
121
  }
Línea 132... Línea -...
132
 
-
 
133
  useEffect(() => {
-
 
134
    setComments(defaultComments)
-
 
135
  }, [defaultComments])
-
 
136
 
-
 
137
  useEffect(() => {
-
 
138
    setTotalComments(total_comments)
-
 
139
  }, [total_comments])
-
 
140
 
122
 
141
  return (
123
  return (
142
    <>
124
    <>
143
      <StyledQuestionCard>
125
      <StyledQuestionCard>
144
        <QuestionDetails>
126
        <QuestionDetails>