12289 |
stevensc |
1 |
/* eslint-disable no-mixed-spaces-and-tabs */
|
|
|
2 |
import axios from 'axios'
|
|
|
3 |
import React, { useState, useEffect } from 'react'
|
|
|
4 |
import { useForm } from 'react-hook-form'
|
|
|
5 |
import { useDispatch } from 'react-redux'
|
|
|
6 |
import { useHistory, useParams } from 'react-router-dom'
|
|
|
7 |
import { addNotification } from '../../../redux/notification/notification.actions'
|
|
|
8 |
|
|
|
9 |
const pointsOptions = [
|
|
|
10 |
{ label: 'Sugerir otro cargo', value: 0 },
|
|
|
11 |
{ label: '25%', value: 1 },
|
|
|
12 |
{ label: '50%', value: 2 },
|
|
|
13 |
{ label: '75%', value: 3 },
|
|
|
14 |
{ label: '100%', value: 4 }
|
|
|
15 |
]
|
|
|
16 |
|
|
|
17 |
const EvaluationView = ({ actionLink, setActionLink }) => {
|
|
|
18 |
|
|
|
19 |
// Hooks
|
|
|
20 |
const dispatch = useDispatch()
|
12291 |
stevensc |
21 |
const history = useHistory()
|
12289 |
stevensc |
22 |
const { action } = useParams()
|
|
|
23 |
const { setValue, register, watch, handleSubmit } = useForm()
|
|
|
24 |
|
|
|
25 |
//States
|
|
|
26 |
const [jobDescription, setJobDescription] = useState({})
|
|
|
27 |
|
|
|
28 |
const onSubmit = () => {
|
|
|
29 |
|
|
|
30 |
const content = []
|
|
|
31 |
jobDescription.competencies.forEach(competency => competency.behaviors.forEach(behavior => {
|
|
|
32 |
content.push({
|
12301 |
stevensc |
33 |
competencyUuid: behavior.competency_uuid,
|
|
|
34 |
behaviorUuid: behavior.uuid,
|
12289 |
stevensc |
35 |
comment: watch(`${behavior.competency_uuid}-${behavior.uuid}-comment`),
|
|
|
36 |
evaluation: watch(`select-${behavior.competency_uuid}-${behavior.uuid}`)
|
|
|
37 |
})
|
|
|
38 |
}))
|
|
|
39 |
|
|
|
40 |
const submitData = new FormData()
|
|
|
41 |
submitData.append('content', JSON.stringify(content))
|
|
|
42 |
submitData.append('points', watch('points'))
|
|
|
43 |
submitData.append('comment', watch('comment'))
|
|
|
44 |
|
|
|
45 |
axios.post(actionLink, submitData)
|
|
|
46 |
.then(({ data }) => {
|
|
|
47 |
if (!data.success) {
|
14843 |
stevensc |
48 |
typeof data.data === 'string'
|
|
|
49 |
?
|
|
|
50 |
dispatch(addNotification({
|
|
|
51 |
style: 'danger',
|
|
|
52 |
msg: data.data
|
|
|
53 |
}))
|
|
|
54 |
: Object.entries(data.data).map(([key, value]) =>
|
|
|
55 |
value.map(err =>
|
|
|
56 |
dispatch(addNotification({
|
|
|
57 |
style: 'danger',
|
|
|
58 |
msg: `${key}: ${err}`
|
|
|
59 |
}))
|
|
|
60 |
)
|
|
|
61 |
)
|
|
|
62 |
return
|
12289 |
stevensc |
63 |
}
|
|
|
64 |
|
|
|
65 |
history.goBack()
|
|
|
66 |
setActionLink('')
|
|
|
67 |
dispatch(addNotification({
|
|
|
68 |
style: 'success',
|
|
|
69 |
msg: `Registro ${action === 'edit' ? 'actualizado' : 'añadido'}`
|
|
|
70 |
}))
|
|
|
71 |
})
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
useEffect(() => {
|
|
|
75 |
axios.get(actionLink)
|
|
|
76 |
.then(({ data }) => {
|
|
|
77 |
const resData = data.data
|
|
|
78 |
|
|
|
79 |
if (!data.success) {
|
|
|
80 |
return dispatch(addNotification({
|
|
|
81 |
style: 'danger',
|
|
|
82 |
msg: 'Ha ocurrido un error'
|
|
|
83 |
}))
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
setJobDescription(resData.job_description)
|
|
|
87 |
|
|
|
88 |
if (action === 'both') {
|
|
|
89 |
setValue('comment', resData.both.comment)
|
|
|
90 |
setValue('points', resData.both.points)
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
if (action === 'self') {
|
|
|
94 |
setValue('comment', resData.self.comment)
|
|
|
95 |
setValue('points', resData.self.points)
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
if (action === 'superviser') {
|
|
|
99 |
setValue('comment', resData.superviser.comment)
|
|
|
100 |
setValue('points', resData.superviser.points)
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
resData.jobDescription.competencies.behaviors.forEach((obj) => {
|
|
|
104 |
setValue(`select-${obj.competency_uuid}-${obj.uuid}`, obj.evaluation)
|
|
|
105 |
setValue(`${obj.competency_uuid}-${obj.uuid}-comment`, obj.comment)
|
|
|
106 |
})
|
|
|
107 |
})
|
|
|
108 |
}, [action])
|
|
|
109 |
|
|
|
110 |
return (
|
|
|
111 |
<section className="content">
|
|
|
112 |
<div className="container-fluid">
|
|
|
113 |
<div className="row">
|
|
|
114 |
<div className="col-12">
|
|
|
115 |
<form onSubmit={handleSubmit(onSubmit)}>
|
|
|
116 |
<div className='card'>
|
|
|
117 |
<div className="card-header">
|
|
|
118 |
<ul className="nav nav-tabs" id="myTab" role="tablist">
|
|
|
119 |
<li className="nav-item" role="presentation">
|
|
|
120 |
<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>
|
|
|
121 |
</li>
|
|
|
122 |
<li className="nav-item" role="presentation">
|
|
|
123 |
<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>
|
|
|
124 |
</li>
|
|
|
125 |
<li className="nav-item" role="presentation">
|
|
|
126 |
<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>
|
|
|
127 |
</li>
|
|
|
128 |
</ul>
|
|
|
129 |
</div>
|
|
|
130 |
<div className="card-body">
|
|
|
131 |
<div className="tab-content" id="myTabContent">
|
|
|
132 |
<div className="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">
|
|
|
133 |
<div className="card">
|
|
|
134 |
<div className="card-body">
|
|
|
135 |
<h5>{jobDescription.name}</h5>
|
|
|
136 |
<h6>Funciones</h6>
|
|
|
137 |
<p>{jobDescription.functions}</p>
|
|
|
138 |
<h6>Objetivos</h6>
|
|
|
139 |
<p>{jobDescription.objectives}</p>
|
|
|
140 |
</div>
|
|
|
141 |
</div>
|
|
|
142 |
</div>
|
|
|
143 |
<div className="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">
|
|
|
144 |
{
|
12292 |
stevensc |
145 |
jobDescription.competencies?.length > 0
|
14843 |
stevensc |
146 |
&&
|
|
|
147 |
jobDescription.competencies.map((competency) => (
|
|
|
148 |
<div className="card" key={competency.competency_uuid}>
|
|
|
149 |
<div className="card-header">
|
|
|
150 |
<h5>{competency.competency_name} - {competency.competency_type_name}</h5>
|
|
|
151 |
</div>
|
|
|
152 |
<div className="card-body">
|
|
|
153 |
<div className="table-responsive">
|
|
|
154 |
{
|
|
|
155 |
competency.behaviors
|
|
|
156 |
&&
|
|
|
157 |
competency.behaviors.map((behavior) => (
|
|
|
158 |
<table key={behavior.uuid} className="table table-hover">
|
|
|
159 |
<thead>
|
|
|
160 |
<tr>
|
|
|
161 |
<th style={{ width: '20%' }}>Conducta Observable</th>
|
|
|
162 |
<th style={{ width: '60%' }}>Comentario</th>
|
|
|
163 |
<th style={{ width: '20%' }}>Evaluación</th>
|
|
|
164 |
</tr>
|
|
|
165 |
</thead>
|
|
|
166 |
<tbody>
|
|
|
167 |
<tr>
|
|
|
168 |
<td style={{ width: '20%' }}>{behavior.description}</td>
|
|
|
169 |
<td style={{ width: '60%' }}>
|
|
|
170 |
<textarea
|
|
|
171 |
name={`${behavior.competency_uuid}-${behavior.uuid}-comment`}
|
|
|
172 |
cols="30"
|
|
|
173 |
rows="3"
|
|
|
174 |
ref={register}
|
|
|
175 |
className='form-control w100'
|
|
|
176 |
/>
|
|
|
177 |
</td>
|
|
|
178 |
<td style={{ width: '20%' }}>
|
|
|
179 |
<select className='form-control' name={`select-${behavior.competency_uuid}-${behavior.uuid}`} ref={register}>
|
|
|
180 |
{
|
|
|
181 |
pointsOptions.map(({ label, value }) => {
|
|
|
182 |
return <option selected={watch(`select-${behavior.competency_uuid}-${behavior.uuid}`) === value} key={value} value={value}>{label}</option>
|
|
|
183 |
})
|
|
|
184 |
}
|
|
|
185 |
</select>
|
|
|
186 |
</td>
|
|
|
187 |
</tr>
|
|
|
188 |
</tbody>
|
|
|
189 |
</table>
|
|
|
190 |
))
|
|
|
191 |
}
|
|
|
192 |
</div>
|
|
|
193 |
</div>
|
|
|
194 |
</div>
|
|
|
195 |
))
|
12289 |
stevensc |
196 |
}
|
|
|
197 |
</div>
|
|
|
198 |
<div className="tab-pane fade" id="contact" role="tabpanel" aria-labelledby="contact-tab">
|
|
|
199 |
<div className="form-group">
|
|
|
200 |
<label>Comentario</label>
|
|
|
201 |
<input type="text" name="comment" className="form-control" ref={register} />
|
|
|
202 |
</div>
|
|
|
203 |
<div className="form-group">
|
|
|
204 |
<label>Evaluación</label>
|
|
|
205 |
<select className='form-control' name='points' ref={register}>
|
|
|
206 |
{
|
|
|
207 |
pointsOptions.map(({ label, value }) => (
|
|
|
208 |
<option selected={watch('points') === value} key={value} value={value}>{label}</option>
|
|
|
209 |
))
|
|
|
210 |
}
|
|
|
211 |
</select>
|
|
|
212 |
</div>
|
|
|
213 |
</div>
|
|
|
214 |
</div>
|
|
|
215 |
<div className="form-group">
|
|
|
216 |
<button type="submit" className="btn btn-primary btn-form-save-close mr-2">
|
14843 |
stevensc |
217 |
Guardar & Cerrar
|
12289 |
stevensc |
218 |
</button>
|
|
|
219 |
<button
|
|
|
220 |
type="button"
|
|
|
221 |
className="btn btn-secondary btn-edit-cancel"
|
|
|
222 |
onClick={() => history.goBack()}
|
|
|
223 |
>
|
14843 |
stevensc |
224 |
Cancelar
|
12289 |
stevensc |
225 |
</button>
|
|
|
226 |
</div>
|
|
|
227 |
</div>
|
|
|
228 |
</div>
|
|
|
229 |
</form>
|
|
|
230 |
</div>
|
|
|
231 |
</div>
|
|
|
232 |
</div>
|
|
|
233 |
</section >
|
|
|
234 |
)
|
|
|
235 |
}
|
|
|
236 |
export default EvaluationView
|