Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 11471 | Rev 11473 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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
 
11471 stevensc 21
const TableView = ({ add_link, table_link, permisions }) => {
11467 stevensc 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'>
11472 stevensc 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.allowEdit
187
                                                                    &&
188
                                                                    <i
189
                                                                    	className='fa fa-pencil'
190
                                                                    	onClick={() => {
191
                                                                    		setActionLink(item.actions.link_edit)
192
                                                                    		setModalToShow('edit')
193
                                                                    	}}
194
                                                                    	style={{ cursor: 'pointer' }}
195
                                                                    />
196
                                                				}
197
                                                				{
198
                                                					permisions.allowDelete
199
                                                                    &&
200
                                                                    <i
201
                                                                    	className='fa fa-trash'
202
                                                                    	onClick={() => {
203
                                                                    		setActionLink(item.actions.link_delete)
204
                                                                    		setModalToShow('delete')
205
                                                                    	}}
206
                                                                    	style={{ cursor: 'pointer' }}
207
                                                                    />
208
                                                				}
209
                                                			</div>
210
                                                		</td>
211
                                                	</tr>
212
                                                ))
213
											}
214
										</Table>
215
									</div>
216
									<div className='row justify-content-between align-items-center'>
217
										<p className='mb-0'>
218
											{`Mostrando registros del ${(dataLength * pages.current) - (dataLength - 1) || 0} al ${(dataLength * pages.current) - (dataLength - total) || 0} de un total de ${total || 0} registros`}
219
										</p>
220
										<TablePagination
221
											onDecrement={() => setPages(prev => prev.current -= 1)}
222
											onIncrement={() => setPages(prev => prev.current += 1)}
223
											totalPages={pages.last}
224
											currentPage={pages.current}
225
										/>
226
									</div>
227
								</Card.Body>
228
							</Card>
229
						</div>
230
					</div >
231
				</div >
232
			</section >
233
			<DeleteModal
234
				url={actionLink}
235
				isOpen={modalToShow === 'delete'}
236
				closeModal={() => setModalToShow('')}
237
				title="Esta seguro de borrar este objetivo?"
238
				onComplete={() => setItems(items.filter((item) => item.actions.link_delete !== actionLink))}
239
				message="Registro borrado"
240
			/>
11467 stevensc 241
		</ContentTitle >
242
	)
243
}
244
 
245
export default TableView