Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 10434 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 10434 Rev 10436
Línea 1... Línea -...
1
import React, { useState, useEffect } from 'react'
-
 
2
import axios from 'axios'
1
import React from 'react'
3
import { Card } from 'react-bootstrap'
-
 
4
import { LengthFilter, SearchInput, Table, TablePagination } from '../../components/TableComponents'
-
 
5
import { useHistory } from 'react-router-dom'
2
import { Switch } from 'react-router-dom'
6
import { addNotification } from '../../../redux/notification/notification.actions'
-
 
7
import { useDispatch } from 'react-redux'
3
import FormView from './FormView'
8
import DeleteModal from '../../../shared/DeleteModal'
4
import TableView from './TableView'
9
import ContentTitle from '../../../shared/ContentTitle'
-
 
Línea 10... Línea -...
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
 
5
 
20
const MainView = ({ 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
        })
-
 
Línea 71... Línea 6...
71
    }, [search, dataLength, pages.current, currentVacancy])
6
const MainView = ({ backendVars }) => {
72
 
7
 
73
    return (
8
    return (
74
        <ContentTitle title="Entrevistas">
-
 
75
            <section className="content">
-
 
76
                <div className="container-fluid">
-
 
77
                    <div className="row">
9
        <ContentTitle title="Entrevistas">
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'
10
            <Switch>
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
                                        {
11
                <Route
137
                                            data.items?.map((item, index) => (
-
 
138
                                                <tr key={index}>
-
 
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>
-
 
154
                                                    <td className='d-inline-flex' style={{ gap: '10px' }}>
-
 
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
                                                            permisions.allowReport
-
 
178
                                                            &&
-
 
179
                                                            <i
-
 
180
                                                                className='fa fa-external-link'
-
 
181
                                                                onClick={() => {
-
 
182
                                                                    setShowDeleteModal(true)
-
 
183
                                                                    setDeleteLink(item.actions.link_delete)
-
 
184
                                                                }}
-
 
185
                                                                style={{ cursor: 'pointer' }}
-
 
186
                                                            />
-
 
187
                                                        }
-
 
188
                                                        {
-
 
189
                                                            permisions.allowFile
-
 
190
                                                            &&
-
 
191
                                                            <a href={item.actions.link_file}>
-
 
192
                                                                <i className='fa fa-file-o' style={{ cursor: 'pointer' }} />
-
 
193
                                                            </a>
-
 
194
                                                        }
-
 
195
                                                    </td>
-
 
196
                                                </tr>
-
 
197
                                            ))
-
 
198
                                        }
-
 
199
                                    </Table>
-
 
200
                                    <div className='row justify-content-between align-items-center'>
-
 
201
                                        <p className='mb-0'>
-
 
202
                                            {`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`}
-
 
203
                                        </p>
-
 
204
                                        <TablePagination
-
 
205
                                            onDecrement={(e) => setPages(prev => prev.current -= 1)}
-
 
206
                                            onIncrement={(e) => setPages(prev => prev.current += 1)}
-
 
207
                                            totalPages={pages.last}
-
 
208
                                            currentPage={pages.current}
-
 
209
                                        />
-
 
210
                                    </div>
-
 
211
                                </Card.Body>
-
 
212
                            </Card>
12
                    exact path='/recruitment-and-selection/interview/form'
213
                        </div>
13
                    component={() => <TableView {...backendVars} />}
214
                    </div >
-
 
215
                </div >
-
 
216
            </section >
-
 
217
            <DeleteModal
-
 
218
                url={deleteLink}
14
                />
219
                isOpen={showDeleteModal}
15
                <Route
220
                closeModal={() => setShowDeleteModal(false)}
-
 
221
                title="Esta seguro de borrar esta vacante?"
16
                    exact path='/recruitment-and-selection/interview/form/:action'
222
                onComplete={() => setData({ ...data, items: data.items.filter((item) => item.actions.link_delete !== deleteLink) })}
17
                    component={() => <FormView {...backendVars} />}
223
                message="Vacante eliminada"
18
                />
224
            />
19
            </Switch>
225
        </ContentTitle >
20
        </ContentTitle >
226
    )
21
    )
227
}
22
}