Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 2611 | Rev 3198 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1309 steven 1
import React from 'react';
2
import { useState } from 'react';
3
import { useLayoutEffect } from 'react';
3197 stevensc 4
import { useDispatch } from 'react-redux';
2468 stevensc 5
import ProfileInfo from '../dashboard/components/home-section/ProfileInfo';
6
import SocialNetworks from '../dashboard/components/home-section/SocialNetworks';
3197 stevensc 7
import { addNotification } from '../redux/notification/notification.actions';
1309 steven 8
import { axios } from '../utils';
1307 steven 9
 
2470 stevensc 10
const Notifications = ({ backendVars }) => {
2468 stevensc 11
 
2470 stevensc 12
  const { image, fullName, country, visits, connections, description } = backendVars
1309 steven 13
  const [notifications, setNotifications] = useState([]);
3197 stevensc 14
  const dispatch = useDispatch()
2468 stevensc 15
 
1309 steven 16
  const handleNotifications = async () => {
1310 steven 17
    try {
18
      const _notifications = await axios.get('/notifications');
19
      setNotifications(_notifications.data.data)
2468 stevensc 20
      console.log('>>: _notifications ', notifications)
1310 steven 21
    } catch (error) {
22
      console.log('>>: error > ', error)
23
    }
1309 steven 24
  }
2468 stevensc 25
 
3197 stevensc 26
  const markReadNotifications = () => {
27
    axios.post('/notifications/markRead')
28
      .then(({ data }) => data.success)
29
      .catch(err => {
30
        dispatch(addNotification({
31
          style: "error",
32
          msg: 'Disculpe, ha ocurrido un error marcando notificaciones como leidas',
33
        }))
34
        console.log('>>: err > ', err)
35
      })
36
  }
37
 
1309 steven 38
  useLayoutEffect(() => {
39
    handleNotifications();
40
  }, []);
2468 stevensc 41
 
1307 steven 42
  return (
1309 steven 43
    <section className="notifications-page">
2468 stevensc 44
      <div className="card notifications-grid">
2478 stevensc 45
        <div className='main-left-sidebar' style={{ marginTop: '1.25rem' }}>
2468 stevensc 46
          <ProfileInfo
47
            image={image}
48
            fullName={fullName}
49
            description={description}
50
            visits={visits}
51
            country={country}
52
            connections={connections}
53
          />
54
          <SocialNetworks />
55
        </div>
1311 steven 56
        <div className="card-body">
57
          <div className="container">
2471 stevensc 58
            <h2
59
              className="card-title"
60
              style={{ fontSize: '1.7rem', fontWeight: '700' }}
61
            >
62
              Notificaciones
63
            </h2>
2476 stevensc 64
            <div className="messages-sec border-gray px-5 py-4">
2471 stevensc 65
              <ul>
66
                {
67
                  notifications.length
2611 stevensc 68
                    ? notifications.reverse().map((element, i) => (
2471 stevensc 69
                      <li key={i}>
2478 stevensc 70
                        <div className="notification-item">
2473 stevensc 71
                          <a href={element.link}>
72
                            {element.message}
73
                          </a>
74
                          <span>
75
                            {element.time_elapsed}
76
                          </span>
2471 stevensc 77
                        </div>
78
                      </li>
1310 steven 79
                    )
2471 stevensc 80
                    )
81
                    :
82
                    <div
83
                      className="section_admin_title_buttons w-100"
84
                      style={{ display: 'grid', placeItems: 'center' }}
85
                    >
2472 stevensc 86
                      <h1 className="title">No hay notificaciones</h1>
2471 stevensc 87
                    </div>
88
                }
89
              </ul>
1311 steven 90
            </div>
91
          </div>
1309 steven 92
        </div>
93
      </div>
2468 stevensc 94
    </section >
1307 steven 95
  )
96
}
2469 stevensc 97
export default Notifications