Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev Autor Línea Nro. Línea
2798 stevensc 1
import React, { useState } from 'react'
2
import { useSelector } from 'react-redux'
3
import { Container } from '@mui/material'
5 stevensc 4
 
2798 stevensc 5
import { useFetch } from '@hooks'
6
import { debounce } from '@app/utils'
5 stevensc 7
 
2798 stevensc 8
import EmptySection from '@components/UI/EmptySection'
9
import SearchBar from '@components/UI/SearchBar'
10
import Spinner from '@components/UI/Spinner'
11
import TitleSection from '@components/UI/TitleSection'
12
import AddCompanyModal from '@components/modals/AddCompanyModal'
13
import ProfileItem from '@components/profile/ProfileItem'
14
 
5 stevensc 15
const MyCompanies = () => {
16
  const [search, setSearch] = useState('')
2798 stevensc 17
  const [showCompanyModal, setShowCompanyModal] = useState(false)
5 stevensc 18
  const labels = useSelector(({ intl }) => intl.labels)
19
 
2798 stevensc 20
  const {
21
    data: companies,
22
    isLoading,
23
    refetch
24
  } = useFetch(`/company/my-companies?search=${search}`)
5 stevensc 25
 
2798 stevensc 26
  const toggleShowCompanyModal = () => setShowCompanyModal(!showCompanyModal)
5 stevensc 27
 
28
  const handleSearch = debounce((value) => setSearch(value), 500)
29
 
30
  return (
2798 stevensc 31
    <>
32
      <Container>
33
        <TitleSection
34
          title={labels.my_companies}
35
          onAdd={toggleShowCompanyModal}
36
          addLabel={`${labels.add} ${labels.company?.toLowerCase()}`}
37
        />
2072 stevensc 38
 
2798 stevensc 39
        <SearchBar onChange={handleSearch} />
2072 stevensc 40
 
1215 stevensc 41
        <ul className='companies-list'>
2798 stevensc 42
          {isLoading ? <Spinner /> : null}
5 stevensc 43
          {companies.length ? (
44
            companies.map(({ id, link_my_company, ...rest }) => (
45
              <ProfileItem
46
                key={id}
47
                link_admin={link_my_company}
48
                btnAcceptTitle={labels.view_company}
49
                {...rest}
50
              />
51
            ))
52
          ) : (
53
            <EmptySection
1215 stevensc 54
              align='left'
5 stevensc 55
              message={labels.datatable_szerorecords}
56
            />
57
          )}
58
        </ul>
2798 stevensc 59
      </Container>
5 stevensc 60
      <AddCompanyModal
2798 stevensc 61
        show={showCompanyModal}
5 stevensc 62
        onHide={toggleShowCompanyModal}
2798 stevensc 63
        fetchCompanies={refetch}
5 stevensc 64
      />
2798 stevensc 65
    </>
5 stevensc 66
  )
67
}
68
 
69
export default MyCompanies