Rev 5158 | AutorÃa | Comparar con el anterior | Ultima modificación | Ver Log |
/* eslint-disable camelcase */
/* eslint-disable react/prop-types */
import React, { useEffect, useState } from 'react'
import { connect } from 'react-redux'
import { debounce } from '../../../utils'
import { addNotification } from '../../../redux/notification/notification.actions'
import { searchEntities } from '../../../services/search'
import Spinner from '../../../shared/loading-spinner/Spinner'
import SearchList from '../../../components/SearchList'
import Card from '../../../components/Profile'
import EmptySection from '../../../shared/empty-section/EmptySection'
import TitleSection from '../../../components/TitleSection'
const SavedJobs = ({ addNotification }) => {
const [savedJobs, setSavedJobs] = useState([])
const [loading, setLoading] = useState(true)
useEffect(() => {
getSavedJobs()
}, [])
const getSavedJobs = async (searchValue = '') => {
setLoading(true)
const response = await searchEntities('job/saved-jobs', searchValue)
if (!response.success) {
addNotification({ style: 'danger', msg: response.data })
setLoading(false)
return
}
setSavedJobs(response.data)
setLoading(false)
}
const handleSearch = debounce((value) => getSavedJobs(value), 500)
return (
<section className="companies-info container">
<TitleSection title={`${LABELS.JOBS} ${LABELS.JOBS_SAVED.toLowerCase()}`} />
<SearchList onChange={handleSearch} />
<div className="companies-list">
{loading && <Spinner />}
{(!loading && Boolean(!savedJobs.length)) && <EmptySection align='left' message={LABELS.DATATABLE_SZERORECORDS} />}
{(!loading && Boolean(savedJobs.length)) &&
savedJobs.map(({ employment_type, id, image, link_remove, link_view, title }) =>
<Card
key={id}
image={image}
name={title}
status={employment_type}
link_view={link_view}
link_delete={link_remove}
fetchCallback={getSavedJobs}
btnAcceptTitle={LABELS.VIEW_JOB}
btnCancelTitle={LABELS.DELETE}
/>
)}
</div>
</section>
)
}
const mapDispatchToProps = {
addNotification: (notification) => addNotification(notification)
}
export default connect(null, mapDispatchToProps)(SavedJobs)