Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 7209 | Rev 7212 | Ir a la última revisión | | Comparar con el anterior | 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'
7211 stevensc 3
import { useLocation } from 'react-router-dom'
7209 stevensc 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
 
11
  const getQuestion = () => {
12
    axios
7211 stevensc 13
      .get(pathname, {
7209 stevensc 14
        headers: {
15
          'Content-Type': 'application/json',
16
        },
17
      })
18
      .then((response) => {
19
        const { data, success } = response.data
20
 
21
        if (!success) {
22
          const errorMessage =
23
            typeof data === 'string'
24
              ? data
25
              : 'Error interno. Por favor, inténtelo de nuevo más tarde.'
26
 
27
          dispatch(addNotification({ style: 'danger', msg: errorMessage }))
28
          return
29
        }
30
 
31
        console.log(data)
32
      })
33
      .catch((error) => {
34
        dispatch(
35
          addNotification({
36
            style: 'danger',
37
            msg: 'Error interno. Por favor, inténtelo de nuevo más tarde.',
38
          })
39
        )
40
        throw new Error(error)
41
      })
42
  }
43
 
44
  useEffect(() => {
45
    getQuestion()
46
  }, [])
47
 
48
  return <div>MyCoachViewPage</div>
49
}
50
 
51
export default MyCoachViewPage