Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 2154 Rev 2798
Línea 1... Línea 1...
1
import React, { useEffect, useState } from 'react'
1
import React, { useState } from 'react'
2
import { useDispatch, useSelector } from 'react-redux'
2
import { useSelector } from 'react-redux'
3
import { debounce } from '../../utils'
3
import { Container } from '@mui/material'
-
 
4
 
4
import { addNotification } from '../../redux/notification/notification.actions'
5
import { useFetch } from '@hooks'
5
import { searchEntities } from '../../services/items'
6
import { debounce } from '@app/utils'
6
 
7
 
7
import Spinner from '../../components/UI/Spinner'
8
import EmptySection from '@components/UI/EmptySection'
8
import SearchBar from '../../components/UI/SearchBar'
9
import SearchBar from '@components/UI/SearchBar'
9
import ProfileItem from '../../components/profile/ProfileItem'
10
import Spinner from '@components/UI/Spinner'
10
import TitleSection from '../../components/UI/TitleSection'
11
import TitleSection from '@components/UI/TitleSection'
11
import EmptySection from '../../components/UI/EmptySection'
12
import AddCompanyModal from '@components/modals/AddCompanyModal'
12
import AddCompanyModal from '../../components/modals/AddCompanyModal'
13
import ProfileItem from '@components/profile/ProfileItem'
Línea 13... Línea 14...
13
 
14
 
14
const MyCompanies = () => {
-
 
15
  const [companies, setCompanies] = useState([])
-
 
16
  const [loading, setLoading] = useState(true)
15
const MyCompanies = () => {
17
  const [search, setSearch] = useState('')
16
  const [search, setSearch] = useState('')
18
  const [showAddCompanyModal, setShowCompanyModal] = useState(false)
17
  const [showCompanyModal, setShowCompanyModal] = useState(false)
19
  const labels = useSelector(({ intl }) => intl.labels)
-
 
Línea 20... Línea -...
20
  const dispatch = useDispatch()
-
 
21
 
18
  const labels = useSelector(({ intl }) => intl.labels)
22
  const getMyCompanies = async (searchValue = '') => {
-
 
23
    setLoading(true)
-
 
24
    const response = await searchEntities('company/my-companies', searchValue)
19
 
25
 
-
 
26
    if (!response.success) {
20
  const {
27
      dispatch(addNotification({ style: 'danger', msg: response.data }))
21
    data: companies,
28
      setLoading(false)
-
 
29
      return
-
 
30
    }
-
 
31
 
-
 
32
    setCompanies(response.data)
-
 
33
    setLoading(false)
-
 
34
  }
-
 
35
 
22
    isLoading,
36
  const toggleShowCompanyModal = () => {
-
 
Línea 37... Línea 23...
37
    setShowCompanyModal(!showAddCompanyModal)
23
    refetch
Línea 38... Línea -...
38
  }
-
 
39
 
24
  } = useFetch(`/company/my-companies?search=${search}`)
40
  const handleSearch = debounce((value) => setSearch(value), 500)
-
 
Línea 41... Línea 25...
41
 
25
 
-
 
26
  const toggleShowCompanyModal = () => setShowCompanyModal(!showCompanyModal)
42
  useEffect(() => {
27
 
43
    getMyCompanies(search)
28
  const handleSearch = debounce((value) => setSearch(value), 500)
44
  }, [search])
29
 
45
 
30
  return (
46
  return (
31
    <>
47
    <main className='companies-info container'>
32
      <Container>
Línea 48... Línea 33...
48
      <TitleSection
33
        <TitleSection
Línea 49... Línea -...
49
        title={labels.my_companies}
-
 
50
        onAdd={toggleShowCompanyModal}
-
 
51
        addLabel={`${labels.add} ${labels.company?.toLowerCase()}`}
-
 
52
      />
34
          title={labels.my_companies}
-
 
35
          onAdd={toggleShowCompanyModal}
53
 
36
          addLabel={`${labels.add} ${labels.company?.toLowerCase()}`}
54
      <SearchBar onChange={handleSearch} />
37
        />
55
 
38
 
56
      {loading ? (
39
        <SearchBar onChange={handleSearch} />
57
        <Spinner />
40
 
Línea 71... Línea 54...
71
              align='left'
54
              align='left'
72
              message={labels.datatable_szerorecords}
55
              message={labels.datatable_szerorecords}
73
            />
56
            />
74
          )}
57
          )}
75
        </ul>
58
        </ul>
76
      )}
59
      </Container>
-
 
60
 
77
      <AddCompanyModal
61
      <AddCompanyModal
78
        show={showAddCompanyModal}
62
        show={showCompanyModal}
79
        onHide={toggleShowCompanyModal}
63
        onHide={toggleShowCompanyModal}
80
        fetchCompanies={getMyCompanies}
64
        fetchCompanies={refetch}
81
      />
65
      />
82
    </main>
66
    </>
83
  )
67
  )
84
}
68
}
Línea 85... Línea 69...
85
 
69