Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5087 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
5087 stevensc 1
/* eslint-disable camelcase */
4241 stevensc 2
/* eslint-disable react/prop-types */
5087 stevensc 3
import React, { useEffect, useState } from 'react'
5174 stevensc 4
import { debounce } from '../../../utils'
5
import { searchEntities } from '../../../services/search'
6
import { addNotification } from '../../../redux/notification/notification.actions'
7
import { useDispatch } from 'react-redux'
5087 stevensc 8
import Spinner from '../../../shared/loading-spinner/Spinner'
9
import Profile from '../../../components/Profile'
10
import SearchList from '../../../components/SearchList'
5174 stevensc 11
import EmptySection from '../../../shared/empty-section/EmptySection'
12
import TitleSection from '../../../components/TitleSection'
1 www 13
 
4241 stevensc 14
const InvitationsReceived = () => {
5087 stevensc 15
  const [companies, setCompanies] = useState([])
16
  const [loading, setLoading] = useState(true)
5174 stevensc 17
  const dispatch = useDispatch()
1 www 18
 
19
  useEffect(() => {
5174 stevensc 20
    getCompanies()
5087 stevensc 21
  }, [])
1 www 22
 
5174 stevensc 23
  const getCompanies = async (searchValue = '') => {
5087 stevensc 24
    setLoading(true)
5174 stevensc 25
    const response = await searchEntities('company/invitations-received', searchValue)
26
 
27
    if (!response.success) {
28
      dispatch(addNotification({ style: 'danger', msg: response.data }))
29
      setLoading(false)
30
      return
31
    }
32
 
33
    setCompanies(response.data)
5087 stevensc 34
    setLoading(false)
35
  }
1 www 36
 
5174 stevensc 37
  const handleSearch = debounce((value) => getCompanies(value), 500)
38
 
1 www 39
  return (
5174 stevensc 40
    <section className="companies-info container">
41
      <TitleSection title={LABELS.INVITATIONS_RECEIVED} />
42
      <SearchList onChange={handleSearch} />
43
      <div className="companies-list position-relative">
44
        {loading && <Spinner />}
45
        {(!loading && Boolean(!companies.length)) && <EmptySection align='left' message={LABELS.DATATABLE_SZERORECORDS} />}
46
        {(!loading && Boolean(companies.length)) &&
47
          companies.map(({ image, name, link_view, link_reject, link_accept }, id) =>
48
            <Profile
49
              key={id}
50
              image={image}
51
              name={name}
52
              link_view={link_view}
53
              link_reject={link_reject}
54
              link_accept={link_accept}
55
              fetchCallback={getCompanies}
56
              btnAcceptTitle={LABELS.VIEW_COMPANY}
57
            />
58
          )}
1 www 59
      </div>
5087 stevensc 60
    </section>
61
  )
62
}
1 www 63
 
5087 stevensc 64
export default InvitationsReceived