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