Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev Autor Línea Nro. Línea
5674 stevensc 1
import React, { useState } from 'react'
11272 stevensc 2
import axios from 'axios'
3
import EditModal from '../../groups-types/view/EditModal'
5674 stevensc 4
import TableContainer from '../../company-sizes/view/TableContainer'
11272 stevensc 5
import DeleteModal from '../../../shared/DeleteModal'
5674 stevensc 6
 
7
const SkillsView = ({ urlsVar }) => {
8
 
11272 stevensc 9
	const { linkTable, addUrl, allowAdd, allowEdit, allowDelete } = urlsVar
10
	const [companyData, setCompanyData] = useState({})
11
	const [showModal, setShowModal] = useState(false)
12
	const [showDeleteModal, setShowDeleteModal] = useState(false)
13
	const [selectItem, setSelectItem] = useState(null)
14
	const [actionLink, setActionLink] = useState(addUrl)
15
	const headers = [
16
		{ key: 'name', label: 'Nombre', isSorteable: true },
17
		{ key: 'status', label: 'Activo', isSorteable: false },
18
		{ key: 'actions', label: 'Acciones', isSorteable: false }
19
	]
5674 stevensc 20
 
11272 stevensc 21
	const getData = (search, start, length) => {
22
		axios.get(
23
			linkTable,
24
			{
25
				params: {
26
					search: search,
27
					start: start,
28
					length: length
29
				}
30
			})
31
			.then(({ data }) => {
32
				if (data.success) {
33
					setCompanyData(data.data)
5674 stevensc 34
 
11272 stevensc 35
					return data.data
36
				}
37
			})
38
			.catch((err) => console.log(err))
39
	}
5674 stevensc 40
 
11272 stevensc 41
	const closeModal = () => {
42
		setShowModal(false)
43
		setSelectItem(null)
44
		setActionLink(addUrl)
45
	}
5674 stevensc 46
 
11272 stevensc 47
	const closeDeleteModal = () => {
48
		setShowDeleteModal(false)
49
		setActionLink(addUrl)
50
	}
5674 stevensc 51
 
11272 stevensc 52
	const editItem = (item) => {
53
		setSelectItem(item)
54
		setActionLink(item.actions.link_edit)
55
		setShowModal(true)
56
	}
5674 stevensc 57
 
11272 stevensc 58
	const deleteItem = (item) => {
59
		setActionLink(item.actions.link_delete)
60
		setShowDeleteModal(true)
61
	}
5674 stevensc 62
 
11272 stevensc 63
	const addItem = () => {
64
		setSelectItem(null)
65
		setActionLink(addUrl)
66
		setShowModal(true)
67
	}
5674 stevensc 68
 
11272 stevensc 69
	return (
70
		<>
71
			<section className="content">
72
				<section className="content-header">
73
					<div className="container-fluid">
74
						<div className="row mb-2">
75
							<div className="col-sm-12">
76
								<h1>Habilidades</h1>
77
							</div>
78
						</div>
79
					</div>
80
				</section>
81
				<TableContainer
82
					data={companyData}
83
					getData={getData}
84
					onEdit={editItem}
85
					onDelete={deleteItem}
86
					onAdd={addItem}
87
					headers={headers}
88
					allowAdd={allowAdd}
89
					allowEdit={allowEdit}
90
					allowDelete={allowDelete}
91
				/>
92
			</section>
93
			<EditModal
94
				isOpen={showModal}
95
				title='Habilidades'
96
				closeModal={closeModal}
97
				isEdit={actionLink !== addUrl}
98
				url={actionLink}
99
				currentItem={selectItem}
100
				action={getData}
101
			/>
102
			<DeleteModal
103
				isOpen={showDeleteModal}
104
				closeModal={closeDeleteModal}
105
				url={actionLink}
106
				onComplete={getData}
107
			/>
108
		</>
109
	)
5674 stevensc 110
}
111
 
112
export default SkillsView