Proyectos de Subversion LeadersLinked - Backend

Rev

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

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