Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev Autor Línea Nro. Línea
10061 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 { 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'
10095 stevensc 9
import ContentTitle from '../../../shared/ContentTitle'
9954 stevensc 10
 
10061 stevensc 11
const headers = [
12
    { key: "first_name", label: "Nombre", isSorteable: true },
13
    { key: "last_name", label: "Apellido", isSorteable: true },
14
    { key: "email", label: "Correo electrónico", isSorteable: true },
15
    { key: "status", label: "Estatus", isSorteable: false },
16
    { key: "actions", label: "Acciones", isSorteable: false }
17
]
9954 stevensc 18
 
10061 stevensc 19
const MainView = ({ email_link, add_link, table_link, permisions }) => {
9954 stevensc 20
 
10061 stevensc 21
    const history = useHistory()
22
    const dispatch = useDispatch()
23
    const [showDeleteModal, setShowDeleteModal] = useState(false)
24
    const [deleteLink, setDeleteLink] = useState('')
25
    const [data, setData] = useState({})
26
    const [search, setSearch] = useState('')
27
    const [dataLength, setDataLength] = useState(10);
28
    const [pages, setPages] = useState({
29
        current: 1,
30
        last: 1
31
    });
32
 
33
    const getData = ({ url = '', params = {} }) => {
34
 
35
        axios.get(url, { params: { ...params } })
36
            .then(({ data }) => {
37
                if (!data.success) {
38
                    dispatch(addNotification({
39
                        style: "error",
40
                        msg: "Ha ocurrido un error"
41
                    }))
42
                }
43
 
44
                setData(data.data)
45
                setPages({ ...pages, last: Math.ceil(data.data.total / dataLength) })
46
            })
47
            .catch((err) => dispatch(addNotification({
48
                style: "error",
49
                msg: "Ha ocurrido un error"
50
            })))
51
    }
52
 
53
    useEffect(() => {
54
        getData({
55
            url: table_link,
56
            params: {
57
                search: search,
58
                length: dataLength,
59
                page: pages.current
60
            }
61
        })
62
    }, [search, dataLength, pages.current])
63
 
9954 stevensc 64
    return (
10095 stevensc 65
        <ContentTitle title='Preselección'>
10061 stevensc 66
            <section className="content">
67
                <div className="container-fluid">
68
                    <div className="row">
69
                        <div className="col-12">
70
                            <Card>
71
                                <Card.Header>
72
                                    <div className="row justify-content-end" style={{ gap: '10px' }}>
73
                                        {
10254 stevensc 74
                                            permisions.allowAdd
10061 stevensc 75
                                            &&
76
                                            <label
77
                                                className='d-flex align-items-center'
78
                                                onClick={() => {
79
                                                    setActionLink(add_link)
80
                                                    history.push('/recruitment-and-selection/vacancies/add')
81
                                                }}
82
                                                style={{ cursor: 'pointer' }}
83
                                            >
84
                                                <i className="fa fa-plus mr-2" />
85
                                                Agregar
86
                                            </label>
87
                                        }
88
                                        <label
89
                                            className='d-flex align-items-center'
90
                                            onClick={() => getData({
91
                                                url: table_link,
92
                                                params: {
93
                                                    search: search,
94
                                                    length: dataLength,
95
                                                    page: pages.current
96
                                                }
97
                                            })}
98
                                            style={{ cursor: 'pointer' }}
99
                                        >
100
                                            <i className='fa fa-refresh mr-2' />
101
                                            Actualizar
102
                                        </label>
103
                                    </div>
104
                                    <div className="row justify-content-between align-items-center">
105
                                        <LengthFilter onChange={(e) => setDataLength(e.target.value)} />
106
                                        <SearchInput onChange={(e) => setSearch(e.target.value)} />
107
                                    </div>
108
                                </Card.Header>
109
                                <Card.Body>
110
                                    <Table data={data.items} headers={headers} setData={setData}>
111
                                        {
112
                                            data.items?.map((item, index) => (
113
                                                <tr key={index}>
114
                                                    <td>{item.first_name}</td>
115
                                                    <td>{item.last_name}</td>
116
                                                    <td>{item.email}</td>
117
                                                    <td>
118
                                                        {
119
                                                            item.status === "a"
120
                                                                ? <i className='fa fa-check' style={{ color: '#5cb85c' }} />
121
                                                                : <i className='fa fa-close' style={{ color: 'red' }} />
122
                                                        }
123
                                                    </td>
124
                                                    <td className='d-flex' style={{ gap: '10px' }}>
125
                                                        {
10254 stevensc 126
                                                            permisions.allowEdit
10061 stevensc 127
                                                            &&
128
                                                            <i
129
                                                                className='fa fa-pencil'
130
                                                                onClick={() => {
131
                                                                    setActionLink(item.actions.link_edit)
132
                                                                    history.push('/recruitment-and-selection/vacancies/edit')
133
                                                                }}
134
                                                                style={{ cursor: 'pointer' }}
135
                                                            />
136
                                                        }
137
                                                        {
10254 stevensc 138
                                                            permisions.allowDelete
10061 stevensc 139
                                                            &&
140
                                                            <i
141
                                                                className='fa fa-trash'
142
                                                                onClick={() => {
143
                                                                    setShowDeleteModal(true)
144
                                                                    setDeleteLink(item.actions.link_delete)
145
                                                                }}
146
                                                                style={{ cursor: 'pointer' }}
147
                                                            />
148
                                                        }
149
                                                    </td>
150
                                                </tr>
151
                                            ))
152
                                        }
153
                                    </Table>
154
                                    <div className='row justify-content-between align-items-center'>
155
                                        <p className='mb-0'>
156
                                            {`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`}
157
                                        </p>
158
                                        <TablePagination
159
                                            onDecrement={(e) => setPages(prev => prev.current -= 1)}
160
                                            onIncrement={(e) => setPages(prev => prev.current += 1)}
161
                                            totalPages={pages.last}
162
                                            currentPage={pages.current}
163
                                        />
164
                                    </div>
165
                                </Card.Body>
166
                            </Card>
167
                        </div>
168
                    </div >
169
                </div >
170
            </section >
171
            <DeleteModal
172
                url={deleteLink}
173
                isOpen={showDeleteModal}
174
                closeModal={() => setShowDeleteModal(false)}
175
                title="Esta seguro de borrar esta vacante?"
176
                onComplete={() => setData({ ...data, items: data.items.filter((item) => item.actions.link_delete !== actionLink) })}
177
                message="Vacante eliminada"
178
            />
10095 stevensc 179
        </ContentTitle>
9954 stevensc 180
    )
181
}
182
export default MainView