Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 14245 | Rev 14247 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 14245 Rev 14246
Línea 17... Línea 17...
17
 
17
 
18
	// Hooks
18
	// Hooks
19
	const dispatch = useDispatch()
19
	const dispatch = useDispatch()
20
	const history = useHistory()
20
	const history = useHistory()
-
 
21
	const selectInput = useRef(null)
21
	const selectInput = useRef(null)
22
	const selectInput2 = useRef(null)
22
	const { action } = useParams()
23
	const { action } = useParams()
23
	const {
24
	const {
24
		setValue,
25
		setValue,
25
		register,
26
		register,
Línea 32... Línea 33...
32
	const [initObjectives, setInitObjectives] = useState('')
33
	const [initObjectives, setInitObjectives] = useState('')
33
	const [initFunctions, setInitFunctions] = useState('')
34
	const [initFunctions, setInitFunctions] = useState('')
34
	const [competencyOptions, setCompetencyOptions] = useState([])
35
	const [competencyOptions, setCompetencyOptions] = useState([])
35
	const [competenciesSelected, setCompetenciesSelected] = useState([])
36
	const [competenciesSelected, setCompetenciesSelected] = useState([])
36
	const [competencyTypeOptions, setCompetencyTypeOptions] = useState([])
37
	const [competencyTypeOptions, setCompetencyTypeOptions] = useState([])
-
 
38
	const [jobsDescription, setJobsDescription] = useState([])
-
 
39
	const [subordinatesSelected, setSubordinatesSelected] = useState([])
Línea 37... Línea 40...
37
 
40
 
Línea 38... Línea 41...
38
	const onSubmit = () => {
41
	const onSubmit = () => {
39
 
42
 
Línea 70... Línea 73...
70
					msg: `Registro ${action === 'edit' ? 'actualizado' : 'añadido'}`
73
					msg: `Registro ${action === 'edit' ? 'actualizado' : 'añadido'}`
71
				}))
74
				}))
72
			})
75
			})
73
	}
76
	}
Línea 74... Línea 77...
74
 
77
 
75
	const àddCompetencies = () => {
78
	const addCompetencies = () => {
-
 
79
		const current_competency = competencyOptions.find(competency => competency.competency_id === selectInput.current.value)
76
		const current_competency = competencyOptions.find(competency => competency.competency_id === selectInput.current.value)
80
		const filterCompetencies = new Set([current_competency, ...competenciesSelected])
-
 
81
		setCompetenciesSelected([...filterCompetencies])
-
 
82
	}
-
 
83
 
-
 
84
	const addSubordinates = () => {
-
 
85
		const current_subordinate = jobsDescription.find(subordinate => subordinate.job_description_id === selectInput2.current.value)
-
 
86
		const filterSubordinate = new Set([current_subordinate, ...subordinatesSelected])
77
		setCompetenciesSelected(prev => [current_competency, ...prev])
87
		setCompetenciesSelected([...filterSubordinate])
Línea 78... Línea 88...
78
	}
88
	}
79
 
89
 
80
	const deleteCompetency = (id) => {
90
	const deleteCompetency = (id) => {
Línea -... Línea 91...
-
 
91
		setCompetenciesSelected(competenciesSelected.filter(competency => competency.competency_id !== id))
-
 
92
	}
-
 
93
 
-
 
94
	const deleteSubordinate = (id) => {
81
		setCompetenciesSelected(competenciesSelected.filter(competency => competency.competency_id !== id))
95
		setSubordinatesSelected(subordinatesSelected.filter(subordinate => subordinate.job_description_id !== id))
82
	}
96
	}
83
 
97
 
84
	useEffect(() => {
98
	useEffect(() => {
85
		register('status')
99
		register('status')
Línea 95... Línea 109...
95
						style: 'danger',
109
						style: 'danger',
96
						msg: 'Ha ocurrido un error'
110
						msg: 'Ha ocurrido un error'
97
					}))
111
					}))
98
				}
112
				}
Línea 99... Línea 113...
99
 
113
 
100
				setSupervisers(data.data['jobs_description'].map(option => {
-
 
101
					return {
-
 
102
						key: option.name,
114
				setSupervisers(data.data['supervisers'].map(option => ({ key: option.name, value: option.uuid })))
103
						value: option.job_description_id
115
				setJobsDescription(data.data['jobs_description'].map(option => ({ key: option.name, value: option.job_description_id })))
104
					}
-
 
105
				}))
116
 
106
				setInitObjectives(data.data['objectives'])
117
				setInitObjectives(data.data['objectives'])
-
 
118
				setInitFunctions(data.data['functions'])
107
				setInitFunctions(data.data['functions'])
119
 
108
				setCompetencyOptions(data.data['competencies'])
120
				setCompetencyOptions(data.data['competencies'])
-
 
121
				setCompetencyTypeOptions(data.data['competency_types'])
109
				setCompetencyTypeOptions(data.data['competency_types'])
122
 
-
 
123
				setCompetenciesSelected(data.data['competencies_selected'])
Línea 110... Línea 124...
110
				setCompetenciesSelected(data.data['competencies_selected'])
124
				setSubordinatesSelected(data.data['subordinates_selected'])
111
 
125
 
112
				setValue('name', data.data['name'])
126
				setValue('name', data.data['name'])
Línea 224... Línea 238...
224
													</div>
238
													</div>
225
													<div className='col-3'>
239
													<div className='col-3'>
226
														<button
240
														<button
227
															type='button'
241
															type='button'
228
															className='btn btn-primary'
242
															className='btn btn-primary'
229
															onClick={àddCompetencies}
243
															onClick={addCompetencies}
230
														>
244
														>
231
															Agregar Competencia
245
															Agregar Competencia
232
														</button>
246
														</button>
233
													</div>
247
													</div>
234
												</div>
248
												</div>
Línea 278... Línea 292...
278
																					</td>
292
																					</td>
279
																					<td>
293
																					<td>
280
																						<button
294
																						<button
281
																							type='button'
295
																							type='button'
282
																							className='btn btn-primary'
296
																							className='btn btn-primary'
283
																							onClick={() => deleteCompetency(competency_selected.competency_id)}
297
																							onClick={() => deleteSubordinate(competency_selected.competency_id)}
284
																						>
298
																						>
285
																							<i className='fa fa-edit mr-1' />
299
																							<i className='fa fa-edit mr-1' />
286
																							Editar Perfil
300
																							Editar Perfil
287
																						</button>
301
																						</button>
288
																					</td>
302
																					</td>
Línea 299... Línea 313...
299
										</div>
313
										</div>
300
										<div className="tab-pane fade" id="contact" role="tabpanel" aria-labelledby="contact-tab">
314
										<div className="tab-pane fade" id="contact" role="tabpanel" aria-labelledby="contact-tab">
301
											<div className="card p-2">
315
											<div className="card p-2">
302
												<div className="d-flex justify-content-around">
316
												<div className="d-flex justify-content-around">
303
													<div className="col-9">
317
													<div className="col-9">
304
														<select className='form-control' name="job_description_id_boss" ref={selectInput}>
318
														<select className='form-control' name="job_description_id_boss" ref={selectInput2}>
305
															<option value="">Seleccione</option>
319
															<option value="">Seleccione</option>
306
															{
320
															{
307
																competencyOptions.map((competency) => {
321
																jobsDescription.map(({ key, value }) =>
308
																	const competency_type = competencyTypeOptions.find(type => type.competency_type_id === competency.competency_type_id)
-
 
309
 
-
 
310
																	return (
-
 
311
																		<option
-
 
312
																			key={competency.competency_id}
-
 
313
																			value={competency.competency_id}>
322
																	<option key={value} value={value}>{key}</option>
314
																			{`${competency_type?.name} - ${competency.name}`}
-
 
315
																		</option>
-
 
316
																	)
-
 
317
																})
323
																)
318
															}
324
															}
319
														</select>
325
														</select>
320
													</div>
326
													</div>
321
													<div className='col-3'>
327
													<div className='col-3'>
322
														<button
328
														<button
323
															type='button'
329
															type='button'
324
															className='btn btn-primary'
330
															className='btn btn-primary'
325
															onClick={àddCompetencies}
331
															onClick={addSubordinates}
326
														>
332
														>
327
															Agregar Competencia
333
															Agregar
328
														</button>
334
														</button>
329
													</div>
335
													</div>
330
												</div>
336
												</div>
331
												{
337
												{
332
													competenciesSelected.map(competency_selected => {
338
													subordinatesSelected.map(subordinate => {
333
														const competency_type = competencyTypeOptions.find(type => type.competency_type_id === competency_selected.competency_type_id)
-
 
Línea 334... Línea 339...
334
 
339
 
335
														return (
340
														return (
336
															<div key={competency_selected.competency_type_id}>
-
 
337
																<h3 className='my-2'>{`${competency_type.name} - ${competency_selected.name}`}</h3>
341
															<div key={subordinate.job_description_id}>
338
																<table className='table table-bordered'>
342
																<table className='table table-bordered'>
339
																	<thead>
343
																	<thead>
340
																		<tr>
344
																		<tr>
341
																			<th>Nombre</th>
345
																			<th>Nombre</th>
342
																			<th>Acciones</th>
346
																			<th>Acciones</th>
343
																		</tr>
347
																		</tr>
344
																	</thead>
348
																	</thead>
345
																	<tbody>
349
																	<tbody>
346
																		<tr>
350
																		<tr>
347
																			<td>{competency_selected.name}</td>
351
																			<td>{subordinate.name}</td>
348
																			<td>
352
																			<td>
349
																				<button
353
																				<button
350
																					type='button'
354
																					type='button'
351
																					className='btn btn-primary'
355
																					className='btn btn-primary'
352
																					onClick={() => deleteCompetency(competency_selected.competency_id)}
356
																					onClick={() => deleteCompetency(subordinate.job_description_id)}
353
																				>
357
																				>
354
																					<i className='fa fa-ban mr-1' />
358
																					<i className='fa fa-ban mr-1' />
355
																					Borrar
359
																					Borrar
356
																				</button>
360
																				</button>