| 11049 |
stevensc |
1 |
import { Button, Modal } from 'react-bootstrap'
|
| 11046 |
stevensc |
2 |
import axios from 'axios'
|
|
|
3 |
import React from 'react'
|
|
|
4 |
import { useState } from 'react'
|
|
|
5 |
import { useForm } from 'react-hook-form'
|
|
|
6 |
import { useDispatch } from 'react-redux'
|
|
|
7 |
import { addNotification } from '../../../redux/notification/notification.actions'
|
|
|
8 |
import DescriptionInput from '../../../shared/DescriptionInput'
|
|
|
9 |
|
|
|
10 |
const AddModal = ({ closeModal, email_link, isOpen, add_link }) => {
|
|
|
11 |
|
|
|
12 |
//Hooks
|
| 11051 |
stevensc |
13 |
const { register, handleSubmit, watch, setError, errors, setValue, clearErrors } = useForm()
|
| 11046 |
stevensc |
14 |
const dispatch = useDispatch()
|
|
|
15 |
|
|
|
16 |
//States
|
|
|
17 |
const [isShowSecondPage, setIsShowSecondPage] = useState(false)
|
|
|
18 |
const [pointsOptions] = useState([
|
| 11065 |
stevensc |
19 |
{ label: 'Evaluación', value: 0 },
|
| 11046 |
stevensc |
20 |
{ label: 'Sugerir otro cargo', value: 0 },
|
|
|
21 |
{ label: '25%', value: 1 },
|
|
|
22 |
{ label: '50%', value: 2 },
|
|
|
23 |
{ label: '75%', value: 3 },
|
|
|
24 |
{ label: '100%', value: 4 }
|
|
|
25 |
])
|
|
|
26 |
const [statusOptions] = useState([
|
|
|
27 |
{ label: 'Estatus', value: '' },
|
|
|
28 |
{ label: 'Aceptado', value: 'a' },
|
|
|
29 |
{ label: 'Rechazado', value: 'r' }
|
|
|
30 |
])
|
|
|
31 |
|
|
|
32 |
const onSubmit = (data) => {
|
|
|
33 |
|
|
|
34 |
const submitData = new FormData()
|
|
|
35 |
Object.entries(data).map(([key, value]) => {
|
|
|
36 |
submitData.append(key, value)
|
|
|
37 |
})
|
|
|
38 |
|
|
|
39 |
axios.post(add_link, submitData)
|
|
|
40 |
.then(({ data }) => {
|
|
|
41 |
if (!data.success) {
|
| 11060 |
stevensc |
42 |
return dispatch(addNotification({
|
| 11051 |
stevensc |
43 |
style: 'danger',
|
| 11046 |
stevensc |
44 |
msg: 'Ha ocurrido un error'
|
|
|
45 |
}))
|
|
|
46 |
}
|
|
|
47 |
|
| 11051 |
stevensc |
48 |
clearErrors()
|
|
|
49 |
closeModal()
|
| 11061 |
stevensc |
50 |
setIsShowSecondPage(false)
|
| 11046 |
stevensc |
51 |
dispatch(addNotification({
|
|
|
52 |
style: 'success',
|
|
|
53 |
msg: 'Usuario registrado'
|
|
|
54 |
}))
|
|
|
55 |
})
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
const showSecondPage = () => {
|
|
|
59 |
if (watch('first_name') && watch('last_name') && watch('email')) {
|
|
|
60 |
return setIsShowSecondPage(true)
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
setError('first_name', { message: 'Este campo es requerido' })
|
|
|
64 |
setError('last_name', { message: 'Este campo es requerido' })
|
|
|
65 |
setError('email', { message: 'Este campo es requerido' })
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
const checkEmail = () => {
|
|
|
69 |
axios.get(email_link, { params: { email: watch('email') } })
|
|
|
70 |
.then(({ data }) => {
|
|
|
71 |
if (!data.success) {
|
|
|
72 |
dispatch(addNotification({
|
| 11051 |
stevensc |
73 |
style: 'danger',
|
| 11046 |
stevensc |
74 |
msg: 'Ha ocurrido un error'
|
|
|
75 |
}))
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
setValue('user_id', data.data.user_id)
|
| 11051 |
stevensc |
79 |
setValue('first_name', data.data.first_name)
|
|
|
80 |
setValue('last_name', data.data.last_name)
|
|
|
81 |
clearErrors()
|
| 11046 |
stevensc |
82 |
})
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
return (
|
| 11056 |
stevensc |
86 |
<Modal size="md" onHide={closeModal} show={isOpen}>
|
| 11046 |
stevensc |
87 |
<Modal.Header closeButton>
|
|
|
88 |
<Modal.Title>Nuevo candidato</Modal.Title>
|
|
|
89 |
</Modal.Header>
|
|
|
90 |
<form onSubmit={handleSubmit(onSubmit)}>
|
| 11053 |
stevensc |
91 |
<Modal.Body>
|
| 11059 |
stevensc |
92 |
<div style={isShowSecondPage ? { display: 'none' } : { display: 'block' }}>
|
| 11057 |
stevensc |
93 |
<div className='form-group'>
|
|
|
94 |
<label className="form-label">Correo electrónico</label>
|
|
|
95 |
<input type="email" name='email' className='form-control' ref={register({ required: true })} />
|
|
|
96 |
{errors.email && <p>{errors.email.message}</p>}
|
|
|
97 |
</div>
|
|
|
98 |
<button
|
|
|
99 |
type="button"
|
|
|
100 |
className="btn btn-primary"
|
|
|
101 |
onClick={checkEmail}
|
|
|
102 |
>
|
|
|
103 |
Verificar Email
|
|
|
104 |
</button>
|
|
|
105 |
<div className='form-group'>
|
|
|
106 |
<label className="form-label">Nombre</label>
|
|
|
107 |
<input type="text" name='first_name' className='form-control' ref={register({ required: true })} />
|
|
|
108 |
{errors.first_name && <p>{errors.first_name.message}</p>}
|
|
|
109 |
</div>
|
|
|
110 |
<div className='form-group'>
|
|
|
111 |
<label className="form-label">Apellido</label>
|
|
|
112 |
<input type="text" name='last_name' className='form-control' ref={register({ required: true })} />
|
|
|
113 |
{errors.last_name && <p>{errors.last_name.message}</p>}
|
|
|
114 |
</div>
|
| 11055 |
stevensc |
115 |
</div>
|
| 11059 |
stevensc |
116 |
<div style={isShowSecondPage ? { display: 'block' } : { display: 'none' }}>
|
| 11057 |
stevensc |
117 |
<div className='form-group'>
|
|
|
118 |
<label className="form-label">Comentario</label>
|
|
|
119 |
<DescriptionInput
|
| 11065 |
stevensc |
120 |
name='coment'
|
| 11057 |
stevensc |
121 |
setValue={setValue}
|
|
|
122 |
/>
|
| 11065 |
stevensc |
123 |
{errors.coment && <p>{errors.coment.message}</p>}
|
| 11057 |
stevensc |
124 |
</div>
|
|
|
125 |
<div className='form-group'>
|
|
|
126 |
<label className="form-label">Evaluación</label>
|
| 11070 |
stevensc |
127 |
<select className='form-control' name='evaluation' ref={register({ required: true })}>
|
| 11057 |
stevensc |
128 |
{
|
|
|
129 |
pointsOptions.map(({ label, value }) => {
|
|
|
130 |
return <option key={value} value={value}>{label}</option>
|
|
|
131 |
})
|
|
|
132 |
}
|
|
|
133 |
</select>
|
| 11071 |
stevensc |
134 |
{errors.evaluation && <p>{errors.evaluation.message}</p>}
|
| 11057 |
stevensc |
135 |
</div>
|
|
|
136 |
<div className='form-group'>
|
|
|
137 |
<label className="form-label">Resumen Curricular</label>
|
|
|
138 |
<input
|
|
|
139 |
className="form-control p-0"
|
|
|
140 |
type="file"
|
|
|
141 |
name="file"
|
|
|
142 |
accept='pdf/docx'
|
|
|
143 |
ref={register}
|
|
|
144 |
style={{ height: '2rem' }}
|
|
|
145 |
/>
|
|
|
146 |
</div>
|
|
|
147 |
<div className='form-group'>
|
|
|
148 |
<label className="form-label">Estatus</label>
|
| 11070 |
stevensc |
149 |
<select className='form-control' name='status' ref={register({ required: true })}>
|
| 11057 |
stevensc |
150 |
{
|
|
|
151 |
statusOptions.map(({ label, value }) => {
|
|
|
152 |
return <option key={value} value={value}>{label}</option>
|
|
|
153 |
})
|
|
|
154 |
}
|
|
|
155 |
</select>
|
| 11071 |
stevensc |
156 |
{errors.status && <p>{errors.status.message}</p>}
|
| 11057 |
stevensc |
157 |
</div>
|
| 11055 |
stevensc |
158 |
</div>
|
| 11053 |
stevensc |
159 |
</Modal.Body>
|
|
|
160 |
<Modal.Footer>
|
| 11060 |
stevensc |
161 |
<Button variant="primary" style={isShowSecondPage ? { display: 'none' } : { display: 'block' }} onClick={showSecondPage}>
|
| 11057 |
stevensc |
162 |
Siguiente
|
|
|
163 |
</Button>
|
| 11059 |
stevensc |
164 |
<Button variant="primary" type='submit' style={isShowSecondPage ? { display: 'block' } : { display: 'none' }}>
|
| 11057 |
stevensc |
165 |
Enviar
|
|
|
166 |
</Button>
|
| 11059 |
stevensc |
167 |
<Button variant="danger" onClick={() => setIsShowSecondPage(false)} style={isShowSecondPage ? { display: 'block' } : { display: 'none' }}>
|
| 11056 |
stevensc |
168 |
Cancelar
|
|
|
169 |
</Button>
|
| 11053 |
stevensc |
170 |
</Modal.Footer>
|
| 11046 |
stevensc |
171 |
</form>
|
|
|
172 |
</Modal >
|
|
|
173 |
)
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
export default AddModal
|