Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 10836 | Rev 10842 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
10540 stevensc 1
/* eslint-disable no-mixed-spaces-and-tabs */
10513 stevensc 2
import axios from 'axios'
10518 stevensc 3
import React, { useState, useEffect } from 'react'
10513 stevensc 4
import { useForm } from 'react-hook-form'
5
import { useDispatch } from 'react-redux'
10450 stevensc 6
import { useHistory, useParams } from 'react-router-dom'
10513 stevensc 7
import { addNotification } from '../../../redux/notification/notification.actions'
10436 stevensc 8
 
10439 stevensc 9
 
10840 stevensc 10
const FormView = ({ actionLink, type_link }) => {
10513 stevensc 11
 
10558 stevensc 12
	// States
10840 stevensc 13
	const [typeOptions, setTypeOptions] = useState({
14
		url: type_link,
15
		value: ''
16
	})
10558 stevensc 17
	const [generalOptions, setGeneralOptions] = useState({
18
		uuid: '',
19
		name: '',
20
		description: '',
21
		functions: '',
22
		objectives: ''
23
	})
24
	const [pointsOptions, setPointsOptions] = useState([
25
		{ label: 'Evaluación', value: 0 },
26
		{ label: 'Sugerir otro cargo', value: 0 },
27
		{ label: '25%', value: 1 },
28
		{ label: '50%', value: 2 },
29
		{ label: '75%', value: 3 },
30
		{ label: '100%', value: 4 }
31
	])
32
	const [statusOptions, setStatusOptions] = useState([
33
		{ label: 'Estatus', value: '' },
34
		{ label: 'Aceptado', value: 'a' },
35
		{ label: 'Rechazado', value: 'r' }
36
	])
37
	const [vacancyOptions, setVacancyOptions] = useState([
38
		{ label: 'Estatus', value: '' },
39
		{ label: 'Aceptado', value: 'a' },
40
		{ label: 'Rechazado', value: 'r' }
41
	])
42
	const [candidatesOptions, setCandidatesOptions] = useState([
43
		{ label: 'Estatus', value: '' },
44
		{ label: 'Aceptado', value: 'a' },
45
		{ label: 'Rechazado', value: 'r' }
46
	])
47
	const [competencies, setCompetencies] = useState([])
10516 stevensc 48
 
10558 stevensc 49
	// Hooks
50
	const { setValue, register, watch } = useForm()
51
	const history = useHistory()
52
	const dispatch = useDispatch()
53
	const { action } = useParams()
10439 stevensc 54
 
10558 stevensc 55
	useEffect(() => {
10840 stevensc 56
		if (action === 'edit') {
57
			axios.get(actionLink)
58
				.then(({ data }) => {
59
					const resData = data.data
60
 
61
					if (!data.success) {
62
						dispatch(addNotification({
63
							style: 'error',
64
							msg: 'Ha ocurrido un error'
65
						}))
66
					}
67
 
68
					setValue('comment', resData.interview.comment)
69
					setValue('points', resData.interview.points)
70
					setValue('status', resData.interview.status)
71
					setCompetencies(resData.job_description.competencies)
72
					setCandidatesOptions({ label: `${resData.candidate.first_name} ${resData.candidate.last_name}`, value: resData.candidate.uuid })
73
					setVacancyOptions({ label: resData.vacancy.name, value: resData.vacancy.uuid })
74
					setTypeOptions({ ...typeOptions, value: resData.interview.type })
75
					setGeneralOptions({
76
						...generalOptions,
77
						name: resData.vacancy.name,
78
						uuid: resData.vacancy.uuid,
79
						description: resData.vacancy.description,
80
						functions: resData.job_description.functions,
81
						objectives: resData.job_description.objectives
82
					})
83
				})
84
		}
85
	}, [action])
86
 
87
	useEffect(() => {
88
		axios.get(typeOptions.url)
10753 stevensc 89
			.then(({ data }) => {
10513 stevensc 90
 
10753 stevensc 91
				if (!data.success) {
92
					dispatch(addNotification({
93
						style: 'error',
94
						msg: 'Ha ocurrido un error'
95
					}))
96
				}
10513 stevensc 97
 
10840 stevensc 98
				console.log(data.data)
10753 stevensc 99
			})
100
 
10840 stevensc 101
	}, [typeOptions.url])
10516 stevensc 102
 
10558 stevensc 103
	return (
104
		<section className="content">
105
			<div className="container-fluid">
106
				<div className="row">
107
					<div className="col-12">
108
						<div className='card'>
109
							<div className="card-header">
110
								<ul className="nav nav-tabs" id="myTab" role="tablist">
111
									<li className="nav-item" role="presentation">
112
										<button className="nav-link active" id="home-tab" data-toggle="tab" data-target="#home" type="button" role="tab" aria-controls="home" aria-selected="true">General</button>
113
									</li>
114
									<li className="nav-item" role="presentation">
115
										<button className="nav-link" id="profile-tab" data-toggle="tab" data-target="#profile" type="button" role="tab" aria-controls="profile" aria-selected="false">Competencias</button>
116
									</li>
117
									<li className="nav-item" role="presentation">
118
										<button className="nav-link" id="contact-tab" data-toggle="tab" data-target="#contact" type="button" role="tab" aria-controls="contact" aria-selected="false">Conclusiones</button>
119
									</li>
120
								</ul>
121
							</div>
122
							<div className="card-body">
123
								<div className="tab-content" id="myTabContent">
124
									<div className="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">
125
										<div className="row p-3 justify-content-between">
10569 stevensc 126
											<div className="col-6">
127
												<div className="form-group">
128
													<label>Vacantes</label>
10753 stevensc 129
													<select className='form-control' name='points' ref={register} disabled={action === 'edit'}>
10569 stevensc 130
														{
131
															vacancyOptions.map(({ label, value }) => (
132
																<option selected={generalOptions.name === label} key={value} value={value}>{label}</option>
133
															))
134
														}
135
													</select>
136
												</div>
10558 stevensc 137
											</div>
10569 stevensc 138
											<div className="col-6">
139
												<div className="form-group">
140
													<label>Candidatos</label>
10840 stevensc 141
													<select className='form-control' name='points' ref={register} disabled={action === 'edit'} onChange={(e) => setTypeOptions(prev => ({ ...prev, url: type_link.replace('UUID_PLACEHOLDER', e.target.value) }))}>
10569 stevensc 142
														{
143
															candidatesOptions.map(({ label, value }) => (
144
																<option selected={watch('candidate') === value} key={value} value={value}>{label}</option>
145
															))
146
														}
147
													</select>
148
												</div>
10558 stevensc 149
											</div>
150
										</div>
151
										<div className="card">
10840 stevensc 152
											<h5>{typeOptions.value === 'r' ? 'Recursos Humanos' : 'Potencial superior'}</h5>
10558 stevensc 153
											<div className="card-body">
154
												<h5>{generalOptions.name}</h5>
155
												<p>{generalOptions.description}</p>
156
												<h6>Funciones</h6>
157
												<p>{generalOptions.functions}</p>
158
												<h6>Objetivos</h6>
159
												<p>{generalOptions.objectives}</p>
160
											</div>
161
										</div>
162
									</div>
163
									<div className="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">
164
										{
10753 stevensc 165
											competencies.map((competency) => (
166
												<div className="card" key={competency.competency_uuid}>
167
													<div className="card-header">
168
														<h5>{competency.competency_name} - {competency.competency_type_name}</h5>
169
													</div>
170
													<div className="card-body">
171
														{
172
															competency.behaviors
173
															&&
174
															competency.behaviors.map((behavior) => (
175
																<table key={behavior.uuid} className="table table-hover">
176
																	<thead>
177
																		<tr>
178
																			<th style={{ width: '20%' }}>Conducta Observable</th>
179
																			<th style={{ width: '60%' }}>Comentario</th>
180
																			<th style={{ width: '20%' }}>Evaluación</th>
181
																		</tr>
182
																	</thead>
183
																	<tbody>
184
																		<tr>
185
																			<td style={{ width: '20%' }}>{behavior.description}</td>
186
																			<td style={{ width: '60%' }}>
187
																				<textarea
188
																					name={`${behavior.competency_uuid}_${behavior.uuid}-name`}
189
																					cols="30"
190
																					rows="3"
191
																					ref={register}
192
																					className='form-control w100'
193
																				/>
194
																			</td>
195
																			<td style={{ width: '20%' }}>
196
																				<select className='form-control' name={`${behavior.competency_uuid}_${behavior.uuid}-points`} ref={register}>
197
																					{
198
																						pointsOptions.map(({ label, value }) => (
199
																							<option selected={behavior.points === value} key={value} value={value}>{label}</option>
200
																						))
201
																					}
202
																				</select>
203
																			</td>
204
																		</tr>
205
																	</tbody>
206
																</table>
207
															))
208
														}
209
													</div>
210
												</div>
211
											))
10558 stevensc 212
										}
213
									</div>
214
									<div className="tab-pane fade" id="contact" role="tabpanel" aria-labelledby="contact-tab">
215
										<div className="form-group">
216
											<label>Comentario</label>
217
											<input type="text" name="comment" className="form-control" ref={register} />
218
										</div>
219
										<div className="form-group">
220
											<label>Evaluación</label>
221
											<select className='form-control' name='points' ref={register}>
222
												{
223
													pointsOptions.map(({ label, value }) => (
224
														<option selected={watch('points') === value} key={value} value={value}>{label}</option>
225
													))
226
												}
227
											</select>
228
										</div>
229
										<div className="form-group">
230
											<label>Estatus</label>
231
											<select className='form-control' name='status' ref={register}>
232
												{
233
													statusOptions.map(({ label, value }) => (
234
														<option selected={watch('status') === value} key={value} value={value}>{label}</option>
235
													))
236
												}
237
											</select>
238
										</div>
239
									</div>
240
								</div>
241
								<div className="form-group">
242
									<button type="submit" className="btn btn-primary btn-form-save-close mr-2">
10753 stevensc 243
										Guardar
10558 stevensc 244
									</button>
245
									<button
246
										type="button"
247
										className="btn btn-secondary btn-edit-cancel"
248
										onClick={() => history.goBack()}
249
									>
10753 stevensc 250
										Cancelar
10558 stevensc 251
									</button>
252
								</div>
253
							</div>
254
						</div>
255
					</div>
256
				</div>
257
			</div>
258
		</section >
259
	)
10436 stevensc 260
}
261
export default FormView