| 5179 | stevensc | 1 | import React, { useEffect, useState } from 'react'
 | 
        
           |  |  | 2 | import { connect } from 'react-redux'
 | 
        
           |  |  | 3 | import { debounce } from '../../../utils'
 | 
        
           |  |  | 4 | import { searchEntities } from '../../../services/search'
 | 
        
           |  |  | 5 | import { addNotification } from '../../../redux/notification/notification.actions'
 | 
        
           |  |  | 6 | import Spinner from '../../../shared/loading-spinner/Spinner'
 | 
        
           |  |  | 7 | import Profile from '../../../components/Profile'
 | 
        
           |  |  | 8 | import SearchList from '../../../components/SearchList'
 | 
        
           |  |  | 9 | import TitleSection from '../../../components/TitleSection'
 | 
        
           |  |  | 10 | import EmptySection from '../../../shared/empty-section/EmptySection'
 | 
        
           | 1 | www | 11 |   | 
        
           | 5179 | stevensc | 12 | const InvitationsReceived = () => {
 | 
        
           |  |  | 13 |   const [invitationsReceived, setInvitationsReceived] = useState([])
 | 
        
           |  |  | 14 |   const [loading, setLoading] = useState(true)
 | 
        
           | 1 | www | 15 |   | 
        
           | 5179 | stevensc | 16 |   useEffect(() => {
 | 
        
           |  |  | 17 |     getInvitationsReceived()
 | 
        
           |  |  | 18 |   }, [])
 | 
        
           | 1 | www | 19 |   | 
        
           | 5179 | stevensc | 20 |   const getInvitationsReceived = async (searchValue = '') => {
 | 
        
           |  |  | 21 |     setLoading(true)
 | 
        
           |  |  | 22 |     const response = await searchEntities('group/invitations-received', searchValue)
 | 
        
           | 1 | www | 23 |   | 
        
           | 5179 | stevensc | 24 |     if (!response.success) {
 | 
        
           |  |  | 25 |       addNotification({ style: 'danger', msg: response.data })
 | 
        
           |  |  | 26 |       setLoading(false)
 | 
        
           |  |  | 27 |       return
 | 
        
           |  |  | 28 |     }
 | 
        
           | 1 | www | 29 |   | 
        
           | 5179 | stevensc | 30 |     setInvitationsReceived(response.data)
 | 
        
           |  |  | 31 |     setLoading(false)
 | 
        
           |  |  | 32 |   }
 | 
        
           | 1 | www | 33 |   | 
        
           | 5179 | stevensc | 34 |   const handleSearch = debounce((value) => getInvitationsReceived(value), 500)
 | 
        
           | 1 | www | 35 |   | 
        
           |  |  | 36 |   return (
 | 
        
           | 5179 | stevensc | 37 |     <section className="companies-info container">
 | 
        
           |  |  | 38 |       <TitleSection title={LABELS.REQUEST_RECEIVE} />
 | 
        
           |  |  | 39 |       <SearchList onChange={handleSearch} />
 | 
        
           |  |  | 40 |       <div className="companies-list">
 | 
        
           |  |  | 41 |         {loading && <Spinner />}
 | 
        
           |  |  | 42 |         {(!loading && Boolean(!invitationsReceived.length)) && <EmptySection align='left' message={LABELS.DATATABLE_SZERORECORDS} />}
 | 
        
           |  |  | 43 |         {(!loading && Boolean(invitationsReceived.length)) &&
 | 
        
           |  |  | 44 |           invitationsReceived.map((request, index) =>
 | 
        
           |  |  | 45 |             <Profile
 | 
        
           |  |  | 46 |               {...request}
 | 
        
           |  |  | 47 |               key={index}
 | 
        
           |  |  | 48 |               fetchCallback={getInvitationsReceived}
 | 
        
           |  |  | 49 |               btnAcceptTitle={LABELS.GROUP_VIEW}
 | 
        
           |  |  | 50 |             />
 | 
        
           |  |  | 51 |           )}
 | 
        
           | 1 | www | 52 |       </div>
 | 
        
           |  |  | 53 |     </section>
 | 
        
           | 5179 | stevensc | 54 |   )
 | 
        
           |  |  | 55 | }
 | 
        
           | 1 | www | 56 |   | 
        
           |  |  | 57 | const mapDispatchToProps = {
 | 
        
           | 5179 | stevensc | 58 |   addNotification: (notification) => addNotification(notification)
 | 
        
           |  |  | 59 | }
 | 
        
           | 1 | www | 60 |   | 
        
           | 5179 | stevensc | 61 | export default connect(null, mapDispatchToProps)(InvitationsReceived)
 |