Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev Autor Línea Nro. Línea
5107 stevensc 1
/* eslint-disable camelcase */
2
import React, { useEffect, useState } from 'react'
3
import { axios } from '../../../../utils'
4
import { useDispatch } from 'react-redux'
5
import { addNotification } from '../../../../redux/notification/notification.actions'
6
import EastIcon from '@mui/icons-material/East'
7
import EmptySection from '../../../../shared/empty-section/EmptySection'
4323 stevensc 8
import './Widget.scss'
4322 stevensc 9
 
10
const PeopleYouMayKnow = () => {
5107 stevensc 11
  const [peopleYouMayKnow, setPeopleYouMayKnow] = useState([])
12
  const dispatch = useDispatch()
4322 stevensc 13
 
5107 stevensc 14
  const handleConnect = (url) => {
15
    axios.post(url)
16
      .then(({ data }) => {
17
        if (!data.success) {
18
          return dispatch(addNotification({
19
            style: 'danger',
20
            msg: typeof data.data === 'string'
21
              ? data.data
22
              : 'Ha ocurrido un error'
23
          }))
24
        }
4322 stevensc 25
 
5107 stevensc 26
        dispatch(addNotification({
27
          style: 'success',
28
          msg: data.data
29
        }))
30
        return getSuggestion()
31
      })
32
  }
4322 stevensc 33
 
5107 stevensc 34
  const getSuggestion = async (url = '/helpers/people-you-may-know') => {
35
    try {
36
      const { data: response } = await axios.get(url)
37
      if (response.success) setPeopleYouMayKnow(response.data.slice(0, 3))
38
    } catch (error) {
39
      console.log(error)
4322 stevensc 40
    }
5107 stevensc 41
  }
4322 stevensc 42
 
5107 stevensc 43
  useEffect(() => {
44
    getSuggestion()
45
  }, [])
4322 stevensc 46
 
5107 stevensc 47
  return (
4324 stevensc 48
        <div className='linked__widget'>
4323 stevensc 49
            <div className="linked__widget-header">
5107 stevensc 50
                <h3>{`${LABELS.CONNECT_WITH}:`}</h3>
4322 stevensc 51
            </div>
4326 stevensc 52
            <div className='linked__widget-list'>
4323 stevensc 53
                {peopleYouMayKnow.length
5107 stevensc 54
                  ? peopleYouMayKnow.map(({ id, image, link_cancel, link_request, name, profile }) => {
55
                    return (
4323 stevensc 56
                            <div className="linked__widget-content" key={id}>
57
                                <a href={profile} target="_blank" rel="noreferrer">
58
                                    <img src={image} alt={`${name} profile image`} />
59
                                </a>
60
                                <div className="linked__widget-info">
61
                                    <h4>{name}</h4>
62
                                    {link_request &&
63
                                        <button
64
                                            className="btn btn-primary"
65
                                            onClick={() => handleConnect(link_request)}
66
                                        >
5107 stevensc 67
                                            {LABELS.CONNECT}
4323 stevensc 68
                                        </button>
69
                                    }
70
                                    {link_cancel &&
71
                                        <button
72
                                            className="btn btn-secondary"
73
                                            onClick={() => handleConnect(link_cancel)}
74
                                        >
5107 stevensc 75
                                            {LABELS.CANCEL}
4323 stevensc 76
                                        </button>
77
                                    }
78
                                </div>
79
                            </div>
5107 stevensc 80
                    )
81
                  })
82
                  : <EmptySection message="Sin sugerencias" />
4323 stevensc 83
                }
84
            </div>
85
            <a href="/connection/people-you-may-know" target='_blank' >
5107 stevensc 86
                {LABELS.VIEW_RECOMMENDATIONS}
4323 stevensc 87
                <EastIcon className="ml-2" />
88
            </a>
5289 stevensc 89
        </div>
5107 stevensc 90
  )
91
}
4322 stevensc 92
 
5107 stevensc 93
export default PeopleYouMayKnow