Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev Autor Línea Nro. Línea
5156 stevensc 1
/* eslint-disable camelcase */
2
/* eslint-disable react/prop-types */
3
import React, { useEffect, useState } from 'react'
4
import { connect } from 'react-redux'
5
import { debounce } from '../../../utils'
6
import { addNotification } from '../../../redux/notification/notification.actions'
7
import { searchEntities } from '../../../services/search'
8
import Spinner from '../../../shared/loading-spinner/Spinner'
9
import SearchList from '../../../components/SearchList'
10
import Card from '../../../components/Profile'
11
import EmptySection from '../../../shared/empty-section/EmptySection'
12
import TitleSection from '../../../components/TitleSection'
1 www 13
 
5156 stevensc 14
const SavedJobs = ({ addNotification }) => {
15
  const [savedJobs, setSavedJobs] = useState([])
16
  const [loading, setLoading] = useState(true)
1 www 17
 
5156 stevensc 18
  useEffect(() => {
19
    getSavedJobs()
20
  }, [])
1 www 21
 
5156 stevensc 22
  const getSavedJobs = async (searchValue = '') => {
23
    setLoading(true)
24
    const response = await searchEntities('job/saved-jobs', searchValue)
1 www 25
 
5156 stevensc 26
    if (!response.success) {
27
      addNotification({ style: 'danger', msg: response.data })
28
      setLoading(false)
29
      return
30
    }
1 www 31
 
5156 stevensc 32
    setSavedJobs(response.data)
33
    setLoading(false)
34
  }
1 www 35
 
5156 stevensc 36
  const handleSearch = debounce((value) => getSavedJobs(value), 500)
1549 steven 37
 
1 www 38
  return (
5159 stevensc 39
    <section className="companies-info container">
5158 stevensc 40
      <TitleSection title={`${LABELS.JOBS} ${LABELS.JOBS_SAVED.toLowerCase()}`} />
5156 stevensc 41
      <SearchList onChange={handleSearch} />
42
      <div className="companies-list">
43
        {loading && <Spinner />}
44
        {(!loading && Boolean(!savedJobs.length)) && <EmptySection align='left' message={LABELS.DATATABLE_SZERORECORDS} />}
45
        {(!loading && Boolean(savedJobs.length)) &&
46
          savedJobs.map(({ employment_type, id, image, link_remove, link_view, title }) =>
47
            <Card
48
              key={id}
49
              image={image}
50
              name={title}
51
              status={employment_type}
52
              link_view={link_view}
53
              link_delete={link_remove}
54
              fetchCallback={getSavedJobs}
55
              btnAcceptTitle={LABELS.VIEW_JOB}
56
              btnCancelTitle={LABELS.DELETE}
57
            />
58
          )}
1 www 59
      </div>
60
    </section>
5156 stevensc 61
  )
62
}
1 www 63
 
64
const mapDispatchToProps = {
5156 stevensc 65
  addNotification: (notification) => addNotification(notification)
66
}
1 www 67
 
5156 stevensc 68
export default connect(null, mapDispatchToProps)(SavedJobs)