Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev Autor Línea Nro. Línea
5104 stevensc 1
/* eslint-disable camelcase */
2
import React, { useEffect, useState } from 'react'
3
import { useDispatch } from 'react-redux'
4
import { addNotification } from '../../../redux/notification/notification.actions'
5
import { axios } from '../../../utils'
6
import EmptySection from '../../empty-section/EmptySection'
1 www 7
 
4014 stevensc 8
const PeopleYouMayKnow = () => {
5104 stevensc 9
  const [peopleYouMayKnow, setPeopleYouMayKnow] = useState([])
10
  const [lookMore, setLookMore] = useState(false)
2885 stevensc 11
  const dispatch = useDispatch()
1 www 12
 
2885 stevensc 13
  const handleConnect = (url) => {
14
    axios.post(url)
15
      .then(({ data }) => {
16
        if (!data.success) {
17
          return dispatch(addNotification({
18
            style: 'danger',
19
            msg: typeof data.data === 'string'
20
              ? data.data
21
              : 'Ha ocurrido un error'
22
          }))
23
        }
24
 
4014 stevensc 25
        dispatch(addNotification({
26
          style: 'success',
27
          msg: data.data
28
        }))
29
        return getSuggestion()
2885 stevensc 30
      })
31
  }
32
 
5104 stevensc 33
  const getSuggestion = async (url = '/helpers/people-you-may-know') => {
4014 stevensc 34
    try {
4111 stevensc 35
      const { data: response } = await axios.get(url)
5104 stevensc 36
      if (response.success) setPeopleYouMayKnow(response.data)
4014 stevensc 37
    } catch (error) {
5104 stevensc 38
      console.log(error)
4014 stevensc 39
    }
40
  }
41
 
42
  useEffect(() => {
43
    getSuggestion()
5104 stevensc 44
  }, [])
4014 stevensc 45
 
4110 stevensc 46
  const dataSlice = () => {
47
    let infoFollows = [...peopleYouMayKnow]
48
    if (!lookMore) {
49
      infoFollows = infoFollows.slice(0, 3)
50
    }
51
    return infoFollows
52
  }
53
 
1 www 54
  return (
3921 stevensc 55
    <div className='peopleYouMayKnow'>
2890 stevensc 56
      <div className="sd-title d-flex align-items-center justify-content-between">
5104 stevensc 57
        <h3>{`${LABELS.CONNECT_WITH}:`}</h3>
58
        {peopleYouMayKnow.length >= 4 &&
4111 stevensc 59
          <label onClick={() => setLookMore(!lookMore)}>
5104 stevensc 60
            {lookMore ? LABELS.VIEW_LESS : LABELS.VIEW_MORE}
61
          </label>}
2890 stevensc 62
      </div>
3837 stevensc 63
      <div className='suggest-list'>
4014 stevensc 64
        {peopleYouMayKnow.length
4110 stevensc 65
          ? dataSlice().map(({ id, image, link_cancel, link_request, name, profile }) =>
4090 stevensc 66
            <div className='user' key={id}>
3921 stevensc 67
              <div className="w-100 d-flex align-items-center" style={{ gap: '.5rem' }}>
68
                <a href={profile} target="_blank" rel="noreferrer">
69
                  <img src={image} alt={`${name} profile image`} />
70
                </a>
4090 stevensc 71
                <h4 className="break-ellipsis">{name}</h4>
3921 stevensc 72
              </div>
4091 stevensc 73
              {link_request &&
74
                <button
75
                  className="btn btn-primary"
76
                  onClick={() => handleConnect(link_request)}
77
                >
5104 stevensc 78
                  {LABELS.CONNECT}
4091 stevensc 79
                </button>
80
              }
81
              {link_cancel &&
82
                <button
83
                  className="btn btn-secondary"
84
                  onClick={() => handleConnect(link_cancel)}
85
                >
5104 stevensc 86
                  {LABELS.CANCEL}
4091 stevensc 87
                </button>
88
              }
3921 stevensc 89
            </div>
90
          )
5104 stevensc 91
          : <EmptySection align='left' message={LABELS.DATATABLE_EMPTY} />
3506 stevensc 92
        }
2890 stevensc 93
      </div>
5104 stevensc 94
    </div>
95
  )
96
}
1 www 97
 
5104 stevensc 98
export default PeopleYouMayKnow