Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev Autor Línea Nro. Línea
15310 stevensc 1
import React from 'react'
2
 
3
// Object that initialize the options to render icon
4
const DEFAULT_OPTION = {
5
	permission: false,
6
	icon: (value) => <i className='fa fa-edit' onClick={() => console.log(value)} /> // Function to render icon and received url by props
7
}
8
 
9
const TableRow = ({
10
	item = {},
11
	editOptions = DEFAULT_OPTION,
12
	deleteOptions = DEFAULT_OPTION
13
}) => {
14
 
15
	// Validate if action have permision to render
16
	const renderActions = (key, value) => {
17
		if (key === 'link_edit' && editOptions.permission) return editOptions.icon(value)
18
		if (key === 'link_delete' && deleteOptions.permission) return deleteOptions.icon(value)
19
		return null
20
	}
21
 
22
	return (
23
		<tr>
24
			{Object.entries(item)
25
				.map(([key, value], index) => {
15320 stevensc 26
					if (key === 'id' || key === 'uuid') return null
15310 stevensc 27
					if (key === 'status') {
28
						let status = value === 'a' ? 'Activo' : 'Inactivo'
29
						return <td key={index}>{status}</td>
30
					}
31
					if (key === 'actions') {
15318 stevensc 32
						return <td className='d-flex' key={index} style={{ gap: '.5rem' }}>
15310 stevensc 33
							{Object.entries(value)
34
								.map(([key, value]) => renderActions(key, value))}
35
						</td>
36
					}
37
					return <td key={index}>{value}</td>
38
				}
39
				)}
40
 
41
		</tr>
42
	)
43
}
44
 
45
export default TableRow