Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 3878 | Rev 3883 | Ir a la última revisión | | Comparar con el anterior | 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
    return (
47
        <Modal show={isShow} onHide={handleClose}>
48
            <Modal.Header closeButton />
49
            <Modal.Body>
50
                <div className="container">
51
                    <div className="mb-2">
52
                        <label htmlFor="search">
53
                            Escribe el nombre
54
                        </label>
55
                        <input
56
                            onChange={handleChange}
57
                            name="search"
58
                            placeholder="Escribe el nombre del usuario"
59
                        />
60
                    </div>
61
                    {!!users.length &&
62
                        users.map(element =>
63
                            <div
64
                                className="d-flex align-items-center justify-content-between flex-column flex-md-row"
65
                                key={element.value}
66
                                style={{ gap: '.5rem' }}
67
                            >
68
                                <span>{element.text}</span>
69
                                <button
70
                                    className="btn btn-primary"
71
                                    onClick={() => invite(element.value)}
72
                                >
73
                                    Invitar
74
                                </button>
75
                            </div>
76
                        )
77
                    }
78
                </div>
79
            </Modal.Body>
80
        </Modal>
81
    )
82
}
83
 
84
export default AddMemberModal