Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 2806 | Rev 2873 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 2806 Rev 2864
Línea 1... Línea 1...
1
import React, { useEffect, useState } from 'react'
1
import React from 'react'
2
import { useDispatch, useSelector } from 'react-redux'
2
import { useSelector } from 'react-redux'
-
 
3
import { Search } from '@mui/icons-material'
3
 
4
 
4
import { debounce } from '../../utils'
5
import { debounce } from '@utils'
5
import { searchEntities } from '../../services/items'
6
import { useFetch, useSearchParams } from '@hooks'
6
import { addNotification } from '../../redux/notification/notification.actions'
-
 
7
 
7
 
8
import Spinner from '../../components/UI/Spinner'
8
import Input from '@components/UI/inputs/Input'
9
import SearchBar from '../../components/UI/SearchBar'
-
 
10
import ProfileItem from '../../components/profile/ProfileItem'
-
 
11
import TitleSection from '../../components/UI/TitleSection'
9
import TitleSection from '@components/UI/TitleSection'
12
import EmptySection from '../../components/UI/EmptySection'
10
import CompanyWhenIWorkList from '@components/company/CompanyWhenIWorkList'
13
import LoaderContainer from '../../components/UI/LoaderContainer'
-
 
Línea 14... Línea 11...
14
 
11
 
15
const CompaniesWhenIWorkPage = () => {
-
 
16
  const [companiesWhenIWork, setCompaniesWhenIWork] = useState([])
-
 
17
  const [loading, setLoading] = useState(false)
-
 
18
  const [search, setSearch] = useState('')
-
 
19
 
12
const CompaniesWhenIWorkPage = () => {
20
  const labels = useSelector(({ intl }) => intl.labels)
-
 
Línea 21... Línea 13...
21
  const dispatch = useDispatch()
13
  const labels = useSelector(({ intl }) => intl.labels)
22
 
-
 
23
  const getCompaniesWhenIWork = async (search = '') => {
14
 
24
    setLoading(true)
-
 
25
    try {
15
  const { params, setParams } = useSearchParams()
26
      const { success, data } = await searchEntities(
-
 
27
        'company/i-work-with',
-
 
28
        search
-
 
29
      )
-
 
30
 
-
 
31
      if (!success) {
16
  const {
32
        dispatch(addNotification({ style: 'danger', msg: data }))
17
    data: companies,
33
        setLoading(false)
-
 
34
        return
-
 
35
      }
18
    isLoading,
36
 
-
 
37
      setCompaniesWhenIWork(data)
-
 
38
    } catch (error) {
-
 
39
      dispatch(addNotification({ style: 'danger', msg: error.message }))
-
 
40
    } finally {
-
 
41
      setLoading(false)
-
 
42
    }
19
    refetch
43
  }
20
  } = useFetch('/company/i-work-with' + params)
44
 
-
 
45
  const handleSearch = debounce((value) => setSearch(value), 500)
-
 
46
 
-
 
47
  useEffect(() => {
-
 
Línea 48... Línea 21...
48
    getCompaniesWhenIWork(search)
21
 
49
  }, [search])
22
  const handleSearch = debounce((value) => setParams('search', value), 500)
50
 
23
 
51
  return (
-
 
52
    <>
24
  return (
53
      <TitleSection title={labels.companies_i_work_with} />
-
 
54
 
-
 
55
      <SearchBar onChange={handleSearch} />
-
 
56
 
-
 
57
      {loading ? (
-
 
58
        <LoaderContainer>
-
 
59
          <Spinner />
-
 
60
        </LoaderContainer>
25
    <>
61
      ) : (
-
 
62
        <ul className='companies-list'>
-
 
63
          {companiesWhenIWork.length ? (
26
      <TitleSection title={labels.companies_i_work_with} />
64
            companiesWhenIWork.map(({ id, link_my_company, ...rest }) => (
-
 
65
              <ProfileItem
-
 
66
                key={id}
-
 
67
                link_admin={link_my_company}
-
 
68
                fetchCallback={getCompaniesWhenIWork}
27
      <Input icon={<Search />} onChange={handleSearch} />
69
                btnAcceptTitle={labels.view_company}
-
 
70
                btnLeaveTitle={labels.company_leave}
-
 
71
                {...rest}
-
 
72
              />
-
 
73
            ))
28
      <CompanyWhenIWorkList
74
          ) : (
-
 
75
            <EmptySection
-
 
76
              align='left'
-
 
77
              message={labels.datatable_szerorecords}
-
 
78
            />
29
        companies={companies}
79
          )}
30
        loading={isLoading}
80
        </ul>
31
        onComplete={refetch}
81
      )}
32
      />
Línea 82... Línea 33...
82
    </>
33
    </>