Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev Autor Línea Nro. Línea
12040 stevensc 1
import axios from 'axios'
2
import React, { useEffect, useState } from 'react'
3
import { useForm } from 'react-hook-form'
4
import { useDispatch } from 'react-redux'
5
import { addNotification } from '../../../redux/notification/notification.actions'
6
import DescriptionInput from '../../../shared/DescriptionInput'
12012 stevensc 7
 
12081 stevensc 8
const levelOptions = {
9
	'1': 'Uno',
10
	'2': 'Dos',
11
	'3': 'Tres',
12
	'4': 'Cuatro',
13
	'5': 'Cinco'
14
}
15
 
12040 stevensc 16
const EditView = ({ actionLink }) => {
17
 
18
	const { register, handleSubmit, setValue, watch } = useForm()
12047 stevensc 19
	const [currentJobDescription, setCurretJobDescription] = useState('')
20
	const [jobDescriptionOptions, setJobDescriptionOptions] = useState([])
12081 stevensc 21
	const [competencyTypes, setCompetencyTypes] = useState([])
22
	const [competenciesSelected, setCompetenciesSelected] = useState([])
12047 stevensc 23
	const [status, setStatus] = useState('a')
12040 stevensc 24
	const dispatch = useDispatch()
25
 
26
	useEffect(() => {
27
		register('description')
28
	}, [])
29
 
30
	useEffect(() => {
31
		axios.get(actionLink)
32
			.then(({ data }) => {
33
				if (!data.success) {
34
					return dispatch(addNotification({
35
						style: 'danger',
36
						msg: 'Ha ocurrido un error'
37
					}))
38
				}
39
 
40
				setValue('name', data.data.name)
41
				setValue('description', data.data.description)
42
				setCurretJobDescription(data.data.job_description_id)
43
				setStatus(data.data.status)
44
			})
45
	}, [actionLink])
46
 
47
	useEffect(() => {
48
		axios.get(`/settings/jobs-description/edit/${currentJobDescription}`)
49
			.then(({ data }) => {
50
				if (!data.success) {
51
					return dispatch(addNotification({
52
						style: 'danger',
53
						msg: 'Ha ocurrido un error'
54
					}))
55
				}
56
 
12047 stevensc 57
				setJobDescriptionOptions([...data.data.jobs_description, { job_description_id: data.data.uuid, name: data.data.name }])
12081 stevensc 58
				setCompetenciesSelected(data.data.competencies_selected)
59
				setCompetencyTypes(data.data.competency_types)
12040 stevensc 60
			})
61
	}, [currentJobDescription])
62
 
12012 stevensc 63
	return (
12040 stevensc 64
		<section className="content">
65
			<div className="row" style={{ padding: 16 }}>
66
				<div className="col-xs-12 col-md-12">
67
					<form onSubmit={handleSubmit}>
68
						<div className="form-group">
12081 stevensc 69
							<label>Nombre</label>
70
							<input type="text" name="name" className='form-control' ref={register({ required: true, maxLength: 50 })} />
12040 stevensc 71
						</div>
72
						<div className="form-group">
73
							<label>Cargo a evaluar</label>
12081 stevensc 74
							<select name="job_description_id" ref={register({ required: true })} className="form-control">
12040 stevensc 75
								{
76
									jobDescriptionOptions.map(({ name, job_description_id }) => (
77
										<option selected={job_description_id === currentJobDescription} key={job_description_id} value={job_description_id}>{name}</option>
78
									))
79
								}
80
							</select>
81
						</div>
82
						<div className="form-group">
83
							<label htmlFor="form-description">Descripción</label>
84
							<DescriptionInput
85
								defaultValue={watch('description')}
86
								name='description'
87
								onChange={setValue}
88
							/>
89
						</div>
90
						<div className="form-group">
91
							<label htmlFor="form-status">Estatus</label>
92
							<select name="form-status" className="form-control">
93
								<option selected={status === 'i'} value="i">Inactivo</option>
94
								<option selected={status === 'a'} value="a">Activo</option>
95
							</select>
96
						</div>
97
						<br />
98
						<div className="row">
99
							<div className="col-xs-12 col-md-12">
100
								<div className="panel-group" id="rows" />
101
							</div>
102
						</div>
103
						<div className="form-group" id="competencies-to-job" style={{}}>
104
							<div className="row">
105
								<div className="col-xs-12 col-md-12">
106
									<hr />
107
									<h4 style={{ fontSize: 18, fontWeight: 'bold' }}>Competencias asociadas al cargo:</h4>
108
									<br />
12081 stevensc 109
									<div className="panel-group" id="rows-job-competencies" >
110
										{
12084 stevensc 111
											competencyTypes.length > 0
112
											&&
12082 stevensc 113
											competenciesSelected.map((competency) => {
114
												const type = competencyTypes.find((type) => type.competency_type_id === competency.competency_type_id)
12083 stevensc 115
 
12081 stevensc 116
												return (
12085 stevensc 117
													<div key={competency.competency_id} className="panel panel-default" id={`panel-${competency.competency_id}`}>
12081 stevensc 118
														<div className="panel-heading">
119
															<h4 className="panel-title" style={{ fontSize: 18 }}>
12085 stevensc 120
																<a className="accordion-toggle" data-toggle="collapse" aria-expanded="true" data-parent={`#panel-${competency.competency_id}`} href={`#collapse-${competency.competency_id}`}>
121
																	<span className={`competency-name${competency.competency_id}`}>
12084 stevensc 122
																		{`${type.name} - ${competency.name}`}
12081 stevensc 123
																	</span>
124
																</a>
125
															</h4>
126
														</div>
12085 stevensc 127
														<div id={`collapse-${competency.competency_id}`} className="panel-collapse in collapse show">
12081 stevensc 128
															<div className="panel-body">
129
																<div className="table-responsive">
130
																	<table className="table table-bordered">
131
																		<thead>
132
																			<tr>
133
																				<th style={{ width: '80%' }}>Conducta Observable</th>
134
																				<th style={{ width: '20%' }}>Nivel</th>
135
																			</tr>
136
																		</thead>
137
																		<tbody>
138
																			{
12082 stevensc 139
																				competency.behaviors?.map(({ behavior_id, description, level }) => (
12081 stevensc 140
																					<tr key={behavior_id}>
141
																						<td className="text-left">
142
																							{description}
143
																						</td>
144
																						<td>
145
																							{levelOptions[level]}
146
																						</td>
147
																					</tr>
148
																				))
149
																			}
150
																		</tbody>
151
																	</table>
152
																</div>
153
															</div>
154
														</div>
12040 stevensc 155
													</div>
12081 stevensc 156
												)
157
											})
158
										}
12040 stevensc 159
									</div>
160
								</div>
161
							</div>
162
						</div>
163
						<div className="form-group">
164
							<button type="button" form="form-main" className="btn btn-info">Guardar & Continuar</button>
165
							<button type="button" className="btn btn-primary">Guardar & Cerrar</button>
166
							<button type="button" className="btn btn-secondary">Cancelar</button>
167
						</div>
168
					</form>
169
				</div>
12081 stevensc 170
			</div >
171
		</section >
12040 stevensc 172
 
12012 stevensc 173
	)
174
}
175
 
176
export default EditView