Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 11470 | Rev 11472 | 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'>
11471 stevensc 71
 
11467 stevensc 72
		</ContentTitle >
73
	)
74
}
75
 
76
export default TableView