| 14197 |
stevensc |
1 |
/* eslint-disable no-mixed-spaces-and-tabs */
|
|
|
2 |
import axios from 'axios'
|
|
|
3 |
import React, { useEffect, useState } 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 FormView = ({
|
|
|
18 |
actionLink = '',
|
|
|
19 |
setActionLink = function () { }
|
|
|
20 |
}) => {
|
|
|
21 |
|
|
|
22 |
// Hooks
|
|
|
23 |
const dispatch = useDispatch()
|
|
|
24 |
const history = useHistory()
|
|
|
25 |
const { action } = useParams()
|
|
|
26 |
const { setValue, register, watch, handleSubmit } = useForm()
|
|
|
27 |
|
|
|
28 |
//States
|
| 14205 |
stevensc |
29 |
const [data, setData] = useState({})
|
|
|
30 |
const [supervisers, setSupervisers] = useState([])
|
| 14197 |
stevensc |
31 |
|
|
|
32 |
const onSubmit = () => {
|
|
|
33 |
|
| 14206 |
stevensc |
34 |
const submitData = new FormData()
|
| 14205 |
stevensc |
35 |
/* const content = []
|
| 14197 |
stevensc |
36 |
jobDescription.competencies.forEach(competency => competency.behaviors.forEach(behavior => {
|
|
|
37 |
content.push({
|
|
|
38 |
competencyUuid: behavior.competency_uuid,
|
|
|
39 |
behaviorUuid: behavior.uuid,
|
|
|
40 |
comment: watch(`${behavior.competency_uuid}-${behavior.uuid}-comment`),
|
|
|
41 |
evaluation: watch(`select-${behavior.competency_uuid}-${behavior.uuid}`)
|
|
|
42 |
})
|
|
|
43 |
}))
|
|
|
44 |
|
|
|
45 |
submitData.append('content', JSON.stringify(content))
|
| 14205 |
stevensc |
46 |
submitData.append('points', watch('points')) */
|
|
|
47 |
//.append('comment', watch('comment'))
|
| 14197 |
stevensc |
48 |
|
|
|
49 |
axios.post(actionLink, submitData)
|
|
|
50 |
.then(({ data }) => {
|
|
|
51 |
if (!data.success) {
|
|
|
52 |
return dispatch(addNotification({
|
|
|
53 |
style: 'danger',
|
|
|
54 |
msg: typeof data.data === 'string'
|
|
|
55 |
? data.data
|
|
|
56 |
: 'Ha ocurrido un error'
|
|
|
57 |
}))
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
history.goBack()
|
|
|
61 |
setActionLink('')
|
|
|
62 |
dispatch(addNotification({
|
|
|
63 |
style: 'success',
|
|
|
64 |
msg: `Registro ${action === 'edit' ? 'actualizado' : 'añadido'}`
|
|
|
65 |
}))
|
|
|
66 |
})
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
useEffect(() => {
|
|
|
70 |
axios.get(actionLink)
|
|
|
71 |
.then(({ data }) => {
|
|
|
72 |
if (!data.success) {
|
|
|
73 |
return dispatch(addNotification({
|
|
|
74 |
style: 'danger',
|
|
|
75 |
msg: 'Ha ocurrido un error'
|
|
|
76 |
}))
|
|
|
77 |
}
|
|
|
78 |
|
| 14206 |
stevensc |
79 |
setSupervisers(data.data['supervisers'].map(option => {
|
|
|
80 |
return {
|
|
|
81 |
key: option.name,
|
|
|
82 |
value: option.uuid
|
|
|
83 |
}
|
|
|
84 |
}))
|
| 14205 |
stevensc |
85 |
setValue('name', data.data['name'])
|
|
|
86 |
setValue('job_description_id_boss', data.data['job_description_id_boss'])
|
| 14197 |
stevensc |
87 |
|
|
|
88 |
})
|
|
|
89 |
}, [action])
|
|
|
90 |
|
|
|
91 |
return (
|
|
|
92 |
<section className="content">
|
|
|
93 |
<div className="container-fluid">
|
|
|
94 |
<div className="row">
|
|
|
95 |
<div className="col-12">
|
|
|
96 |
<form onSubmit={handleSubmit(onSubmit)}>
|
|
|
97 |
<div className='card'>
|
|
|
98 |
<div className="card-header">
|
|
|
99 |
<ul className="nav nav-tabs" id="myTab" role="tablist">
|
|
|
100 |
<li className="nav-item" role="presentation">
|
|
|
101 |
<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>
|
|
|
102 |
</li>
|
|
|
103 |
<li className="nav-item" role="presentation">
|
|
|
104 |
<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>
|
|
|
105 |
</li>
|
|
|
106 |
<li className="nav-item" role="presentation">
|
|
|
107 |
<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>
|
|
|
108 |
</li>
|
|
|
109 |
</ul>
|
|
|
110 |
</div>
|
|
|
111 |
<div className="card-body">
|
|
|
112 |
<div className="tab-content" id="myTabContent">
|
|
|
113 |
<div className="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">
|
|
|
114 |
<div className="card">
|
| 14205 |
stevensc |
115 |
<div className="row">
|
|
|
116 |
<div className="col-4">
|
|
|
117 |
<div className="form-group">
|
|
|
118 |
<label>Nombre</label>
|
|
|
119 |
<input type="text" name='name' ref={register} />
|
| 14197 |
stevensc |
120 |
</div>
|
| 14205 |
stevensc |
121 |
</div>
|
|
|
122 |
<div className="col-4">
|
|
|
123 |
<div className="form-group">
|
|
|
124 |
<label>Nombre</label>
|
| 14206 |
stevensc |
125 |
<select className='form-control' name="job_description_id_boss" ref={register}>
|
| 14205 |
stevensc |
126 |
<option value="">No aplica</option>
|
| 14197 |
stevensc |
127 |
{
|
| 14207 |
stevensc |
128 |
supervisers.map(({ key, value }) =>
|
| 14205 |
stevensc |
129 |
<option key={value} value={value}>{key}</option>
|
|
|
130 |
)
|
| 14197 |
stevensc |
131 |
}
|
| 14205 |
stevensc |
132 |
</select>
|
| 14197 |
stevensc |
133 |
</div>
|
|
|
134 |
</div>
|
| 14205 |
stevensc |
135 |
</div>
|
|
|
136 |
</div>
|
| 14197 |
stevensc |
137 |
</div>
|
| 14205 |
stevensc |
138 |
<div className="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">
|
| 14206 |
stevensc |
139 |
|
| 14205 |
stevensc |
140 |
</div>
|
| 14197 |
stevensc |
141 |
<div className="tab-pane fade" id="contact" role="tabpanel" aria-labelledby="contact-tab">
|
| 14206 |
stevensc |
142 |
|
| 14197 |
stevensc |
143 |
</div>
|
|
|
144 |
</div>
|
|
|
145 |
<div className="form-group">
|
|
|
146 |
<button type="submit" className="btn btn-primary btn-form-save-close mr-2">
|
|
|
147 |
Guardar & Cerrar
|
|
|
148 |
</button>
|
|
|
149 |
<button
|
|
|
150 |
type="button"
|
|
|
151 |
className="btn btn-secondary btn-edit-cancel"
|
|
|
152 |
onClick={() => history.goBack()}
|
|
|
153 |
>
|
|
|
154 |
Cancelar
|
|
|
155 |
</button>
|
|
|
156 |
</div>
|
|
|
157 |
</div>
|
|
|
158 |
</div>
|
|
|
159 |
</form>
|
|
|
160 |
</div>
|
|
|
161 |
</div>
|
|
|
162 |
</div>
|
|
|
163 |
</section >
|
|
|
164 |
)
|
|
|
165 |
}
|
|
|
166 |
|
|
|
167 |
export default FormView
|