Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev Autor Línea Nro. Línea
10436 stevensc 1
import React, { useState, useEffect } from 'react'
2
import axios from 'axios'
3
import { Card } from 'react-bootstrap'
4
import { LengthFilter, SearchInput, Table, TablePagination } from '../../components/TableComponents'
5
import { Link, useHistory } from 'react-router-dom'
6
import { addNotification } from '../../../redux/notification/notification.actions'
7
import { useDispatch } from 'react-redux'
8
import DeleteModal from '../../../shared/DeleteModal'
9
import ContentTitle from '../../../shared/ContentTitle'
10
 
11
const headers = [
12
    { key: "name", label: "Nombre", isSorteable: true },
13
    { key: "email", label: "Correo electrónico", isSorteable: true },
14
    { key: "type", label: "Entrevistado por", isSorteable: true },
15
    { key: "vacancy", label: "Vacantes", isSorteable: true },
16
    { key: "points", label: "Evaluación", isSorteable: true },
17
    { key: "actions", label: "Acciones", isSorteable: false }
18
]
19
 
20
const TableView = ({ table_link, permisions, add_link, vacancies }) => {
21
 
22
    const history = useHistory()
23
    const dispatch = useDispatch()
24
    const [showDeleteModal, setShowDeleteModal] = useState(false)
25
    const [currentVacancy, setCurrentVacancy] = useState(vacancies[0].uuid || '')
26
    const [deleteLink, setDeleteLink] = useState('')
27
    const [data, setData] = useState({})
28
    const [search, setSearch] = useState('')
29
    const [dataLength, setDataLength] = useState(10);
30
    const points = {
31
        0: '0%',
32
        1: '25%',
33
        2: '50%',
34
        3: '75%',
35
        4: '100%'
36
    }
37
    const [pages, setPages] = useState({
38
        current: 1,
39
        last: 1
40
    });
41
 
42
    const getData = ({ url = '', params = {} }) => {
43
 
44
        axios.get(url, { params: { ...params } })
45
            .then(({ data }) => {
46
                if (!data.success) {
47
                    dispatch(addNotification({
48
                        style: "error",
49
                        msg: "Ha ocurrido un error"
50
                    }))
51
                }
52
 
53
                setData(data.data)
54
                setPages({ ...pages, last: Math.ceil(data.data.total / dataLength) })
55
            })
56
            .catch((err) => dispatch(addNotification({
57
                style: "error",
58
                msg: "Ha ocurrido un error"
59
            })))
60
    }
61
 
62
    useEffect(() => {
63
        getData({
64
            url: `${table_link}/${currentVacancy}`,
65
            params: {
66
                search: search,
67
                length: dataLength,
68
                page: pages.current
69
            }
70
        })
71
    }, [search, dataLength, pages.current, currentVacancy])
72
 
73
    return (
74
        <>
75
            <section className="content">
76
                <div className="container-fluid">
77
                    <div className="row">
78
                        <div className="col-12">
79
                            <Card>
80
                                <Card.Header>
81
                                    <div className="row" style={{ gap: '10px' }}>
82
                                        <div className="form-group">
83
                                            <label>Vacantes</label>
84
                                            <select
85
                                                className="form-control"
86
                                                value={currentVacancy}
87
                                                onChange={(e) => setCurrentVacancy(e.target.value)}
88
                                                defaultValue={vacancies[0].uuid}
89
                                            >
90
                                                {
91
                                                    vacancies.map((vacancy) => (
92
                                                        <option value={vacancy.uuid}>{vacancy.name}</option>
93
                                                    ))
94
                                                }
95
                                            </select>
96
                                        </div>
97
                                    </div>
98
                                    <div className="row justify-content-end" style={{ gap: '10px' }}>
99
                                        {
100
                                            permisions.allowAdd
101
                                            &&
102
                                            <label
103
                                                className='d-flex align-items-center'
104
                                                onClick={() => {
105
                                                    history.push('/recruitment-and-selection/vacancies/add')
106
                                                }}
107
                                                style={{ cursor: 'pointer' }}
108
                                            >
109
                                                <i className="fa fa-plus mr-2" />
110
                                                Agregar
111
                                            </label>
112
                                        }
113
                                        <label
114
                                            className='d-flex align-items-center'
115
                                            onClick={() => getData({
116
                                                url: table_link,
117
                                                params: {
118
                                                    search: search,
119
                                                    length: dataLength,
120
                                                    page: pages.current
121
                                                }
122
                                            })}
123
                                            style={{ cursor: 'pointer' }}
124
                                        >
125
                                            <i className='fa fa-refresh mr-2' />
126
                                            Actualizar
127
                                        </label>
128
                                    </div>
129
                                    <div className="row justify-content-between align-items-center">
130
                                        <LengthFilter onChange={(e) => setDataLength(e.target.value)} />
131
                                        <SearchInput onChange={(e) => setSearch(e.target.value)} />
132
                                    </div>
133
                                </Card.Header>
134
                                <Card.Body>
135
                                    <Table data={data.items} headers={headers} setData={setData}>
136
                                        {
137
                                            data.items?.map((item) => (
138
                                                <tr key={item.uuid}>
139
                                                    <td>{`${item.first_name} ${item.last_name}`}</td>
140
                                                    <td>{item.email}</td>
141
                                                    <td>
142
                                                        {
143
                                                            item.type === "r"
144
                                                                ? "Recursos Humanos"
145
                                                                : "Potencial superior"
146
                                                        }
147
                                                    </td>
148
                                                    <td>{item.vacancy}</td>
149
                                                    <td>
150
                                                        {
151
                                                            points[item.points]
152
                                                        }
153
                                                    </td>
10439 stevensc 154
                                                    <td className='d-inline-flex align-items-center' style={{ gap: '10px' }}>
10436 stevensc 155
                                                        {
156
                                                            permisions.allowEdit
157
                                                            &&
158
                                                            <i
159
                                                                className='fa fa-pencil'
160
                                                                onClick={() => { console.log("edit") }}
161
                                                                style={{ cursor: 'pointer' }}
162
                                                            />
163
                                                        }
164
                                                        {
165
                                                            permisions.allowDelete
166
                                                            &&
167
                                                            <i
168
                                                                className='fa fa-trash'
169
                                                                onClick={() => {
170
                                                                    setShowDeleteModal(true)
171
                                                                    setDeleteLink(item.actions.link_delete)
172
                                                                }}
173
                                                                style={{ cursor: 'pointer' }}
174
                                                            />
175
                                                        }
176
                                                        {
177
                                                            item.type === "r"
178
                                                            &&
179
                                                            <Link to={`/recruitment-and-selection/interview/form/${item.uuid}/file`} className='btn p-0'>
180
                                                                <i className='fa fa-external-link' style={{ cursor: 'pointer' }} />
181
                                                            </Link>
182
                                                        }
183
                                                        {
184
                                                            permisions.allowFile
185
                                                            &&
186
                                                            <a href={item.actions.link_report} target='_blank' className='btn p-0'>
187
                                                                <i className='fa fa-file-o' style={{ cursor: 'pointer' }} />
188
                                                            </a>
189
                                                        }
190
                                                    </td>
191
                                                </tr>
192
                                            ))
193
                                        }
194
                                    </Table>
195
                                    <div className='row justify-content-between align-items-center'>
196
                                        <p className='mb-0'>
197
                                            {`Mostrando registros del ${(dataLength * pages.current) - (dataLength - 1) || 0} al ${(dataLength * pages.current) - (dataLength - data.total) || 0} de un total de ${data.total || 0} registros`}
198
                                        </p>
199
                                        <TablePagination
200
                                            onDecrement={(e) => setPages(prev => prev.current -= 1)}
201
                                            onIncrement={(e) => setPages(prev => prev.current += 1)}
202
                                            totalPages={pages.last}
203
                                            currentPage={pages.current}
204
                                        />
205
                                    </div>
206
                                </Card.Body>
207
                            </Card>
208
                        </div>
209
                    </div >
210
                </div >
211
            </section >
212
            <DeleteModal
213
                url={deleteLink}
214
                isOpen={showDeleteModal}
215
                closeModal={() => setShowDeleteModal(false)}
216
                title="Esta seguro de borrar esta entrevista?"
217
                onComplete={() => setData({ ...data, items: data.items.filter((item) => item.actions.link_delete !== deleteLink) })}
218
                message="Entrevista eliminada"
219
            />
220
        </>
221
    )
222
}
223
export default TableView