| 15761 |
stevensc |
1 |
/* eslint-disable react/prop-types */
|
|
|
2 |
import React, { useState } from 'react'
|
|
|
3 |
import { axios } from '../../../utils'
|
|
|
4 |
import { useForm } from 'react-hook-form'
|
|
|
5 |
import { Button, Modal } from 'react-bootstrap'
|
|
|
6 |
import styled from 'styled-components'
|
|
|
7 |
import FormErrorFeedback from '../../../shared/form-error-feedback/FormErrorFeedback'
|
|
|
8 |
import Spinner from '../../../shared/loading-spinner/Spinner'
|
|
|
9 |
|
|
|
10 |
const StyledSpinnerContainer = styled.div`
|
|
|
11 |
position: absolute;
|
|
|
12 |
left: 0;
|
|
|
13 |
top: 0;
|
|
|
14 |
width: 100%;
|
|
|
15 |
height: 100%;
|
|
|
16 |
background: rgba(255, 255, 255, 0.4);
|
|
|
17 |
display: flex;
|
|
|
18 |
justify-content: center;
|
|
|
19 |
align-items: center;
|
|
|
20 |
z-index: 300;
|
|
|
21 |
`
|
|
|
22 |
|
|
|
23 |
const CreateGroupModal = ({ closeModal, show }) => {
|
|
|
24 |
const [loading, setLoading] = useState(false)
|
|
|
25 |
const { register, errors, handleSubmit } = useForm()
|
|
|
26 |
|
|
|
27 |
const onSubmitHandler = async (data) => {
|
|
|
28 |
setLoading(true)
|
|
|
29 |
const formData = new FormData()
|
|
|
30 |
Object.entries(data).map(([key, value]) => formData.append(key, value))
|
|
|
31 |
|
|
|
32 |
await axios
|
|
|
33 |
.post('/chat/create-group', formData)
|
|
|
34 |
.then(({ data: response }) => {
|
|
|
35 |
if (response.success) closeModal()
|
|
|
36 |
})
|
|
|
37 |
|
|
|
38 |
setLoading(false)
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
return (
|
|
|
42 |
<Modal show={show} onHide={closeModal}>
|
|
|
43 |
<Modal.Header closeButton>
|
|
|
44 |
<Modal.Title>Crear grupo</Modal.Title>
|
|
|
45 |
</Modal.Header>
|
|
|
46 |
<form onSubmit={handleSubmit(onSubmitHandler)}>
|
|
|
47 |
<Modal.Body>
|
|
|
48 |
<label className="mb-1" htmlFor="name">Nombre del grupo</label>
|
|
|
49 |
<input
|
|
|
50 |
type="text"
|
|
|
51 |
name="name"
|
|
|
52 |
id="name"
|
|
|
53 |
ref={register({
|
|
|
54 |
required: 'Este campo es requerido'
|
|
|
55 |
})}
|
|
|
56 |
/>
|
|
|
57 |
{errors.name && <FormErrorFeedback>{errors.name.message}</FormErrorFeedback>}
|
|
|
58 |
{loading &&
|
|
|
59 |
<StyledSpinnerContainer>
|
|
|
60 |
<Spinner />
|
|
|
61 |
</StyledSpinnerContainer>
|
|
|
62 |
}
|
|
|
63 |
</Modal.Body>
|
|
|
64 |
<Modal.Footer>
|
|
|
65 |
<Button type="submit">Enviar</Button>
|
|
|
66 |
<Button variant="danger" onClick={closeModal}>
|
|
|
67 |
Cancelar
|
|
|
68 |
</Button>
|
|
|
69 |
</Modal.Footer>
|
|
|
70 |
</form>
|
|
|
71 |
</Modal>
|
|
|
72 |
)
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
export default CreateGroupModal
|