| 6952 |
stevensc |
1 |
import React, { useState } from 'react'
|
|
|
2 |
import { useForm } from 'react-hook-form'
|
|
|
3 |
import { useDispatch, useSelector } from 'react-redux'
|
|
|
4 |
import { axios } from '../../utils'
|
|
|
5 |
import { addNotification } from '../../redux/notification/notification.actions'
|
|
|
6 |
import { Modal } from 'react-bootstrap'
|
|
|
7 |
import Datetime from 'react-datetime'
|
|
|
8 |
import FormErrorFeedback from '../UI/FormErrorFeedback'
|
|
|
9 |
import useFetchHelper from '../../hooks/useFetchHelper'
|
| 7317 |
stevensc |
10 |
import 'react-datetime/css/react-datetime.css'
|
| 6952 |
stevensc |
11 |
|
|
|
12 |
const ConferenceModal = ({
|
|
|
13 |
show = false,
|
|
|
14 |
zoomUrl = '',
|
| 6954 |
stevensc |
15 |
onClose = () => null,
|
| 6952 |
stevensc |
16 |
}) => {
|
|
|
17 |
const dt = new Date()
|
|
|
18 |
const [date, setDate] = useState({
|
|
|
19 |
year: dt.toLocaleString('default', { year: 'numeric' }),
|
|
|
20 |
month: dt.toLocaleString('default', { month: '2-digit' }),
|
|
|
21 |
day: dt.toLocaleString('default', { day: '2-digit' }),
|
|
|
22 |
})
|
|
|
23 |
const [time, setTime] = useState(
|
|
|
24 |
dt.toLocaleString('es', {
|
|
|
25 |
hour: 'numeric',
|
|
|
26 |
minute: '2-digit',
|
|
|
27 |
second: '2-digit',
|
|
|
28 |
})
|
|
|
29 |
)
|
| 6955 |
stevensc |
30 |
const { data: timezones } = useFetchHelper('timezones')
|
| 6952 |
stevensc |
31 |
const labels = useSelector(({ intl }) => intl.labels)
|
|
|
32 |
const dispatch = useDispatch()
|
|
|
33 |
|
|
|
34 |
const { handleSubmit, register, errors, reset, getValues } = useForm({
|
|
|
35 |
mode: 'all',
|
|
|
36 |
})
|
|
|
37 |
|
|
|
38 |
const handleDateTime = (value) => {
|
|
|
39 |
setDate({
|
|
|
40 |
...date,
|
|
|
41 |
year: new Intl.DateTimeFormat('es', { year: 'numeric' }).format(value),
|
|
|
42 |
month: new Intl.DateTimeFormat('es', { month: '2-digit' }).format(value),
|
|
|
43 |
day: new Intl.DateTimeFormat('es', { day: '2-digit' }).format(value),
|
|
|
44 |
})
|
|
|
45 |
setTime(
|
|
|
46 |
new Intl.DateTimeFormat('es', {
|
|
|
47 |
hour: 'numeric',
|
|
|
48 |
minute: '2-digit',
|
|
|
49 |
second: 'numeric',
|
|
|
50 |
}).format(value)
|
|
|
51 |
)
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
const onSubmit = handleSubmit(async (data) => {
|
|
|
55 |
try {
|
|
|
56 |
const formData = new FormData()
|
|
|
57 |
|
|
|
58 |
Object.entries(data).forEach(([key, value]) =>
|
|
|
59 |
formData.append(key, value)
|
|
|
60 |
)
|
|
|
61 |
|
|
|
62 |
formData.append('date', `${date.year}-${date.month}-${date.day}`)
|
|
|
63 |
formData.append('time', time)
|
|
|
64 |
|
|
|
65 |
const { data: response } = await axios.post(zoomUrl, formData)
|
|
|
66 |
|
|
|
67 |
if (!response.success && typeof response.data === 'string') {
|
|
|
68 |
dispatch(addNotification({ msg: response.data, style: 'danger' }))
|
|
|
69 |
return
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
if (!response.success && typeof response.data === 'object') {
|
|
|
73 |
Object.entries(response.data).forEach(([key, value]) => {
|
|
|
74 |
dispatch(
|
|
|
75 |
addNotification({ msg: `${key}: ${value[0]}`, style: 'danger' })
|
|
|
76 |
)
|
|
|
77 |
})
|
|
|
78 |
return
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
dispatch(addNotification({ msg: response.data, style: 'success' }))
|
| 6954 |
stevensc |
82 |
onClose()
|
| 6952 |
stevensc |
83 |
reset()
|
|
|
84 |
} catch (error) {
|
|
|
85 |
console.log(`Error: ${error}`)
|
|
|
86 |
dispatch(
|
|
|
87 |
addNotification({ msg: 'Ha ocurrido un error', style: 'danger' })
|
|
|
88 |
)
|
|
|
89 |
throw new Error(error)
|
|
|
90 |
}
|
|
|
91 |
})
|
|
|
92 |
|
|
|
93 |
return (
|
| 6954 |
stevensc |
94 |
<Modal show={show} onHide={onClose}>
|
|
|
95 |
<Modal.Header closeButton>
|
| 6952 |
stevensc |
96 |
<Modal.Title>{labels.create_conference}</Modal.Title>
|
|
|
97 |
</Modal.Header>
|
| 6954 |
stevensc |
98 |
<Modal.Body>
|
|
|
99 |
<form onSubmit={onSubmit} autoComplete="new-password">
|
|
|
100 |
<div className="form-group">
|
|
|
101 |
<label htmlFor="first_name">Título</label>
|
|
|
102 |
<input
|
|
|
103 |
type="text"
|
|
|
104 |
name="title"
|
|
|
105 |
className="form-control"
|
|
|
106 |
maxLength={128}
|
|
|
107 |
ref={register({ required: 'Por favor ingrese un título' })}
|
|
|
108 |
/>
|
|
|
109 |
{errors.title && (
|
|
|
110 |
<FormErrorFeedback>{errors.title.message}</FormErrorFeedback>
|
|
|
111 |
)}
|
|
|
112 |
</div>
|
|
|
113 |
<div className="form-group">
|
|
|
114 |
<label htmlFor="first_name">Descripción</label>
|
|
|
115 |
<input
|
|
|
116 |
type="text"
|
|
|
117 |
name="description"
|
|
|
118 |
className="form-control"
|
|
|
119 |
ref={register({ required: 'Por favor ingrese una descripción' })}
|
|
|
120 |
/>
|
|
|
121 |
{errors.description && (
|
|
|
122 |
<FormErrorFeedback>
|
|
|
123 |
{errors.description.message}
|
|
|
124 |
</FormErrorFeedback>
|
|
|
125 |
)}
|
|
|
126 |
</div>
|
|
|
127 |
<div className="form-group">
|
|
|
128 |
<label htmlFor="timezone">Tipo de conferencia</label>
|
|
|
129 |
<select name="type" className="form-control" ref={register}>
|
|
|
130 |
<option value="i">Inmediata</option>
|
|
|
131 |
<option value="s">Programada</option>
|
|
|
132 |
</select>
|
|
|
133 |
</div>
|
|
|
134 |
{getValues('type') === 's' && (
|
|
|
135 |
<div className="form-group">
|
|
|
136 |
<label htmlFor="timezone">Horario</label>
|
|
|
137 |
<Datetime
|
|
|
138 |
dateFormat="DD-MM-YYYY"
|
|
|
139 |
onChange={(e) => {
|
|
|
140 |
if (e.toDate) {
|
|
|
141 |
handleDateTime(e.toDate())
|
|
|
142 |
}
|
|
|
143 |
}}
|
|
|
144 |
inputProps={{ className: 'form-control' }}
|
|
|
145 |
initialValue={Date.parse(new Date())}
|
|
|
146 |
closeOnSelect
|
|
|
147 |
/>
|
|
|
148 |
</div>
|
| 6952 |
stevensc |
149 |
)}
|
|
|
150 |
<div className="form-group">
|
| 6954 |
stevensc |
151 |
<label htmlFor="timezone">Zona horaria</label>
|
|
|
152 |
<select
|
|
|
153 |
className="form-control"
|
|
|
154 |
name="timezone"
|
|
|
155 |
ref={register({ required: 'Por favor elige una Zona horaria' })}
|
|
|
156 |
>
|
|
|
157 |
<option value="" hidden>
|
|
|
158 |
Zona horaria
|
|
|
159 |
</option>
|
| 6955 |
stevensc |
160 |
{timezones.map(({ name, value }) => (
|
|
|
161 |
<option value={value} key={value}>
|
|
|
162 |
{name}
|
| 6954 |
stevensc |
163 |
</option>
|
|
|
164 |
))}
|
|
|
165 |
</select>
|
|
|
166 |
{errors.timezone && (
|
|
|
167 |
<FormErrorFeedback>{errors.timezone.message}</FormErrorFeedback>
|
|
|
168 |
)}
|
|
|
169 |
</div>
|
|
|
170 |
<div className="form-group">
|
|
|
171 |
<label htmlFor="timezone">Duración</label>
|
|
|
172 |
<select className="form-control" name="duration" ref={register}>
|
|
|
173 |
<option value={5}>5-min</option>
|
|
|
174 |
<option value={10}>10-min</option>
|
|
|
175 |
<option value={15}>15-min</option>
|
|
|
176 |
<option value={20}>20-min</option>
|
|
|
177 |
<option value={25}>25-min</option>
|
|
|
178 |
<option value={30}>30-min</option>
|
|
|
179 |
<option value={35}>35-min</option>
|
|
|
180 |
<option value={40}>40-min</option>
|
|
|
181 |
<option value={45}>45-min</option>
|
|
|
182 |
</select>
|
|
|
183 |
</div>
|
|
|
184 |
<div className="form-group">
|
|
|
185 |
<label htmlFor="first_name">Contraseña de ingreso</label>
|
|
|
186 |
<input
|
|
|
187 |
type="password"
|
|
|
188 |
name="password"
|
|
|
189 |
className="form-control"
|
|
|
190 |
ref={register({
|
|
|
191 |
required: 'Por favor ingrese una contraseña',
|
|
|
192 |
maxLength: {
|
|
|
193 |
value: 6,
|
|
|
194 |
message: 'La contraseña debe tener al menos 6 digitos',
|
|
|
195 |
},
|
|
|
196 |
})}
|
| 6952 |
stevensc |
197 |
/>
|
| 6954 |
stevensc |
198 |
{errors.password && (
|
|
|
199 |
<FormErrorFeedback>{errors.password.message}</FormErrorFeedback>
|
|
|
200 |
)}
|
| 6952 |
stevensc |
201 |
</div>
|
| 6954 |
stevensc |
202 |
<button className="btn btn-primary" type="submit">
|
|
|
203 |
Crear
|
|
|
204 |
</button>
|
|
|
205 |
</form>
|
|
|
206 |
</Modal.Body>
|
| 6952 |
stevensc |
207 |
</Modal>
|
|
|
208 |
)
|
|
|
209 |
}
|
|
|
210 |
|
|
|
211 |
export default ConferenceModal
|