| 7317 |
stevensc |
1 |
import React, { useState } from 'react'
|
|
|
2 |
import { axios } from '../../../utils'
|
|
|
3 |
import { useForm } from 'react-hook-form'
|
|
|
4 |
import { Button, Modal } from 'react-bootstrap'
|
|
|
5 |
|
|
|
6 |
import Spinner from '../../UI/Spinner'
|
|
|
7 |
import LoaderContainer from '../../UI/LoaderContainer'
|
|
|
8 |
import FormErrorFeedback from '../../UI/FormErrorFeedback'
|
|
|
9 |
|
|
|
10 |
const CreateGroupModal = ({ closeModal, show }) => {
|
|
|
11 |
const [loading, setLoading] = useState(false)
|
|
|
12 |
const { register, errors, handleSubmit } = useForm()
|
|
|
13 |
|
|
|
14 |
const onSubmitHandler = async (data) => {
|
|
|
15 |
setLoading(true)
|
|
|
16 |
const formData = new FormData()
|
|
|
17 |
Object.entries(data).map(([key, value]) => formData.append(key, value))
|
|
|
18 |
|
|
|
19 |
await axios
|
|
|
20 |
.post('/chat/create-group', formData)
|
|
|
21 |
.then(({ data: response }) => {
|
|
|
22 |
if (response.success) closeModal()
|
|
|
23 |
})
|
|
|
24 |
|
|
|
25 |
setLoading(false)
|
|
|
26 |
}
|
|
|
27 |
|
|
|
28 |
return (
|
|
|
29 |
<Modal show={show} onHide={closeModal}>
|
|
|
30 |
<Modal.Header closeButton>
|
|
|
31 |
<Modal.Title>Crear grupo</Modal.Title>
|
|
|
32 |
</Modal.Header>
|
|
|
33 |
<form onSubmit={handleSubmit(onSubmitHandler)}>
|
|
|
34 |
<Modal.Body>
|
|
|
35 |
<label className="mb-1" htmlFor="name">
|
|
|
36 |
Nombre del grupo
|
|
|
37 |
</label>
|
|
|
38 |
<input
|
|
|
39 |
type="text"
|
|
|
40 |
name="name"
|
|
|
41 |
id="name"
|
|
|
42 |
ref={register({
|
|
|
43 |
required: 'Este campo es requerido',
|
|
|
44 |
})}
|
|
|
45 |
/>
|
|
|
46 |
{errors.name && (
|
|
|
47 |
<FormErrorFeedback>{errors.name.message}</FormErrorFeedback>
|
|
|
48 |
)}
|
|
|
49 |
{loading && (
|
|
|
50 |
<LoaderContainer>
|
|
|
51 |
<Spinner />
|
|
|
52 |
</LoaderContainer>
|
|
|
53 |
)}
|
|
|
54 |
</Modal.Body>
|
|
|
55 |
<Modal.Footer>
|
|
|
56 |
<Button type="submit">Enviar</Button>
|
|
|
57 |
<Button variant="danger" onClick={closeModal}>
|
|
|
58 |
Cancelar
|
|
|
59 |
</Button>
|
|
|
60 |
</Modal.Footer>
|
|
|
61 |
</form>
|
|
|
62 |
</Modal>
|
|
|
63 |
)
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
export default CreateGroupModal
|