Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 12487 | Rev 12492 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 12487 Rev 12491
Línea 29... Línea 29...
29
	const [pages, setPages] = useState({
29
	const [pages, setPages] = useState({
30
		current: 1,
30
		current: 1,
31
		last: 1
31
		last: 1
32
	})
32
	})
Línea -... Línea 33...
-
 
33
 
-
 
34
	const getData = ({ url = '', params = {} }) => {
-
 
35
 
-
 
36
		axios.get(url, { params: { ...params } })
-
 
37
			.then(({ data }) => {
-
 
38
				if (!data.success) {
-
 
39
					dispatch(addNotification({
-
 
40
						style: 'error',
-
 
41
						msg: 'Ha ocurrido un error'
-
 
42
					}))
-
 
43
				}
-
 
44
 
-
 
45
				setItems(data.data.items)
-
 
46
				setTotal(data.data.total)
-
 
47
				setPages({ ...pages, last: Math.ceil(data.data.total / dataLength) })
-
 
48
			})
-
 
49
			.catch(() => dispatch(addNotification({
-
 
50
				style: 'error',
-
 
51
				msg: 'Ha ocurrido un error'
-
 
52
			})))
-
 
53
	}
-
 
54
 
-
 
55
	useEffect(() => {
-
 
56
		getData({
-
 
57
			url: table_link,
-
 
58
			params: {
-
 
59
				search: search,
-
 
60
				length: dataLength,
-
 
61
				start: pages.current
-
 
62
			}
-
 
63
		})
-
 
64
	}, [search, dataLength, pages.current])
-
 
65
 
-
 
66
	useEffect(() => {
-
 
67
		if (pages.current > 1) {
-
 
68
			setStartItem((dataLength * (pages.current - 1)) + 1)
-
 
69
		} else {
-
 
70
			setStartItem(1)
-
 
71
		}
-
 
72
	}, [pages.current])
-
 
73
 
-
 
74
	useEffect(() => {
-
 
75
		if (items) {
-
 
76
			if (startItem > 1) {
-
 
77
				setLastItem(startItem + (items.length - 1))
-
 
78
			} else {
-
 
79
				setLastItem(items.length)
-
 
80
			}
-
 
81
		}
-
 
82
	}, [items])
33
 
83
 
34
	return (
84
	return (
-
 
85
		<>
-
 
86
			<section className="content">
-
 
87
				<div className="container-fluid">
-
 
88
					<div className="row">
-
 
89
						<div className="col-12">
-
 
90
							<Card>
-
 
91
								<Card.Header>
-
 
92
									<div className="row justify-content-end" style={{ gap: '10px' }}>
-
 
93
										{
-
 
94
											permisions.allowAdd
-
 
95
											&&
-
 
96
											<label
-
 
97
												className='d-flex align-items-center'
-
 
98
												onClick={() => {
-
 
99
													setActionLink(add_link)
-
 
100
													history.push('/organizational-climate/form/add')
-
 
101
												}}
-
 
102
												style={{ cursor: 'pointer' }}
-
 
103
											>
-
 
104
												<i className="fa fa-plus mr-2" />
-
 
105
												Agregar
-
 
106
											</label>
-
 
107
										}
-
 
108
										<label
-
 
109
											className='d-flex align-items-center'
-
 
110
											onClick={() => getData({
-
 
111
												url: table_link,
-
 
112
												params: {
-
 
113
													search: search,
-
 
114
													length: dataLength,
-
 
115
													start: pages.current
-
 
116
												}
-
 
117
											})}
-
 
118
											style={{ cursor: 'pointer' }}
-
 
119
										>
-
 
120
											<i className='fa fa-refresh mr-2' />
-
 
121
											Actualizar
-
 
122
										</label>
-
 
123
									</div>
-
 
124
									<div className="row justify-content-between align-items-center">
-
 
125
										<LengthFilter onChange={(e) => setDataLength(e.target.value)} />
-
 
126
										<SearchInput onChange={(e) => setSearch(e.target.value)} />
-
 
127
									</div>
-
 
128
								</Card.Header>
-
 
129
								<Card.Body>
-
 
130
									<div className="table-responsive">
-
 
131
										<Table data={items} headers={headers} setData={setItems}>
-
 
132
											{
-
 
133
												items?.map((item, index) => (
-
 
134
													<tr key={index}>
-
 
135
														<td>{item.name}</td>
-
 
136
														<td>{item.job_description}</td>
-
 
137
														<td>
-
 
138
															{
-
 
139
																item.status === 'A'
-
 
140
																	? 'Activo'
-
 
141
																	: 'Inactivo'
-
 
142
															}
-
 
143
														</td>
-
 
144
														<td className='d-flex' style={{ gap: '10px' }}>
-
 
145
															{
-
 
146
																permisions.allowEdit
-
 
147
																&&
-
 
148
																<i
-
 
149
																	className='fa fa-pencil'
-
 
150
																	onClick={() => {
-
 
151
																		setActionLink(item.actions.link_edit)
-
 
152
																		history.push('/organizational-climate/form/edit')
-
 
153
																	}}
-
 
154
																	style={{ cursor: 'pointer' }}
-
 
155
																/>
-
 
156
															}
-
 
157
															{
-
 
158
																permisions.allowDelete
-
 
159
																&&
-
 
160
																<i
-
 
161
																	className='fa fa-trash'
-
 
162
																	onClick={() => {
-
 
163
																		setShowDeleteModal(true)
-
 
164
																		setDeleteLink(item.actions.link_delete)
-
 
165
																	}}
-
 
166
																	style={{ cursor: 'pointer' }}
-
 
167
																/>
-
 
168
															}
35
		<>
169
														</td>
-
 
170
													</tr>
-
 
171
												))
-
 
172
											}
-
 
173
										</Table>
-
 
174
									</div>
-
 
175
									<div className='row justify-content-between align-items-center'>
-
 
176
										<p className='mb-0'>
-
 
177
											{`Mostrando registros del ${startItem} al ${lastItem} de un total de ${total} registros`}
-
 
178
										</p>
-
 
179
										<TablePagination
-
 
180
											onDecrement={() => setPages({ ...pages, current: pages.current - 1 })}
-
 
181
											onIncrement={() => setPages({ ...pages, current: pages.current + 1 })}
-
 
182
											totalPages={pages.last}
-
 
183
											currentPage={pages.current}
-
 
184
										/>
-
 
185
									</div>
-
 
186
								</Card.Body>
-
 
187
							</Card>
-
 
188
						</div>
-
 
189
					</div >
-
 
190
				</div >
-
 
191
			</section >
-
 
192
			<DeleteModal
-
 
193
				url={deleteLink}
-
 
194
				isOpen={showDeleteModal}
-
 
195
				closeModal={() => setShowDeleteModal(false)}
-
 
196
				title="Esta seguro de borrar este formulario?"
-
 
197
				onComplete={() => setItems(items.filter((item) => item.actions.link_delete !== deleteLink))}
-
 
198
				message="Registro eliminado"
36
			<h1>Hello</h1>
199
			/>
37
		</>
200
		</>
38
	)
201
	)
Línea 39... Línea 202...
39
}
202
}
40
 
203