Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 15393 | | Comparar con el anterior | Ultima modificación | Ver Log |

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