Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 9954 | Rev 10095 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

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