Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 7211 | Ir a la última revisión | | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
7209 stevensc 1
import React, { useEffect } from 'react'
2
import { axios } from '../../utils'
3
import { useLocation, useParams } from 'react-router-dom'
4
import { addNotification } from '../../redux/notification/notification.actions'
5
import { useDispatch } from 'react-redux'
6
 
7
const MyCoachViewPage = () => {
8
  const dispatch = useDispatch()
9
  const { pathname } = useLocation()
10
  const { uuid } = useParams()
11
 
12
  const getQuestion = () => {
13
    axios
14
      .get(`${pathname}/${uuid}`, {
15
        headers: {
16
          'Content-Type': 'application/json',
17
        },
18
      })
19
      .then((response) => {
20
        const { data, success } = response.data
21
 
22
        if (!success) {
23
          const errorMessage =
24
            typeof data === 'string'
25
              ? data
26
              : 'Error interno. Por favor, inténtelo de nuevo más tarde.'
27
 
28
          dispatch(addNotification({ style: 'danger', msg: errorMessage }))
29
          return
30
        }
31
 
32
        console.log(data)
33
      })
34
      .catch((error) => {
35
        dispatch(
36
          addNotification({
37
            style: 'danger',
38
            msg: 'Error interno. Por favor, inténtelo de nuevo más tarde.',
39
          })
40
        )
41
        throw new Error(error)
42
      })
43
  }
44
 
45
  useEffect(() => {
46
    getQuestion()
47
  }, [])
48
 
49
  return <div>MyCoachViewPage</div>
50
}
51
 
52
export default MyCoachViewPage