Proyectos de Subversion LeadersLinked - SPA

Rev

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

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