Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 535 Rev 1484
Línea 1... Línea 1...
1
import React, { useEffect, useRef, useState } from 'react'
1
import React, { useEffect, useRef, useState } from 'react'
2
import { axios } from '../../utils'
-
 
3
import { useHistory, useLocation } from 'react-router-dom'
2
import { useHistory, useLocation } from 'react-router-dom'
4
import { addNotification } from '../../redux/notification/notification.actions'
-
 
5
import { useDispatch, useSelector } from 'react-redux'
3
import { useDispatch, useSelector } from 'react-redux'
-
 
4
 
6
import { Col, Container, Row } from 'react-bootstrap'
5
import { axios } from '../../utils'
7
import styled from 'styled-components'
6
import { addNotification } from '../../redux/notification/notification.actions'
Línea 8... Línea 7...
8
 
7
 
9
import QuestionCard from '../../components/my-coach/QuestionCard'
8
import QuestionCard from '../../components/my-coach/QuestionCard'
10
import AnswerCard from '../../components/my-coach/AnswerCard'
9
import AnswerCard from '../../components/my-coach/AnswerCard'
11
import AnswerModal from '../../components/my-coach/AnswerModal'
10
import AnswerModal from '../../components/my-coach/AnswerModal'
12
import ConfirmModal from '../../components/modals/ConfirmModal'
11
import ConfirmModal from '../../components/modals/ConfirmModal'
13
import TitleSection from '../../components/UI/TitleSection'
-
 
14
 
12
import TitleSection from '../../components/UI/TitleSection'
15
const StyledSection = styled(Col)`
-
 
16
  display: flex;
-
 
17
  flex-direction: column;
-
 
18
  gap: 0.5rem;
-
 
19
  margin: auto;
-
 
Línea 20... Línea 13...
20
`
13
import { Container, Grid } from '@mui/material'
21
 
14
 
22
const MyCoachViewPage = () => {
15
const MyCoachViewPage = () => {
23
  const [question, setQuestion] = useState({})
16
  const [question, setQuestion] = useState({})
Línea 33... Línea 26...
33
 
26
 
34
  const getQuestion = () => {
27
  const getQuestion = () => {
35
    axios
28
    axios
36
      .get(pathname, {
29
      .get(pathname, {
37
        headers: {
30
        headers: {
38
          'Content-Type': 'application/json',
31
          'Content-Type': 'application/json'
39
        },
32
        }
40
      })
33
      })
41
      .then((response) => {
34
      .then((response) => {
Línea 42... Línea 35...
42
        const { data, success } = response.data
35
        const { data, success } = response.data
Línea 56... Línea 49...
56
      })
49
      })
57
      .catch((error) => {
50
      .catch((error) => {
58
        dispatch(
51
        dispatch(
59
          addNotification({
52
          addNotification({
60
            style: 'danger',
53
            style: 'danger',
61
            msg: 'Error interno. Por favor, inténtelo de nuevo más tarde.',
54
            msg: 'Error interno. Por favor, inténtelo de nuevo más tarde.'
62
          })
55
          })
63
        )
56
        )
64
        throw new Error(error)
57
        throw new Error(error)
65
      })
58
      })
66
  }
59
  }
Línea 87... Línea 80...
87
      })
80
      })
88
      .catch((error) => {
81
      .catch((error) => {
89
        dispatch(
82
        dispatch(
90
          addNotification({
83
          addNotification({
91
            style: 'danger',
84
            style: 'danger',
92
            msg: 'Ha ocurrido un error, por favor intente más tarde.',
85
            msg: 'Ha ocurrido un error, por favor intente más tarde.'
93
          })
86
          })
94
        )
87
        )
95
        throw new Error(error)
88
        throw new Error(error)
96
      })
89
      })
97
  }
90
  }
Línea 114... Línea 107...
114
 
107
 
115
        setQuestion((prevQuestion) => ({
108
        setQuestion((prevQuestion) => ({
116
          ...prevQuestion,
109
          ...prevQuestion,
117
          comments: data.total_comments,
110
          comments: data.total_comments,
118
          answers: data.total_answers,
111
          answers: data.total_answers,
119
          reactions: data.total_reactions,
112
          reactions: data.total_reactions
120
        }))
113
        }))
121
        closeModal()
114
        closeModal()
122
      })
115
      })
123
      .catch((error) => {
116
      .catch((error) => {
124
        dispatch(
117
        dispatch(
125
          addNotification({
118
          addNotification({
126
            style: 'danger',
119
            style: 'danger',
127
            msg: 'Ha ocurrido un error, por favor intente más tarde.',
120
            msg: 'Ha ocurrido un error, por favor intente más tarde.'
128
          })
121
          })
129
        )
122
        )
130
        throw new Error(error)
123
        throw new Error(error)
131
      })
124
      })
Línea 180... Línea 173...
180
  }
173
  }
Línea 181... Línea 174...
181
 
174
 
182
  const updateTotalComments = (total) => {
175
  const updateTotalComments = (total) => {
183
    setQuestion({
176
    setQuestion({
184
      ...question,
177
      ...question,
185
      comments: total,
178
      comments: total
186
    })
179
    })
Línea 187... Línea 180...
187
  }
180
  }
188
 
181
 
189
  const updateTotalReactions = (total) => {
182
  const updateTotalReactions = (total) => {
190
    setQuestion({
183
    setQuestion({
191
      ...question,
184
      ...question,
192
      reactions: total,
185
      reactions: total
Línea 193... Línea 186...
193
    })
186
    })
194
  }
187
  }
Línea 218... Línea 211...
218
        })
211
        })
219
        .catch((error) => {
212
        .catch((error) => {
220
          dispatch(
213
          dispatch(
221
            addNotification({
214
            addNotification({
222
              style: 'danger',
215
              style: 'danger',
223
              msg: 'Error interno. Por favor, inténtelo de nuevo más tarde.',
216
              msg: 'Error interno. Por favor, inténtelo de nuevo más tarde.'
224
            })
217
            })
225
          )
218
          )
226
          throw new Error(error)
219
          throw new Error(error)
227
        })
220
        })
228
    }
221
    }
229
  }, [question])
222
  }, [question])
Línea 230... Línea 223...
230
 
223
 
231
  return (
224
  return (
232
    <>
225
    <>
233
      <Container as="section" className="px-0">
226
      <Container sx={{ px: 0 }}>
-
 
227
        <TitleSection title={labels.my_coach} />
-
 
228
 
234
        <TitleSection title={labels.my_coach} />
229
        <Grid container>
-
 
230
          <Grid
-
 
231
            item
-
 
232
            xs={12}
-
 
233
            md={8}
-
 
234
            mx='auto'
-
 
235
            sx={{
235
        <Row>
236
              display: 'flex',
-
 
237
              flexDirection: 'column',
-
 
238
              gap: 1
-
 
239
            }}
236
          <StyledSection md="8">
240
          >
237
            <QuestionCard
241
            <QuestionCard
238
              key={question.uuid}
242
              key={question.uuid}
239
              onEdit={editQuestion}
243
              onEdit={editQuestion}
240
              onDelete={deleteQuestion}
244
              onDelete={deleteQuestion}
241
              onReply={addAnswer}
245
              onReply={addAnswer}
242
              {...question}
246
              {...question}
-
 
247
            />
243
            />
248
 
244
            {answers.map((answer) => (
249
            {answers.map((answer) => (
245
              <AnswerCard
250
              <AnswerCard
246
                key={answer.unique}
251
                key={answer.unique}
247
                {...answer}
252
                {...answer}
248
                onEdit={editAnswer}
253
                onEdit={editAnswer}
249
                onDelete={deleteAnswer}
254
                onDelete={deleteAnswer}
250
                updateComments={updateTotalComments}
255
                updateComments={updateTotalComments}
251
                updateReactions={updateTotalReactions}
256
                updateReactions={updateTotalReactions}
252
              />
257
              />
253
            ))}
258
            ))}
254
          </StyledSection>
259
          </Grid>
255
        </Row>
260
        </Grid>
256
      </Container>
261
      </Container>
257
      <AnswerModal
262
      <AnswerModal
258
        url={currentAnswer ? actionUrl.current : addUrl.current}
263
        url={currentAnswer ? actionUrl.current : addUrl.current}
259
        show={['addAnswer', 'editAnswer'].includes(modalShow)}
264
        show={['addAnswer', 'editAnswer'].includes(modalShow)}