Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 3274 Rev 3276
Línea 1... Línea 1...
1
/* eslint-disable react/prop-types */
1
/* eslint-disable react/prop-types */
2
import React from 'react';
2
import React from 'react';
3
import { useState } from 'react';
3
import { useState } from 'react';
4
import { useLayoutEffect } from 'react';
4
import { useLayoutEffect } from 'react';
5
import { useDispatch } from 'react-redux';
5
import { connect } from 'react-redux';
6
import ProfileInfo from '../dashboard/components/home-section/ProfileInfo';
6
import ProfileInfo from '../dashboard/components/home-section/ProfileInfo';
7
import SocialNetworks from '../dashboard/components/home-section/SocialNetworks';
7
import SocialNetworks from '../dashboard/components/home-section/SocialNetworks';
8
import { addNotification } from '../redux/notification/notification.actions';
8
import { addNotification } from '../redux/notification/notification.actions';
9
import { axios } from '../utils';
9
import { axios } from '../utils';
Línea 10... Línea 10...
10
 
10
 
Línea 11... Línea 11...
11
const Notifications = ({ backendVars }) => {
11
const Notifications = ({ backendVars }) => {
12
 
12
 
13
  const { image, fullName, country, visits, connections, description } = backendVars
-
 
Línea 14... Línea 13...
14
  const [notifications, setNotifications] = useState([]);
13
  const { image, fullName, country, visits, connections, description } = backendVars
15
  const dispatch = useDispatch()
14
  const [notifications, setNotifications] = useState([]);
16
 
15
 
17
  const handleNotifications = async () => {
16
  const handleNotifications = async () => {
Línea 24... Línea 23...
24
    }
23
    }
25
  }
24
  }
Línea 26... Línea 25...
26
 
25
 
27
  const markReadNotifications = () => {
26
  const markReadNotifications = () => {
28
    axios.post('/notifications/mark-all-read')
27
    axios.post('/notifications/mark-all-read')
-
 
28
      .then(({ data }) => {
-
 
29
        !data.success && addNotification({ style: 'danger', msg: data.data })
-
 
30
        addNotification({ style: 'success', msg: data.data })
29
      .then(({ data }) => data.success)
31
      })
30
      .catch(err => {
32
      .catch(err => {
31
        dispatch(addNotification({
33
        addNotification({
32
          style: "error",
34
          style: "danger",
33
          msg: 'Disculpe, ha ocurrido un error marcando notificaciones como leidas',
35
          msg: 'Disculpe, ha ocurrido un error marcando notificaciones como leidas',
34
        }))
36
        })
35
        console.log('>>: err > ', err)
37
        console.log('>>: err > ', err)
36
      })
38
      })
Línea 37... Línea 39...
37
  }
39
  }
38
 
40
 
39
  useLayoutEffect(() => {
-
 
40
    handleNotifications();
41
  useLayoutEffect(() => {
Línea 41... Línea 42...
41
    markReadNotifications()
42
    handleNotifications();
42
  }, []);
43
  }, []);
43
 
44
 
Línea 63... Línea 64...
63
            >
64
            >
64
              Notificaciones
65
              Notificaciones
65
            </h2>
66
            </h2>
66
            <div className="messages-sec border-gray px-5 py-4">
67
            <div className="messages-sec border-gray px-5 py-4">
67
              <ul>
68
              <ul>
68
                {
-
 
69
                  notifications.length
69
                {notifications.length
70
                    ? notifications.reverse().map((element, i) => (
70
                  ? [...notifications].reverse().map((element, i) =>
71
                      <li key={i}>
71
                    <li key={i}>
72
                        <div className="notification-item">
72
                      <div className="notification-item">
73
                          <a href={element.link}>
73
                        <a href={element.link}>
74
                            {element.message}
74
                          {element.message}
75
                          </a>
75
                        </a>
76
                          <span>
76
                        <span>
77
                            {element.time_elapsed}
77
                          {element.time_elapsed}
78
                          </span>
78
                        </span>
79
                        </div>
79
                      </div>
80
                      </li>
80
                    </li>
81
                    )
-
 
82
                    )
81
                  )
83
                    :
82
                  :
84
                    <div
83
                  <div
85
                      className="section_admin_title_buttons w-100"
84
                    className="section_admin_title_buttons w-100"
86
                      style={{ display: 'grid', placeItems: 'center' }}
85
                    style={{ display: 'grid', placeItems: 'center' }}
87
                    >
86
                  >
88
                      <h1 className="title">No hay notificaciones</h1>
87
                    <h1 className="title">No hay notificaciones</h1>
89
                    </div>
88
                  </div>
90
                }
89
                }
91
              </ul>
90
              </ul>
92
            </div>
91
            </div>
93
          </div>
92
          </div>
94
        </div>
93
        </div>
95
      </div>
94
      </div>
96
    </section >
95
    </section >
97
  )
96
  )
98
}
97
}
99
export default Notifications
-
 
100
98
const mapDispatchToProps = {
-
 
99
  addNotification: (notification) => addNotification(notification)
-
 
100
};
-
 
101
 
-
 
102
export default connect(null, mapDispatchToProps)(Notifications)
-
 
103
101
104