Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev Autor Línea Nro. Línea
5 stevensc 1
import React, { useEffect, useState } from 'react'
2
import { useDispatch, useSelector } from 'react-redux'
2864 stevensc 3
import { Search } from '@mui/icons-material'
4
 
5 stevensc 5
import { debounce } from '../../utils'
6
import { searchEntities } from '../../services/items'
7
import { addNotification } from '../../redux/notification/notification.actions'
8
 
9
import Spinner from '../../components/UI/Spinner'
2864 stevensc 10
import Input from '../../components/UI/inputs/Input'
5 stevensc 11
import ProfileItem from '../../components/profile/ProfileItem'
12
import TitleSection from '../../components/UI/TitleSection'
13
import EmptySection from '../../components/UI/EmptySection'
14
import AddProfileModal from '../../components/modals/AddProfileModal'
15
 
16
const MyProfilesPage = () => {
17
  const [isShowAddModal, setIsShowAddModal] = useState(false)
18
  const [myProfiles, setMyProfiles] = useState([])
19
  const [loading, setLoading] = useState(false)
20
  const [search, setSearch] = useState('')
21
 
22
  const labels = useSelector(({ intl }) => intl.labels)
23
  const dispatch = useDispatch()
24
 
25
  const getMyProfiles = async (search = '') => {
26
    setLoading(true)
27
    try {
28
      const { success, data } = await searchEntities(
29
        'profile/my-profiles',
30
        search
31
      )
32
 
33
      if (!success) {
34
        dispatch(addNotification({ style: 'danger', msg: data }))
35
        setLoading(false)
36
        return
37
      }
38
 
39
      setMyProfiles(data)
40
    } catch (error) {
2194 stevensc 41
      dispatch(addNotification({ style: 'danger', msg: error.message }))
5 stevensc 42
    } finally {
43
      setLoading(false)
44
    }
45
  }
46
 
47
  const handleSearch = debounce((value) => setSearch(value), 500)
48
 
49
  const toggleModal = () => {
50
    setIsShowAddModal(!isShowAddModal)
51
  }
52
 
53
  useEffect(() => {
54
    getMyProfiles(search)
55
  }, [search])
56
 
57
  return (
2194 stevensc 58
    <main className='companies-info container'>
5 stevensc 59
      <TitleSection
60
        title={labels.my_profiles}
61
        onAdd={toggleModal}
62
        addLabel={labels.add}
63
      />
2875 stevensc 64
      <Input icon={<Search />} onChange={handleSearch} variant='search' />
5 stevensc 65
      {loading ? (
2864 stevensc 66
        <Spinner />
5 stevensc 67
      ) : (
2194 stevensc 68
        <ul className='companies-list'>
5 stevensc 69
          {myProfiles.length ? (
70
            myProfiles.map(({ id, ...rest }) => (
71
              <ProfileItem key={id} {...rest} fetchCallback={getMyProfiles} />
72
            ))
73
          ) : (
74
            <EmptySection
2194 stevensc 75
              align='left'
5 stevensc 76
              message={labels.datatable_szerorecords}
77
            />
78
          )}
79
        </ul>
80
      )}
81
      <AddProfileModal
82
        show={isShowAddModal}
83
        getProfiles={() => getMyProfiles()}
84
        onHide={toggleModal}
85
      />
86
    </main>
87
  )
88
}
89
 
90
export default MyProfilesPage