Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 3311 Rev 3313
Línea 1... Línea 1...
1
/* eslint-disable react/prop-types */
1
/* eslint-disable react/prop-types */
2
import React, { useState, useLayoutEffect, useRef } from 'react';
2
import React, { useState, useLayoutEffect, useRef } from 'react';
3
import { axios } from '../utils';
3
import { axios } from '../utils';
4
import { connect } from 'react-redux';
-
 
5
import { BiDotsVerticalRounded } from 'react-icons/bi';
4
import { BiDotsVerticalRounded } from 'react-icons/bi';
6
import { FaTrash } from 'react-icons/fa';
5
import { FaTrash } from 'react-icons/fa';
7
import { addNotification } from '../redux/notification/notification.actions';
6
import { addNotification } from '../redux/notification/notification.actions';
8
import ProfileInfo from '../dashboard/components/home-section/ProfileInfo';
7
import ProfileInfo from '../dashboard/components/home-section/ProfileInfo';
9
import SocialNetworks from '../dashboard/components/home-section/SocialNetworks';
8
import SocialNetworks from '../dashboard/components/home-section/SocialNetworks';
10
import ConfirmModal from '../shared/confirm-modal/ConfirmModal';
9
import ConfirmModal from '../shared/confirm-modal/ConfirmModal';
-
 
10
import { useDispatch } from 'react-redux';
Línea 11... Línea 11...
11
 
11
 
Línea 12... Línea 12...
12
const Notifications = ({ backendVars }) => {
12
const Notifications = ({ backendVars }) => {
13
 
13
 
14
  const { image, fullName, country, visits, connections, description } = backendVars
14
  const { image, fullName, country, visits, connections, description } = backendVars
15
  const [notifications, setNotifications] = useState([])
15
  const [notifications, setNotifications] = useState([])
-
 
16
  const [displayOption, setDisplayOption] = useState(false)
16
  const [displayOption, setDisplayOption] = useState(false)
17
  const [confirmModalShow, setConfirmModalShow] = useState(false);
Línea 17... Línea 18...
17
  const [confirmModalShow, setConfirmModalShow] = useState(false);
18
  const dispatch = useDispatch()
Línea 18... Línea 19...
18
  const menuOptions = useRef(null)
19
  const menuOptions = useRef(null)
Línea 30... Línea 31...
30
 
31
 
31
  const markReadNotifications = () => {
32
  const markReadNotifications = () => {
32
    axios.post('/notifications/mark-all-read')
33
    axios.post('/notifications/mark-all-read')
33
      .then(({ data }) => {
34
      .then(({ data }) => {
34
        !data.success
35
        !data.success
35
          ? addNotification({ style: 'danger', msg: data.data })
36
          ? dispatch(addNotification({ style: 'danger', msg: data.data }))
36
          : addNotification({ style: 'success', msg: data.data })
37
          : dispatch(addNotification({ style: 'success', msg: data.data }))
37
      })
38
      })
38
      .catch(err => {
39
      .catch(err => {
39
        addNotification({
40
        dispatch(addNotification({
40
          style: "danger",
41
          style: "danger",
41
          msg: 'Disculpe, ha ocurrido un error marcando notificaciones como leidas',
42
          msg: 'Disculpe, ha ocurrido un error marcando notificaciones como leidas',
42
        })
43
        }))
43
        console.log('>>: err > ', err)
44
        console.log('>>: err > ', err)
44
      })
45
      })
Línea 45... Línea 46...
45
  }
46
  }
46
 
47
 
47
  const deleteAllNotifications = () => {
48
  const deleteAllNotifications = () => {
48
    axios.post('/notifications/clear')
49
    axios.post('/notifications/clear')
49
      .then(({ data }) => {
50
      .then(({ data }) => {
50
        if (!data.success) addNotification({ style: 'danger', msg: data.data })
51
        if (!data.success) dispatch(addNotification({ style: 'danger', msg: data.data }))
51
        addNotification({ style: 'success', msg: data.data })
52
        dispatch(addNotification({ style: 'success', msg: data.data }))
52
        setNotifications([])
53
        setNotifications([])
53
      })
54
      })
Línea 54... Línea 55...
54
      .catch(err => addNotification({ style: "danger", msg: `Error: ${err}` }))
55
      .catch(err => dispatch(addNotification({ style: "danger", msg: `Error: ${err}` })))
55
  }
56
  }
56
 
57
 
Línea 101... Línea 102...
101
                    <div className={`feed-options ${displayOption ? 'active' : ''}`} ref={menuOptions} >
102
                    <div className={`feed-options ${displayOption ? 'active' : ''}`} ref={menuOptions} >
102
                      <ul>
103
                      <ul>
103
                        <li>
104
                        <li>
104
                          <button
105
                          <button
105
                            className="option-btn mb-2"
106
                            className="option-btn mb-2"
106
                            onClick={deleteAllNotifications}
107
                            onClick={handleConfirmModalShow}
107
                          >
108
                          >
108
                            <FaTrash className="mr-1" />
109
                            <FaTrash className="mr-1" />
109
                            Borrar notificaciones
110
                            Borrar notificaciones
110
                          </button>
111
                          </button>
111
                        </li>
112
                        </li>
Línea 149... Línea 150...
149
        onAccept={deleteAllNotifications}
150
        onAccept={deleteAllNotifications}
150
      />
151
      />
151
    </>
152
    </>
152
  )
153
  )
153
}
154
}
154
const mapDispatchToProps = {
-
 
155
  addNotification: (notification) => addNotification(notification)
-
 
156
};
-
 
Línea 157... Línea -...
157
 
-
 
158
export default connect(null, mapDispatchToProps)(Notifications)
155
 
-
 
156
export default Notifications
159
157