| 11467 |
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 { Link } from 'react-router-dom'
|
|
|
6 |
import axios from 'axios'
|
|
|
7 |
import { LengthFilter, SearchInput, Table, TablePagination } from '../../../recruitment_and_selection/components/TableComponents'
|
|
|
8 |
import { addNotification } from '../../../redux/notification/notification.actions'
|
|
|
9 |
import ContentTitle from '../../../shared/ContentTitle'
|
|
|
10 |
import DeleteModal from '../../../shared/DeleteModal'
|
|
|
11 |
|
|
|
12 |
const headers = [
|
|
|
13 |
{ key: 'title', label: 'Nombre', isSorteable: true },
|
|
|
14 |
{ key: 'description', label: 'Descripción', 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 TableView = ({ 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 [objetive, setObjetive] = 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 |
setObjetive(data.data.objetive)
|
|
|
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 |
<div className="col-sm-12 d-flex flex-column p-2">
|
|
|
72 |
<div className="m-2">
|
|
|
73 |
<strong>Descripción:</strong>
|
|
|
74 |
<br />
|
|
|
75 |
<span className="xd">{objetive.descriptionObjective}</span>
|
|
|
76 |
</div>
|
|
|
77 |
<div className="m-2 d-flex">
|
|
|
78 |
<div>
|
|
|
79 |
<strong>Estatus:</strong>
|
|
|
80 |
<br />
|
|
|
81 |
<span className="xd">{objetive.statusObjective}</span>
|
|
|
82 |
</div>
|
|
|
83 |
<div className="ml-5">
|
|
|
84 |
<strong>Fecha:</strong>
|
|
|
85 |
<br />
|
|
|
86 |
<span className="xd">{objetive.dateObjective}</span>
|
|
|
87 |
</div>
|
|
|
88 |
<div className="ml-5">
|
|
|
89 |
<strong>Costo:</strong>
|
|
|
90 |
<br />
|
|
|
91 |
<span className="xd">{objetive.costObjective}</span>
|
|
|
92 |
</div>
|
|
|
93 |
<div className="ml-5 ">
|
|
|
94 |
<strong>Progreso:</strong>
|
|
|
95 |
<br />
|
|
|
96 |
<div className="d-flex align-items-center">
|
|
|
97 |
<progress value={objetive.indicatorObjective} max={100} />
|
|
|
98 |
<span className="ml-2">{`${objetive.indicatorObjective}%`}</span>
|
|
|
99 |
</div>
|
|
|
100 |
</div>
|
|
|
101 |
</div>
|
|
|
102 |
<div className="col-sm-12 mt-3">
|
|
|
103 |
<Link to="/" className="btn btn-primary">
|
|
|
104 |
<i className="fa fa-arrow-left mr-1" />
|
|
|
105 |
Ir atras
|
|
|
106 |
</Link>
|
|
|
107 |
</div>
|
|
|
108 |
</div>
|
|
|
109 |
<section className="content">
|
|
|
110 |
<div className="container-fluid">
|
|
|
111 |
<div className="row">
|
|
|
112 |
<div className="col-12">
|
|
|
113 |
<Card>
|
|
|
114 |
<Card.Header>
|
|
|
115 |
<div className="row justify-content-end" style={{ gap: '10px' }}>
|
|
|
116 |
{
|
|
|
117 |
permisions.allowAdd
|
|
|
118 |
&&
|
|
|
119 |
<label
|
|
|
120 |
className='d-flex align-items-center'
|
|
|
121 |
onClick={() => {
|
|
|
122 |
setActionLink(add_link)
|
|
|
123 |
setModalToShow('add')
|
|
|
124 |
}}
|
|
|
125 |
style={{ cursor: 'pointer' }}
|
|
|
126 |
>
|
|
|
127 |
<i className="fa fa-plus mr-2" />
|
|
|
128 |
Agregar
|
|
|
129 |
</label>
|
|
|
130 |
}
|
|
|
131 |
<label
|
|
|
132 |
className='d-flex align-items-center'
|
|
|
133 |
onClick={() => getData({
|
|
|
134 |
url: table_link,
|
|
|
135 |
params: {
|
|
|
136 |
search: search,
|
|
|
137 |
length: dataLength,
|
|
|
138 |
page: pages.current
|
|
|
139 |
}
|
|
|
140 |
})}
|
|
|
141 |
style={{ cursor: 'pointer' }}
|
|
|
142 |
>
|
|
|
143 |
<i className='fa fa-refresh mr-2' />
|
|
|
144 |
Actualizar
|
|
|
145 |
</label>
|
|
|
146 |
</div>
|
|
|
147 |
<div className="row justify-content-between align-items-center">
|
|
|
148 |
<LengthFilter onChange={(e) => setDataLength(e.target.value)} />
|
|
|
149 |
<SearchInput onChange={(e) => setSearch(e.target.value)} />
|
|
|
150 |
</div>
|
|
|
151 |
</Card.Header>
|
|
|
152 |
<Card.Body>
|
|
|
153 |
<div className="table-responsive">
|
|
|
154 |
<Table data={items} headers={headers} setData={setItems}>
|
|
|
155 |
{
|
|
|
156 |
items.length
|
|
|
157 |
&&
|
|
|
158 |
items.map((item, index) => (
|
|
|
159 |
<tr key={index}>
|
|
|
160 |
<td className='text-vertical-middle'>{item.title}</td>
|
|
|
161 |
<td className='text-vertical-middle'>{item.description}</td>
|
|
|
162 |
<td className='text-vertical-middle'>{item.date}</td>
|
|
|
163 |
<td className='d-flex align-items-center'>
|
|
|
164 |
{
|
|
|
165 |
item.progress > 0
|
|
|
166 |
?
|
|
|
167 |
<>
|
|
|
168 |
<progress value={item.progress} max='100' />
|
|
|
169 |
<span className='ml-2'>{item.progress}</span>
|
|
|
170 |
</>
|
|
|
171 |
:
|
|
|
172 |
'Sin metas'
|
|
|
173 |
}
|
|
|
174 |
</td>
|
|
|
175 |
<td className='text-vertical-middle'>{item.cost}</td>
|
|
|
176 |
<td className='text-vertical-middle'>
|
|
|
177 |
{
|
|
|
178 |
item.status === 'a'
|
|
|
179 |
? 'Activo'
|
|
|
180 |
: 'Inactivo'
|
|
|
181 |
}
|
|
|
182 |
</td>
|
|
|
183 |
<td>
|
|
|
184 |
<div className="d-flex align-items-center" style={{ gap: '5px' }}>
|
|
|
185 |
{
|
|
|
186 |
permisions.allowGoals
|
|
|
187 |
&&
|
|
|
188 |
<a href={item.actions.link_goals} style={{ color: '#333' }}>
|
|
|
189 |
<i className='fa fa-level-down' />
|
|
|
190 |
</a>
|
|
|
191 |
}
|
|
|
192 |
{
|
|
|
193 |
permisions.allowEdit
|
|
|
194 |
&&
|
|
|
195 |
<i
|
|
|
196 |
className='fa fa-pencil'
|
|
|
197 |
onClick={() => {
|
|
|
198 |
setActionLink(item.actions.link_edit)
|
|
|
199 |
setModalToShow('edit')
|
|
|
200 |
}}
|
|
|
201 |
style={{ cursor: 'pointer' }}
|
|
|
202 |
/>
|
|
|
203 |
}
|
|
|
204 |
{
|
|
|
205 |
permisions.allowDelete
|
|
|
206 |
&&
|
|
|
207 |
<i
|
|
|
208 |
className='fa fa-trash'
|
|
|
209 |
onClick={() => {
|
|
|
210 |
setActionLink(item.actions.link_delete)
|
|
|
211 |
setModalToShow('delete')
|
|
|
212 |
}}
|
|
|
213 |
style={{ cursor: 'pointer' }}
|
|
|
214 |
/>
|
|
|
215 |
}
|
|
|
216 |
</div>
|
|
|
217 |
</td>
|
|
|
218 |
</tr>
|
|
|
219 |
))
|
|
|
220 |
}
|
|
|
221 |
</Table>
|
|
|
222 |
</div>
|
|
|
223 |
<div className='row justify-content-between align-items-center'>
|
|
|
224 |
<p className='mb-0'>
|
|
|
225 |
{`Mostrando registros del ${(dataLength * pages.current) - (dataLength - 1) || 0} al ${(dataLength * pages.current) - (dataLength - total) || 0} de un total de ${total || 0} registros`}
|
|
|
226 |
</p>
|
|
|
227 |
<TablePagination
|
|
|
228 |
onDecrement={() => setPages(prev => prev.current -= 1)}
|
|
|
229 |
onIncrement={() => setPages(prev => prev.current += 1)}
|
|
|
230 |
totalPages={pages.last}
|
|
|
231 |
currentPage={pages.current}
|
|
|
232 |
/>
|
|
|
233 |
</div>
|
|
|
234 |
</Card.Body>
|
|
|
235 |
</Card>
|
|
|
236 |
</div>
|
|
|
237 |
</div >
|
|
|
238 |
</div >
|
|
|
239 |
</section >
|
|
|
240 |
<DeleteModal
|
|
|
241 |
url={actionLink}
|
|
|
242 |
isOpen={modalToShow === 'delete'}
|
|
|
243 |
closeModal={() => setModalToShow('')}
|
|
|
244 |
title="Esta seguro de borrar este objetivo?"
|
|
|
245 |
onComplete={() => setItems(items.filter((item) => item.actions.link_delete !== actionLink))}
|
|
|
246 |
message="Registro borrado"
|
|
|
247 |
/>
|
|
|
248 |
</ContentTitle >
|
|
|
249 |
)
|
|
|
250 |
}
|
|
|
251 |
|
|
|
252 |
export default TableView
|