Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 12475 | Rev 12487 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

import axios from 'axios'
import React, { useState, useEffect } from 'react'
import { Card } from 'react-bootstrap'
import { useDispatch } from 'react-redux'
import { useHistory } from 'react-router-dom'
import { LengthFilter, SearchInput, Table, TablePagination } from '../../../recruitment_and_selection/components/TableComponents'
import { addNotification } from '../../../redux/notification/notification.actions'
import DeleteModal from '../../../shared/DeleteModal'

const headers = [
        { key: 'name', label: 'Nombre', isSorteable: true },
        { key: 'description', label: 'Descripción', isSorteable: true },
        { key: 'status', label: 'Estatus', isSorteable: false },
        { key: 'actions', label: 'Acciones', isSorteable: false }
]

const TableView = ({ table_link, setActionLink, permisions, add_link }) => {

        const history = useHistory()
        const dispatch = useDispatch()
        const [showDeleteModal, setShowDeleteModal] = useState(false)
        const [deleteLink, setDeleteLink] = useState('')
        const [items, setItems] = useState({})
        const [search, setSearch] = useState('')
        const [startItem, setStartItem] = useState(1)
        const [lastItem, setLastItem] = useState(10)
        const [total, setTotal] = useState(10)
        const [dataLength, setDataLength] = useState(10)
        const [pages, setPages] = useState({
                current: 1,
                last: 1
        })

        const getData = ({ url = '', params = {} }) => {

                axios.get(url, { params: { ...params } })
                        .then(({ data }) => {
                                if (!data.success) {
                                        dispatch(addNotification({
                                                style: 'error',
                                                msg: 'Ha ocurrido un error'
                                        }))
                                }

                                setItems(data.data.items)
                                setTotal(data.data.total)
                                setPages({ ...pages, last: Math.ceil(data.data.total / dataLength) })
                        })
                        .catch(() => dispatch(addNotification({
                                style: 'error',
                                msg: 'Ha ocurrido un error'
                        })))
        }

        useEffect(() => {
                getData({
                        url: table_link,
                        params: {
                                search: search,
                                length: dataLength,
                                start: pages.current
                        }
                })
        }, [search, dataLength, pages.current])

        useEffect(() => {
                if (pages.current > 1) {
                        setStartItem((dataLength * (pages.current - 1)) + 1)
                } else {
                        setStartItem(1)
                }
        }, [pages.current])

        useEffect(() => {
                if (items) {
                        if (startItem > 1) {
                                setLastItem(startItem + (items.length - 1))
                        } else {
                                setLastItem(items.length)
                        }
                }
        }, [items])

        return (
                <>
                        <h1>Hello</h1>
                </>
        )
}

export default TableView