Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6004 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
5175 stevensc 1
/* eslint-disable react/prop-types */
2
/* eslint-disable camelcase */
3
import React, { useEffect, useState } from 'react'
4
import { connect } from 'react-redux'
5
import { debounce } from '../../../../utils'
6
import { searchEntities } from '../../../../services/search'
7
import { addNotification } from '../../../../redux/notification/notification.actions'
8
import Spinner from '../../../../shared/loading-spinner/Spinner'
9
import Profile from '../../../../components/Profile'
10
import SearchList from '../../../../components/SearchList'
11
import TitleSection from '../../../../components/TitleSection'
12
import EmptySection from '../../../../shared/empty-section/EmptySection'
13
import AddGroupModal from './add-group-modal/AddGroupModal'
5996 stevensc 14
import { setIntlLabels } from '../../../../redux/intl/intl.action'
1 www 15
 
5996 stevensc 16
const MyGroups = ({ groupTypes, industries, addNotification, labels }) => {
5175 stevensc 17
  const [groups, setGroups] = useState([])
18
  const [loading, setLoading] = useState(true)
19
  const [showAddGroupModal, setShowAddGroupModal] = useState(false)
1 www 20
 
5175 stevensc 21
  useEffect(() => {
22
    getGroups()
5996 stevensc 23
    setIntlLabels(labels)
5175 stevensc 24
  }, [])
1 www 25
 
5175 stevensc 26
  const getGroups = async (searchValue = '') => {
27
    setLoading(true)
28
    const response = await searchEntities('group/my-groups', searchValue)
1 www 29
 
5175 stevensc 30
    if (!response.success) {
31
      addNotification({ style: 'danger', msg: response.data })
32
      setLoading(false)
33
      return
34
    }
1 www 35
 
5175 stevensc 36
    setGroups(response.data)
37
    setLoading(false)
38
  }
1 www 39
 
40
  const handleShowAddGroupModal = () => {
5175 stevensc 41
    setShowAddGroupModal(!showAddGroupModal)
42
  }
1 www 43
 
5175 stevensc 44
  const handleSearch = debounce((value) => getGroups(value), 500)
45
 
1 www 46
  return (
5175 stevensc 47
    <section className="companies-info container">
5996 stevensc 48
      <TitleSection
49
        title={labels.MY_GROUPS}
50
        allowAdd
51
        onAdd={handleShowAddGroupModal}
52
      />
5175 stevensc 53
      <SearchList onChange={handleSearch} />
54
      <div className="companies-list">
55
        {loading && <Spinner />}
5996 stevensc 56
        {!loading && Boolean(!groups.length) && (
57
          <EmptySection align="left" message={labels.DATATABLE_SZERORECORDS} />
58
        )}
59
        {!loading &&
60
          Boolean(groups.length) &&
5175 stevensc 61
          groups.map(
5996 stevensc 62
            (
63
              { image, link_delete, link_edit, link_view, name, privacy },
64
              id
65
            ) => (
5175 stevensc 66
              <Profile
67
                image={image}
68
                name={name}
69
                status={privacy}
70
                link_view={link_view}
71
                link_edit={link_edit}
72
                link_delete={link_delete}
73
                key={id}
74
                fetchCallback={getGroups}
5996 stevensc 75
                btnAcceptTitle={labels.GROUP_VIEW}
6457 stevensc 76
                btnEditTitle={`${labels.EDIT} ${labels.GROUP?.toLowerCase()}`}
5996 stevensc 77
                btnCancelTitle={`${
78
                  labels.DELETE
6457 stevensc 79
                } ${labels.GROUP?.toLowerCase()}`}
5175 stevensc 80
              />
5996 stevensc 81
            )
5175 stevensc 82
          )}
83
      </div>
1 www 84
      <AddGroupModal
85
        show={showAddGroupModal}
86
        groupTypes={groupTypes}
87
        industries={industries}
6004 stevensc 88
        onHide={() => handleShowAddGroupModal()}
89
        fetchGroups={getGroups}
1 www 90
      />
5175 stevensc 91
    </section>
92
  )
93
}
1 www 94
 
95
const mapDispatchToProps = {
5996 stevensc 96
  addNotification: (notification) => addNotification(notification),
5175 stevensc 97
}
1 www 98
 
5175 stevensc 99
export default connect(null, mapDispatchToProps)(MyGroups)