Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 7086 Rev 7097
Línea 1... Línea 1...
1
import React, { useRef, useState } from 'react'
1
import React, { useRef, useState } from 'react'
2
import { axios } from '../../utils'
2
import { axios } from '../../utils'
3
import { useSelector } from 'react-redux'
3
import { useDispatch, useSelector } from 'react-redux'
4
import { addNotification } from '../../redux/notification/notification.actions'
4
import { addNotification } from '../../redux/notification/notification.actions'
5
import styled from 'styled-components'
5
import styled from 'styled-components'
Línea 6... Línea 6...
6
 
6
 
7
import Spinner from '../UI/Spinner'
7
import Spinner from '../UI/Spinner'
Línea 12... Línea 12...
12
 
12
 
13
const StyledSpinnerContainer = styled.div`
13
const StyledSpinnerContainer = styled.div`
14
  position: absolute;
14
  position: absolute;
15
  left: 0;
15
  left: 0;
16
  top: 0;
16
  top: 0;
-
 
17
  width: 100%;
17
  padding: 100px;
18
  height: 100%;
18
  background: rgba(255, 255, 255, 0.4);
-
 
19
  border-radius: 50%;
-
 
20
  display: flex;
-
 
21
  justify-content: center;
19
  background: rgba(255, 255, 255, 0.4);
22
  align-items: center;
20
  place-items: center;
23
  z-index: 300;
21
  z-index: 50;
24
`
22
`
25
const ProfileItem = ({
23
const ProfileItem = ({
26
  image,
24
  image,
27
  name,
25
  name,
Línea 53... Línea 51...
53
}) => {
51
}) => {
54
  const [isShowConfirmation, setIsShowConfirmation] = useState(false)
52
  const [isShowConfirmation, setIsShowConfirmation] = useState(false)
55
  const [loading, setLoading] = useState(false)
53
  const [loading, setLoading] = useState(false)
56
  const confirmUrl = useRef('')
54
  const confirmUrl = useRef('')
57
  const labels = useSelector(({ intl }) => intl.labels)
55
  const labels = useSelector(({ intl }) => intl.labels)
-
 
56
  const dispatch = useDispatch()
Línea 58... Línea 57...
58
 
57
 
59
  const showConfirm = (url = '') => {
58
  const showConfirm = (url = '') => {
60
    setIsShowConfirmation(true)
59
    setIsShowConfirmation(true)
61
    confirmUrl.current = url
60
    confirmUrl.current = url
Línea 75... Línea 74...
75
    }
74
    }
76
  }
75
  }
Línea 77... Línea 76...
77
 
76
 
78
  const onConfirm = (url) => {
77
  const onConfirm = (url) => {
-
 
78
    setLoading(true)
79
    setLoading(true)
79
 
80
    axios
80
    axios
81
      .post(url)
81
      .post(url)
82
      .then(({ data }) => {
82
      .then(({ data }) => {
83
        if (!data.success) {
83
        if (!data.success) {
84
          const errorMsg =
84
          const errorMessage =
85
            typeof data.data === 'string'
85
            typeof data.data === 'string'
86
              ? data.data
86
              ? data.data
87
              : 'Ha ocurrido un error, Por favor intente más tarde'
-
 
-
 
87
              : labels.error_there_was_an_error
88
          addNotification({
88
 
89
            style: 'danger',
-
 
90
            msg: errorMsg,
89
          dispatch(addNotification({ style: 'danger', msg: errorMessage }))
91
          })
90
          return
92
        }
-
 
93
        const msg = data.data
-
 
-
 
91
        }
94
        addNotification({ style: 'success', msg })
92
 
-
 
93
        if (fetchCallback) fetchCallback()
-
 
94
        dispatch(addNotification({ style: 'success', msg: data }))
-
 
95
      })
-
 
96
      .catch((error) => {
-
 
97
        dispatch(
-
 
98
          addNotification({
-
 
99
            style: 'error',
-
 
100
            msg: labels.error_there_was_an_error,
-
 
101
          })
-
 
102
        )
95
        if (fetchCallback) fetchCallback()
103
        throw new Error(error)
96
      })
-
 
97
      .catch((error) => console.log('>>: error > ', error))
104
      })
98
      .finally(() => {
105
      .finally(() => {
99
        confirmUrl.current = ''
106
        confirmUrl.current = ''
100
        setLoading(false)
107
        setLoading(false)
101
      })
108
      })
Línea 102... Línea 109...
102
  }
109
  }
103
 
110
 
-
 
111
  const handleUnfollow = (link_unfollow) => {
104
  const handleUnfollow = async (link_unfollow) => {
112
    setLoading(true)
-
 
113
    axios
105
    setLoading(true)
114
      .post(link_unfollow)
-
 
115
      .then((response) => {
-
 
116
        const { data, success } = response.data
-
 
117
 
-
 
118
        if (!success) {
Línea 106... Línea 119...
106
    await axios.post(link_unfollow).then(({ data }) => {
119
          const errorMessage =
107
      if (data.success) fetchCallback()
120
            typeof data === 'string' ? data : labels.error_there_was_an_error
108
 
121
 
-
 
122
          dispatch(addNotification({ style: 'danger', msg: errorMessage }))
109
      typeof data.data === 'string' &&
123
          return
110
        addNotification({
124
        }
111
          style: 'danger',
-
 
112
          msg: data.data,
125
 
113
        })
126
        fetchCallback()
Línea 114... Línea 127...
114
    })
127
      })
115
    setLoading(false)
128
      .finally(() => setLoading(false))
116
  }
129
  }