Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 14883 | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

import axios from 'axios'
import React, { useState } from 'react'
import { useEffect } from 'react'
import { Button, Modal } from 'react-bootstrap'
import { useDispatch } from 'react-redux'
import { addNotification } from '../../../redux/notification/notification.actions'


const AppliedModal = ({ closeModal, dataLink }) => {

        const dispatch = useDispatch()
        const [data, setData] = useState([])

        const getData = () => {
                axios.get(dataLink)
                        .then(({ data }) => {
                                if (!data.success) {
                                        typeof data.data === 'string'
                                                ?
                                                dispatch(addNotification({
                                                        style: 'danger',
                                                        msg: data.data
                                                }))
                                                : Object.entries(data.data).map(([key, value]) =>
                                                        value.map(err =>
                                                                dispatch(addNotification({
                                                                        style: 'danger',
                                                                        msg: `${key}: ${err}`
                                                                }))
                                                        )
                                                )
                                        return
                                }

                                setData(data.data)
                        })
        }

        useEffect(() => {
                getData()
        }, [])


        return (
                <Modal size="lg" show onHide={closeModal}>
                        <Modal.Header closeButton>
                                <Modal.Title>Usuario que aplicaron</Modal.Title>
                        </Modal.Header>
                        <Modal.Body>
                                <table className="table table-hover dataTable no-footer dtr-inline w-100">
                                        <thead>
                                                <tr>
                                                        <th className="text-vertical-middle">
                                                                Nombre
                                                        </th>
                                                        <th className="text-vertical-middle">
                                                                Correo
                                                        </th>
                                                        <th className="text-vertical-middle">
                                                                Acciones
                                                        </th>
                                                </tr>
                                        </thead>
                                        <tbody>
                                                {
                                                        data.map((item, index) =>
                                                                <tr key={index}>
                                                                        <td>{`${item.first_name} ${item.last_name}`}</td>
                                                                        <td>{item.email}</td>
                                                                        <td>
                                                                                <a
                                                                                        className='btn btn-default btn-view-profile'
                                                                                        href={item.link_view}
                                                                                        target="_blank"
                                                                                        rel="noopener noreferrer"
                                                                                >
                                                                                        <i className='fa fa-external-link' />
                                                                                        Ver aplicación
                                                                                </a>
                                                                        </td>
                                                                </tr>
                                                        )}
                                        </tbody>
                                </table >
                        </Modal.Body>
                        <Modal.Footer>
                                <Button variant="danger" onClick={closeModal}>
                                        Cerrar
                                </Button>
                        </Modal.Footer>
                </Modal >
        )
}

export default AppliedModal