Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

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