Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 9511 Rev 9512
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'
-
 
4
import { TablePagination } from '../components/TableComponents'
Línea 3... Línea 5...
3
 
5
 
4
const headers = [
6
const headers = [
5
  { key: "name", label: "Nombre", isSorteable: true },
7
  { key: "name", label: "Nombre", isSorteable: true },
6
  { key: "minimum_no_of_employee", label: "Mínimo", isSorteable: true },
8
  { key: "minimum_no_of_employee", label: "Mínimo", isSorteable: true },
Línea 10... Línea 12...
10
]
12
]
Línea 11... Línea 13...
11
 
13
 
Línea 12... Línea 14...
12
const MainView = ({ add_link, dashboard_link, permisions, table_link }) => {
14
const MainView = ({ add_link, dashboard_link, permisions, table_link }) => {
-
 
15
 
-
 
16
  const [data, setData] = useState({})
-
 
17
  const [dataLength, setDataLength] = useState(10);
-
 
18
  const [pages, setPages] = useState({
-
 
19
    current: 1,
Línea 13... Línea 20...
13
 
20
    last: 1
Línea 14... Línea 21...
14
  const [data, setData] = useState({})
21
  });
15
 
22
 
16
  const getData = ({ url = '', params = {} }) => {
23
  const getData = ({ url = '', params = {} }) => {
17
 
24
 
18
    axios.get(url, { params: { ...params } })
-
 
19
      .then(({ data }) => {
-
 
20
        if (data.success) {
25
    axios.get(url, { params: { ...params } })
-
 
26
      .then(({ data }) => {
-
 
27
        if (!data.success) {
-
 
28
          console.log('Ha ocurrido un error')
21
          setData(data.data)
29
        }
22
 
30
 
23
          return data.data
31
        setData(data.data)
Línea 24... Línea 32...
24
        }
32
        setPages(prev => prev.last = Math.ceil(data.data.total / dataLength))
25
      })
33
      })
26
      .catch((err) => console.log(err))
34
      .catch((err) => console.log(err))
Línea 27... Línea 35...
27
  }
35
  }
-
 
36
 
-
 
37
  useEffect(() => {
-
 
38
    getData({ url: table_link })
-
 
39
  }, [dataLength, pages.current])
-
 
40
 
-
 
41
  return (
-
 
42
    <section className="content">
-
 
43
      <div className="container-fluid">
-
 
44
        <div className="row">
-
 
45
          <div className="col-12">
-
 
46
            <Card>
-
 
47
              <Card.Header>
-
 
48
 
-
 
49
              </Card.Header>
-
 
50
              <Card.Body>
-
 
51
 
-
 
52
              </Card.Body>
-
 
53
              <Card.Footer>
-
 
54
                <div className="col-sm-12 col-md-5">
-
 
55
                  <div className="d-flex justify-content-start" >
-
 
56
                    {`Mostrando registros del ${(dataLength * pages.current) - (dataLength - 1) || 0} al ${0} de un total de ${data.total || 0} registros`}
-
 
57
                  </div>
-
 
58
                </div>
-
 
59
                <div className="col-sm-12 col-md-5">
-
 
60
                  <div className="d-flex justify-content-end" >
-
 
61
                    <TablePagination
-
 
62
                      onDecrement={(e) => setPages(prev => prev.current -= 1)}
-
 
63
                      onIncrement={(e) => setPages(prev => prev.current += 1)}
-
 
64
                      totalPages={pages.last}
-
 
65
                      currentPage={pages.current}
-
 
66
                    />
-
 
67
                  </div>
28
 
68
                </div>
29
  useEffect(() => {
69
              </Card.Footer>
30
    getData(table_link)
70
            </Card>
31
  }, [])
71
          </div>
32
 
72
        </div >