11379 |
stevensc |
1 |
/* eslint-disable no-mixed-spaces-and-tabs */
|
|
|
2 |
import React, { useState, useEffect } from 'react'
|
|
|
3 |
import { Card } from 'react-bootstrap'
|
|
|
4 |
import { useDispatch } from 'react-redux'
|
|
|
5 |
import axios from 'axios'
|
|
|
6 |
import { addNotification } from '../../../redux/notification/notification.actions'
|
|
|
7 |
import ContentTitle from '../../../shared/ContentTitle'
|
|
|
8 |
import { LengthFilter, SearchInput, Table, TablePagination } from '../../../recruitment_and_selection/components/TableComponents'
|
|
|
9 |
import DeleteModal from '../../../shared/DeleteModal'
|
|
|
10 |
|
|
|
11 |
const headers = [
|
|
|
12 |
{ key: 'title', label: 'Nombre', isSorteable: true },
|
|
|
13 |
{ key: 'description', label: 'Descripción', isSorteable: true },
|
|
|
14 |
{ key: 'date', label: 'Fecha', isSorteable: true },
|
|
|
15 |
{ key: 'progress', label: 'Progreso', isSorteable: true },
|
|
|
16 |
{ key: 'cost', label: 'Costo', isSorteable: true },
|
|
|
17 |
{ key: 'status', label: 'Estatus', isSorteable: true },
|
|
|
18 |
{ key: 'actions', label: 'Acciones', isSorteable: false }
|
|
|
19 |
]
|
|
|
20 |
|
|
|
21 |
const ObjectivesAndGoals = ({ add_link, table_link, permisions }) => {
|
|
|
22 |
|
|
|
23 |
const dispatch = useDispatch()
|
|
|
24 |
const [modalToShow, setModalToShow] = useState('')
|
|
|
25 |
const [actionLink, setActionLink] = useState(add_link)
|
|
|
26 |
const [items, setItems] = useState([])
|
|
|
27 |
const [module, setModule] = useState({})
|
|
|
28 |
const [total, setTotal] = useState(0)
|
|
|
29 |
const [search, setSearch] = useState('')
|
|
|
30 |
const [dataLength, setDataLength] = useState(10)
|
|
|
31 |
const [pages, setPages] = useState({
|
|
|
32 |
current: 1,
|
|
|
33 |
last: 1
|
|
|
34 |
})
|
|
|
35 |
|
|
|
36 |
const getData = ({ url = '', params = {} }) => {
|
|
|
37 |
|
|
|
38 |
axios.get(url, { params: { ...params } })
|
|
|
39 |
.then(({ data }) => {
|
|
|
40 |
if (!data.success) {
|
|
|
41 |
return dispatch(addNotification({
|
|
|
42 |
style: 'danger',
|
|
|
43 |
msg: 'Ha ocurrido un error'
|
|
|
44 |
}))
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
setItems(data.data.items)
|
|
|
48 |
setModule(data.data.module)
|
|
|
49 |
setTotal(data.data.total)
|
|
|
50 |
setPages({ ...pages, last: Math.ceil(data.data.total / dataLength) })
|
|
|
51 |
})
|
|
|
52 |
.catch(() => dispatch(addNotification({
|
|
|
53 |
style: 'danger',
|
|
|
54 |
msg: 'Ha ocurrido un error'
|
|
|
55 |
})))
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
useEffect(() => {
|
|
|
59 |
getData({
|
|
|
60 |
url: table_link,
|
|
|
61 |
params: {
|
|
|
62 |
search: search,
|
|
|
63 |
length: dataLength,
|
|
|
64 |
page: pages.current
|
|
|
65 |
}
|
|
|
66 |
})
|
|
|
67 |
}, [search, dataLength, pages.current])
|
|
|
68 |
|
|
|
69 |
return (
|
|
|
70 |
<ContentTitle title='Planificación - Objetivos y Metas'>
|
|
|
71 |
<section className="content">
|
|
|
72 |
<div className="container-fluid">
|
|
|
73 |
<div className="row">
|
|
|
74 |
<div className="col-12">
|
|
|
75 |
<Card>
|
|
|
76 |
<Card.Header>
|
|
|
77 |
<div className="row" style={{ gap: '10px' }}>
|
|
|
78 |
|
|
|
79 |
</div>
|
|
|
80 |
<div className="row justify-content-end" style={{ gap: '10px' }}>
|
|
|
81 |
{
|
|
|
82 |
permisions.allowAdd
|
|
|
83 |
&&
|
|
|
84 |
<label
|
|
|
85 |
className='d-flex align-items-center'
|
|
|
86 |
onClick={() => setModalToShow('add')}
|
|
|
87 |
style={{ cursor: 'pointer' }}
|
|
|
88 |
>
|
|
|
89 |
<i className="fa fa-plus mr-2" />
|
|
|
90 |
Agregar
|
|
|
91 |
</label>
|
|
|
92 |
}
|
|
|
93 |
<label
|
|
|
94 |
className='d-flex align-items-center'
|
|
|
95 |
onClick={() => getData({
|
|
|
96 |
url: table_link,
|
|
|
97 |
params: {
|
|
|
98 |
search: search,
|
|
|
99 |
length: dataLength,
|
|
|
100 |
page: pages.current
|
|
|
101 |
}
|
|
|
102 |
})}
|
|
|
103 |
style={{ cursor: 'pointer' }}
|
|
|
104 |
>
|
|
|
105 |
<i className='fa fa-refresh mr-2' />
|
|
|
106 |
Actualizar
|
|
|
107 |
</label>
|
|
|
108 |
</div>
|
|
|
109 |
<div className="row justify-content-between align-items-center">
|
|
|
110 |
<LengthFilter onChange={(e) => setDataLength(e.target.value)} />
|
|
|
111 |
<SearchInput onChange={(e) => setSearch(e.target.value)} />
|
|
|
112 |
</div>
|
|
|
113 |
</Card.Header>
|
|
|
114 |
<Card.Body>
|
|
|
115 |
<div className="table-responsive">
|
11396 |
stevensc |
116 |
<Table data={items} headers={headers} setData={setItems}>
|
|
|
117 |
|
|
|
118 |
</Table>
|
11379 |
stevensc |
119 |
</div>
|
|
|
120 |
<div className='row justify-content-between align-items-center'>
|
|
|
121 |
<p className='mb-0'>
|
|
|
122 |
{`Mostrando registros del ${(dataLength * pages.current) - (dataLength - 1) || 0} al ${(dataLength * pages.current) - (dataLength - total) || 0} de un total de ${total || 0} registros`}
|
|
|
123 |
</p>
|
|
|
124 |
<TablePagination
|
|
|
125 |
onDecrement={() => setPages(prev => prev.current -= 1)}
|
|
|
126 |
onIncrement={() => setPages(prev => prev.current += 1)}
|
|
|
127 |
totalPages={pages.last}
|
|
|
128 |
currentPage={pages.current}
|
|
|
129 |
/>
|
|
|
130 |
</div>
|
|
|
131 |
</Card.Body>
|
|
|
132 |
</Card>
|
|
|
133 |
</div>
|
|
|
134 |
</div >
|
|
|
135 |
</div >
|
|
|
136 |
</section >
|
|
|
137 |
<DeleteModal
|
|
|
138 |
url={actionLink}
|
|
|
139 |
isOpen={modalToShow === 'delete'}
|
|
|
140 |
closeModal={() => modalToShow('')}
|
|
|
141 |
title="Esta seguro de borrar este objetivo?"
|
|
|
142 |
onComplete={() => setItems(items.filter((item) => item.actions.link_delete !== actionLink))}
|
|
|
143 |
message="Registro borrado"
|
|
|
144 |
/>
|
|
|
145 |
</ContentTitle>
|
|
|
146 |
)
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
export default ObjectivesAndGoals
|