Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev Autor Línea Nro. Línea
5682 stevensc 1
import React, { useState } from 'react'
2
import axios from 'axios';
3
import EditModal from '../../groups-types/view/EditModal';
4
import TableContainer from '../../company-sizes/view/TableContainer'
7427 stevensc 5
import DeleteModal from '../../../shared/DeleteModal';
5682 stevensc 6
 
7
const DegreesView = ({ urlsVar }) => {
8
 
6353 stevensc 9
  const { linkTable, addUrl, allowAdd, allowEdit, allowDelete } = urlsVar
5682 stevensc 10
  const [companyData, setCompanyData] = useState({});
11
  const [showModal, setShowModal] = useState(false);
12
  const [showDeleteModal, setShowDeleteModal] = useState(false);
13
  const [selectItem, setSelectItem] = useState(null);
14
  const [actionLink, setActionLink] = useState(addUrl);
15
  const headers = [
16
    { key: "name", label: "Nombre", isSorteable: true },
17
    { key: "status", label: "Activo", isSorteable: false },
18
    { key: "actions", label: "Acciones", isSorteable: false }
19
  ]
20
 
21
  const getData = (search, start, length) => {
22
    axios.get(
23
      linkTable,
24
      {
25
        params: {
26
          search: search,
27
          start: start,
28
          length: length
29
        }
30
      })
31
      .then(({ data }) => {
32
        if (data.success) {
33
          setCompanyData(data.data)
34
 
35
          return data.data
36
        }
37
      })
38
      .catch((err) => console.log(err))
39
  }
40
 
41
  const closeModal = () => {
42
    setShowModal(false)
43
    setSelectItem(null)
44
    setActionLink(addUrl)
45
  }
46
 
47
  const closeDeleteModal = () => {
48
    setShowDeleteModal(false)
49
    setActionLink(addUrl)
50
  }
51
 
52
  const editItem = (item) => {
53
    setSelectItem(item);
54
    setActionLink(item.actions.link_edit);
55
    setShowModal(true);
56
  }
57
 
58
  const deleteItem = (item) => {
59
    setActionLink(item.actions.link_delete);
60
    setShowDeleteModal(true);
61
  }
62
 
63
  const addItem = () => {
64
    setSelectItem(null);
65
    setActionLink(addUrl)
66
    setShowModal(true);
67
  }
68
 
69
  return (
70
    <>
71
      <section className="content">
72
        <section className="content-header">
73
          <div className="container-fluid">
74
            <div className="row mb-2">
75
              <div className="col-sm-12">
76
                <h1>Grados</h1>
77
              </div>
78
            </div>
79
          </div>
80
        </section>
81
        <TableContainer
82
          data={companyData}
83
          getData={getData}
84
          onEdit={editItem}
85
          onDelete={deleteItem}
86
          onAdd={addItem}
87
          headers={headers}
6353 stevensc 88
          allowAdd={allowAdd}
89
          allowEdit={allowEdit}
90
          allowDelete={allowDelete}
5682 stevensc 91
        />
92
      </section>
93
      <EditModal
94
        isOpen={showModal}
95
        title='Grados'
96
        closeModal={closeModal}
97
        isEdit={actionLink !== addUrl}
98
        url={actionLink}
99
        currentItem={selectItem}
100
        action={getData}
101
      />
102
      <DeleteModal
103
        isOpen={showDeleteModal}
104
        closeModal={closeDeleteModal}
105
        url={actionLink}
106
        action={getData}
107
      />
108
    </>
109
  )
110
}
111
 
112
export default DegreesView