Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 3879 | Ir a la última revisión | | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
3878 stevensc 1
/* eslint-disable react/prop-types */
2
import axios from 'axios'
3
import React, { useState } from 'react'
4
import { useEffect } from 'react'
5
import { Modal } from 'react-bootstrap'
6
import { addNotification } from '../../../redux/notification/notification.actions'
7
 
8
const AddMemberModal = ({
9
    isShow = false,
10
    linkInvite = '',
11
    handleClose = function () { }
12
}) => {
13
 
14
    const [users, setUsers] = useState([])
15
    const [search, setSearch] = useState('')
16
 
17
    const handleChange = ({ target }) => setSearch(target.value)
18
 
19
    const searchMember = async (value) => {
20
        try {
21
            const { data } = await axios.get(linkInvite + '?search=' + value)
22
            setUsers(data.data)
23
        } catch (error) {
24
            console.log('>>: error > ', error)
25
        }
26
    }
27
 
28
    const invite = (uuid) => {
29
        const formData = new FormData()
30
        formData.append('id', uuid)
31
        axios.post(linkInvite, formData)
32
            .then(({ data }) => {
33
                if (!data.success) {
34
                    return addNotification({ msg: data.data, style: 'danger' })
35
                }
36
                addNotification({ msg: data.data, style: 'success' })
37
                handleClose()
38
            })
39
            .catch(() => addNotification({ msg: 'Disculpe, ha ocurrido un error', style: 'danger' }))
40
    }
41
 
42
    useEffect(() => {
43
        searchMember(search)
44
    }, [search])
45
 
46
 
47
    return (
48
        <Modal show={isShow} onHide={handleClose}>
49
            <Modal.Header closeButton />
50
            <Modal.Body>
51
                <div className="container">
52
                    <div className="mb-2">
53
                        <label htmlFor="search">
54
                            Escribe el nombre
55
                        </label>
56
                        <input
57
                            onChange={handleChange}
58
                            name="search"
59
                            placeholder="Escribe el nombre del usuario"
60
                        />
61
                    </div>
62
                    {!!users.length &&
63
                        users.map(element =>
64
                            <div
65
                                className="d-flex align-items-center justify-content-between flex-column flex-md-row"
66
                                key={element.value}
67
                                style={{ gap: '.5rem' }}
68
                            >
69
                                <span>{element.text}</span>
70
                                <button
71
                                    className="btn btn-primary"
72
                                    onClick={() => invite(element.value)}
73
                                >
74
                                    Invitar
75
                                </button>
76
                            </div>
77
                        )
78
                    }
79
                </div>
80
            </Modal.Body>
81
        </Modal>
82
    )
83
}
84
 
85
export default AddMemberModal