Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 15080 Rev 15102
Línea 1... Línea 1...
1
import axios from 'axios'
1
import axios from 'axios'
2
import React, { useEffect, useState } from 'react'
2
import React, { useEffect, useState } from 'react'
3
import parse from 'html-react-parser'
3
import parse from 'html-react-parser'
4
import { useForm } from 'react-hook-form'
4
import { useForm } from 'react-hook-form'
5
import { useDispatch } from 'react-redux'
5
import { useDispatch } from 'react-redux'
6
import { useHistory, useParams } from 'react-router-dom'
-
 
7
import { addNotification } from '../../../redux/notification/notification.actions'
6
import { addNotification } from '../../../redux/notification/notification.actions'
8
import DescriptionInput from '../../../shared/DescriptionInput'
-
 
9
import { CKEditor } from 'ckeditor4-react'
-
 
10
import { config } from '../../../shared/helpers/ckeditor_config'
-
 
Línea 11... Línea 7...
11
 
7
 
12
const levelOptions = {
8
const levelOptions = {
13
	'0': 'Cero',
9
	'0': 'Cero',
14
	'1': 'Uno',
10
	'1': 'Uno',
15
	'2': 'Dos',
11
	'2': 'Dos',
16
	'3': 'Tres',
12
	'3': 'Tres',
17
	'4': 'Cuatro',
13
	'4': 'Cuatro',
18
	'5': 'Cinco'
14
	'5': 'Cinco'
Línea 19... Línea 15...
19
}
15
}
-
 
16
 
-
 
17
const EditView = ({
-
 
18
	actionLink,
-
 
19
	jobsDescription,
Línea 20... Línea 20...
20
 
20
	action,
21
const EditView = ({ actionLink, jobsDescription }) => {
-
 
22
 
21
	setAction }) => {
23
	// Hooks
22
 
24
	const history = useHistory()
-
 
Línea 25... Línea 23...
25
	const { register, setValue, watch, reset } = useForm()
23
	// Hooks
26
	const dispatch = useDispatch()
24
	const { register, setValue, watch, reset } = useForm()
27
	const { action } = useParams()
25
	const dispatch = useDispatch()
28
 
26
 
Línea 70... Línea 68...
70
	}
68
	}
Línea 71... Línea 69...
71
 
69
 
72
	const submitAndClose = () => {
70
	const submitAndClose = () => {
73
		onSubmit()
71
		onSubmit()
74
		reset()
72
		reset()
75
		history.goBack()
73
		setAction('')
76
	}
-
 
77
/*
-
 
78
	useEffect(() => {
-
 
79
		register('description')
-
 
80
	}, [])
74
	}
81
*/
75
 
82
	useEffect(() => {
76
	useEffect(() => {
83
		if (action === 'edit') {
77
		if (action === 'edit') {
84
			axios.get(actionLink)
78
			axios.get(actionLink)
85
				.then(({ data }) => {
79
				.then(({ data }) => {
Línea 89... Línea 83...
89
							msg: 'Ha ocurrido un error'
83
							msg: 'Ha ocurrido un error'
90
						}))
84
						}))
91
					}
85
					}
Línea 92... Línea 86...
92
 
86
 
93
					setValue('name', data.data.name)
-
 
94
					//setDescription(data.data.description)
87
					setValue('name', data.data.name)
95
					setValue('description', data.data.description)
88
					setValue('description', parse(data.data.description))
96
					setStatus(data.data.status)
89
					setStatus(data.data.status)
97
					setCurretJobDescription(data.data.job_description_id)
90
					setCurretJobDescription(data.data.job_description_id)
98
					setValue('jobs_description', data.data.job_description_id)
91
					setValue('jobs_description', data.data.job_description_id)
99
				})
92
				})
100
		}
93
		}
Línea 101... Línea 94...
101
	}, [actionLink])
94
	}, [actionLink])
102
 
95
 
103
	useEffect(() => {
96
	useEffect(() => {
104
		if(currentJobDescription) {
97
		if (currentJobDescription) {
105
		
98
 
106
		axios.get(`/performance-evaluation/forms/job-decription?id=${currentJobDescription}`)
99
			axios.get(`/performance-evaluation/forms/job-decription?id=${currentJobDescription}`)
107
			.then(({ data }) => {
100
				.then(({ data }) => {
108
				if (!data.success) {
101
					if (!data.success) {
109
					return dispatch(addNotification({
102
						return dispatch(addNotification({
110
						style: 'danger',
103
							style: 'danger',
111
						msg: 'Ha ocurrido un error'
104
							msg: 'Ha ocurrido un error'
112
					}))
105
						}))
113
				}
106
					}
114
				let options = data.data.jobs_description?.map(description => ({ uuid: description.job_description_id, name: description.name }))
107
					let options = data.data.jobs_description?.map(description => ({ uuid: description.job_description_id, name: description.name }))
115
				setJobDescriptionOptions([...options, { name: data.data.name, uuid: data.data.uuid }])
108
					setJobDescriptionOptions([...options, { name: data.data.name, uuid: data.data.uuid }])
116
				setCompetenciesSelected(data.data.competencies_selected)
109
					setCompetenciesSelected(data.data.competencies_selected)
117
				setCompetencyTypes(data.data.competency_types)
110
					setCompetencyTypes(data.data.competency_types)
118
			})
111
				})
Línea 119... Línea 112...
119
		}
112
		}
120
	}, [currentJobDescription])
113
	}, [currentJobDescription])
121
 
114
 
122
	return (
115
	return (
123
		<section className="content">
116
		<section className="content">
124
			<div className="row" style={{ padding: 16 }}>
117
			<div className="row" style={{ padding: 16 }}>
-
 
118
				<div className="col-xs-12 col-md-12">
-
 
119
					<div className="form-group">
-
 
120
						<label>Nombre</label>
-
 
121
						<input
125
				<div className="col-xs-12 col-md-12">
122
							type="text"
126
					<div className="form-group">
123
							name="name"
127
						<label>Nombre</label>
124
							className='form-control'
128
						<input type="text" name="name" className='form-control' ref={register({ required: true, maxLength: 50 })} />
125
							ref={register({ required: true, maxLength: 50 })} />
-
 
126
					</div>
-
 
127
					<div className="form-group">
-
 
128
						<label>Cargo a evaluar</label>
129
					</div>
129
						<select
130
					<div className="form-group">
130
							name="job_description_id"
131
						<label>Cargo a evaluar</label>
-
 
132
						<select name="job_description_id" className="form-control" onChange={(e) => setCurretJobDescription(e.target.value)}>
131
							className="form-control"
133
							<option value=''>Seleccione</option>
132
							onChange={(e) => setCurretJobDescription(e.target.value)}>
134
							{
133
							<option value=''>Seleccione</option>
135
								jobDescriptionOptions.map(({ name, uuid }) => (
134
							{jobDescriptionOptions.map(({ name, uuid }) => (
136
									<option selected={uuid === currentJobDescription} key={uuid} value={uuid}>{name}</option>
135
								<option selected={uuid === currentJobDescription} key={uuid} value={uuid}>{name}</option>
137
								))
136
							))
138
							}
137
							}
139
						</select>
138
						</select>
-
 
139
					</div>
-
 
140
					<div className="form-group">
-
 
141
						<label htmlFor="form-description">Descripción</label>
-
 
142
						<textarea
-
 
143
							type="text"
-
 
144
							name="description"
140
					</div>
145
							rows="5"
141
					<div className="form-group">
-
 
142
						<label htmlFor="form-description">Descripción</label>
-
 
143
						<textarea type="text" name="description" rows="5" cols="50" className='form-control' ref={register({ required: true })} />
146
							cols="50"
144
 
147
							className='form-control'
145
						
148
							ref={register({ required: true })} />
146
					</div>
149
					</div>
147
					<div className="form-group">
150
					<div className="form-group">
Línea 160... Línea 163...
160
										<div className="col-xs-12 col-md-12">
163
										<div className="col-xs-12 col-md-12">
161
											<hr />
164
											<hr />
162
											<h4 style={{ fontSize: 18, fontWeight: 'bold' }}>Competencias asociadas al cargo:</h4>
165
											<h4 style={{ fontSize: 18, fontWeight: 'bold' }}>Competencias asociadas al cargo:</h4>
163
											<br />
166
											<br />
164
											<div className="panel-group" id="rows-job-competencies" >
167
											<div className="panel-group" id="rows-job-competencies" >
165
												{
-
 
166
													competencyTypes.length > 0
168
												{!!competencyTypes.length &&
167
													&&
-
 
168
													competenciesSelected.map((competency) => {
169
													competenciesSelected.map((competency) => {
169
														const type = competencyTypes.find((type) => type.competency_type_id === competency.competency_type_id)
170
														const type = competencyTypes.find((type) => type.competency_type_id === competency.competency_type_id)
Línea 170... Línea 171...
170
 
171
 
171
														return (
172
														return (
Línea 188... Línea 189...
188
																						<th style={{ width: '80%' }}>Conducta Observable</th>
189
																						<th style={{ width: '80%' }}>Conducta Observable</th>
189
																						<th style={{ width: '20%' }}>Nivel</th>
190
																						<th style={{ width: '20%' }}>Nivel</th>
190
																					</tr>
191
																					</tr>
191
																				</thead>
192
																				</thead>
192
																				<tbody>
193
																				<tbody>
193
																					{
-
 
194
																						competency.behaviors?.map(({ behavior_id, description, level }) => (
194
																					{competency.behaviors?.map(({ behavior_id, description, level }) => (
195
																							<tr key={behavior_id}>
195
																						<tr key={behavior_id}>
196
																								<td className="text-left">
196
																							<td className="text-left">
197
																									{description}
197
																								{description}
198
																								</td>
198
																							</td>
199
																								<td>
199
																							<td>
200
																									{levelOptions[level]}
200
																								{levelOptions[level]}
201
																								</td>
201
																							</td>
202
																							</tr>
202
																						</tr>
203
																						))
203
																					))
204
																					}
204
																					}
205
																				</tbody>
205
																				</tbody>
206
																			</table>
206
																			</table>
207
																		</div>
207
																		</div>
208
																	</div>
208
																	</div>
Línea 218... Línea 218...
218
							</div>
218
							</div>
219
						</div>
219
						</div>
220
					</div>
220
					</div>
221
					<div className="d-flex" style={{ gap: '5px' }}>
221
					<div className="d-flex" style={{ gap: '5px' }}>
222
						<button type="button" className="btn btn-primary" onClick={submitAndClose}>Guardar</button>
222
						<button type="button" className="btn btn-primary" onClick={submitAndClose}>Guardar</button>
223
						<button type="button" className="btn btn-secondary" onClick={() => history.goBack()}>Cancelar</button>
223
						<button type="button" className="btn btn-secondary" onClick={() => setAction('')}>Cancelar</button>
224
					</div>
224
					</div>
225
				</div>
225
				</div>
226
			</div >
226
			</div >
227
		</section >
227
		</section >