Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev Autor Línea Nro. Línea
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">
11395 stevensc 116
 
11379 stevensc 117
									</div>
118
									<div className='row justify-content-between align-items-center'>
119
										<p className='mb-0'>
120
											{`Mostrando registros del ${(dataLength * pages.current) - (dataLength - 1) || 0} al ${(dataLength * pages.current) - (dataLength - total) || 0} de un total de ${total || 0} registros`}
121
										</p>
122
										<TablePagination
123
											onDecrement={() => setPages(prev => prev.current -= 1)}
124
											onIncrement={() => setPages(prev => prev.current += 1)}
125
											totalPages={pages.last}
126
											currentPage={pages.current}
127
										/>
128
									</div>
129
								</Card.Body>
130
							</Card>
131
						</div>
132
					</div >
133
				</div >
134
			</section >
135
			<DeleteModal
136
				url={actionLink}
137
				isOpen={modalToShow === 'delete'}
138
				closeModal={() => modalToShow('')}
139
				title="Esta seguro de borrar este objetivo?"
140
				onComplete={() => setItems(items.filter((item) => item.actions.link_delete !== actionLink))}
141
				message="Registro borrado"
142
			/>
143
		</ContentTitle>
144
	)
145
}
146
 
147
export default ObjectivesAndGoals