Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev Autor Línea Nro. Línea
5647 stevensc 1
import React, { useState } from 'react'
11272 stevensc 2
import axios from 'axios'
3
import EditModal from './EditModal'
4
import DeleteModal from '../../../shared/DeleteModal'
15499 stevensc 5
import TableFilters from '../../../shared/table/TableFilters'
6
import Table from '../../../shared/table/Table'
5647 stevensc 7
 
8
const IndustriesView = ({ urlsVar }) => {
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
	]
5647 stevensc 20
 
15465 stevensc 21
	const getData = (params = {}) => {
15473 stevensc 22
		axios.get(linkTable, { params: params })
23
			.then(({ data: response }) => {
24
				if (response.success) setCompanyData(response.data)
11272 stevensc 25
			})
26
			.catch((err) => console.log(err))
27
	}
5647 stevensc 28
 
11272 stevensc 29
	const closeModal = () => {
30
		setShowModal(false)
31
		setSelectItem(null)
32
		setActionLink(addUrl)
33
	}
5647 stevensc 34
 
11272 stevensc 35
	const closeDeleteModal = () => {
36
		setShowDeleteModal(false)
37
		setActionLink(addUrl)
38
	}
5647 stevensc 39
 
11272 stevensc 40
	const editItem = (item) => {
41
		setSelectItem(item)
42
		setActionLink(item.actions.link_edit)
43
		setShowModal(true)
44
	}
5647 stevensc 45
 
11272 stevensc 46
	const deleteItem = (item) => {
47
		setActionLink(item.actions.link_delete)
48
		setShowDeleteModal(true)
49
	}
5647 stevensc 50
 
11272 stevensc 51
	const addItem = () => {
52
		setSelectItem(null)
53
		setActionLink(addUrl)
54
		setShowModal(true)
55
	}
5647 stevensc 56
 
15496 stevensc 57
	const tableRendered = () => {
58
		return (
59
			<Table
60
				data={companyData.items}
61
				onEdit={editItem}
62
				onDelete={deleteItem}
63
				headers={headers}
64
				allowEdit={allowEdit}
65
				allowDelete={allowDelete}
66
			/>
67
		)
68
	}
69
 
11272 stevensc 70
	return (
15469 stevensc 71
		<>
72
			<section className="content">
73
				<section className="content-header">
15493 stevensc 74
					<h1>Industrias</h1>
15469 stevensc 75
				</section>
15493 stevensc 76
				<div className="container-fluid">
15499 stevensc 77
					<TableFilters data={companyData} getData={getData} onAdd={addItem} allowAdd={allowAdd}>
15498 stevensc 78
						{companyData.items && tableRendered()}
15499 stevensc 79
					</TableFilters>
15493 stevensc 80
				</div>
15469 stevensc 81
			</section>
15473 stevensc 82
			<EditModal
83
				isOpen={showModal}
84
				title='Industrias'
85
				closeModal={closeModal}
86
				isEdit={actionLink !== addUrl}
87
				url={actionLink}
88
				currentItem={selectItem}
89
				action={getData}
90
			/>
91
			<DeleteModal
92
				isOpen={showDeleteModal}
93
				closeModal={closeDeleteModal}
94
				url={actionLink}
95
				onComplete={getData}
96
			/>
15469 stevensc 97
		</>
11272 stevensc 98
	)
5647 stevensc 99
}
100
 
101
export default IndustriesView