Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 14236 Rev 14237
Línea 1... Línea 1...
1
/* eslint-disable no-mixed-spaces-and-tabs */
1
/* eslint-disable no-mixed-spaces-and-tabs */
2
import axios from 'axios'
2
import axios from 'axios'
3
import { CKEditor } from 'ckeditor4-react'
3
import { CKEditor } from 'ckeditor4-react'
4
import React, { useEffect, useState } from 'react'
4
import React, { useEffect, useState } from 'react'
-
 
5
import { useRef } from 'react'
5
import { useForm } from 'react-hook-form'
6
import { useForm } from 'react-hook-form'
6
import { useDispatch } from 'react-redux'
7
import { useDispatch } from 'react-redux'
7
import { useHistory, useParams } from 'react-router-dom'
8
import { useHistory, useParams } from 'react-router-dom'
8
import { addNotification } from '../../redux/notification/notification.actions'
9
import { addNotification } from '../../redux/notification/notification.actions'
9
import { config } from '../../shared/helpers/ckeditor_config'
10
import { config } from '../../shared/helpers/ckeditor_config'
Línea 15... Línea 16...
15
}) => {
16
}) => {
Línea 16... Línea 17...
16
 
17
 
17
	// Hooks
18
	// Hooks
18
	const dispatch = useDispatch()
19
	const dispatch = useDispatch()
-
 
20
	const history = useHistory()
19
	const history = useHistory()
21
	const selectInput = useRef(null)
20
	const { action } = useParams()
22
	const { action } = useParams()
21
	const {
23
	const {
22
		setValue,
24
		setValue,
23
		register,
25
		register,
Línea 27... Línea 29...
27
 
29
 
28
	//States
30
	//States
29
	const [supervisers, setSupervisers] = useState([])
31
	const [supervisers, setSupervisers] = useState([])
30
	const [initObjectives, setInitObjectives] = useState('')
32
	const [initObjectives, setInitObjectives] = useState('')
-
 
33
	const [initFunctions, setInitFunctions] = useState('')
-
 
34
	const [competencyOptions, setCompetencyOptions] = useState([])
-
 
35
	const [competenciesSelected, setCompetenciesSelected] = useState([])
Línea 31... Línea 36...
31
	const [initFunctions, setInitFunctions] = useState('')
36
	const [competencyTypeOptions, setCompetencyTypeOptions] = useState([])
Línea 32... Línea 37...
32
 
37
 
33
	const onSubmit = () => {
38
	const onSubmit = () => {
Línea 65... Línea 70...
65
					msg: `Registro ${action === 'edit' ? 'actualizado' : 'añadido'}`
70
					msg: `Registro ${action === 'edit' ? 'actualizado' : 'añadido'}`
66
				}))
71
				}))
67
			})
72
			})
68
	}
73
	}
Línea -... Línea 74...
-
 
74
 
-
 
75
	const handleSetCompetencies = () => {
-
 
76
		const current_competency = competencyOptions.find(competency => competency.competency_id === selectInput.current.value)
-
 
77
		console.log(current_competency)
-
 
78
		setCompetenciesSelected(prev => [current_competency, ...prev])
-
 
79
	}
69
 
80
 
70
	useEffect(() => {
81
	useEffect(() => {
71
		register('status')
82
		register('status')
72
		register('objectives')
83
		register('objectives')
73
		register('functions')
84
		register('functions')
Línea 74... Línea 85...
74
	}, [])
85
	}, [])
75
 
-
 
76
	useEffect(() => {
-
 
77
		console.log(watch('status'))
-
 
78
		console.log(watch('objectives'))
-
 
79
		console.log(watch('functions'))
-
 
80
	}, [])
-
 
81
 
86
 
82
	useEffect(() => {
87
	useEffect(() => {
83
		axios.get(actionLink)
88
		axios.get(actionLink)
84
			.then(({ data }) => {
89
			.then(({ data }) => {
85
				if (!data.success) {
90
				if (!data.success) {
Línea 95... Línea 100...
95
						value: option.uuid
100
						value: option.uuid
96
					}
101
					}
97
				}))
102
				}))
98
				setInitObjectives(data.data['objectives'])
103
				setInitObjectives(data.data['objectives'])
99
				setInitFunctions(data.data['functions'])
104
				setInitFunctions(data.data['functions'])
-
 
105
				setCompetencyOptions(data.data['competencies'])
-
 
106
				setCompetencyTypeOptions(data.data['competency_types'])
-
 
107
				setCompetenciesSelected(data.data['competencies_selected'])
Línea 100... Línea 108...
100
 
108
 
101
				setValue('name', data.data['name'])
109
				setValue('name', data.data['name'])
102
				setValue('status', data.data['status'])
110
				setValue('status', data.data['status'])
Línea 126... Línea 134...
126
									</ul>
134
									</ul>
127
								</div>
135
								</div>
128
								<div className="card-body">
136
								<div className="card-body">
129
									<div className="tab-content" id="myTabContent">
137
									<div className="tab-content" id="myTabContent">
130
										<div className="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">
138
										<div className="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">
131
											<div className="card px-2">
139
											<div className="card p-2">
132
												<div className="d-flex">
140
												<div className="d-flex">
133
													<div className="col-4">
141
													<div className="col-4">
134
														<div className="form-group">
142
														<div className="form-group">
135
															<label>Nombre</label>
143
															<label>Nombre</label>
136
															<input className='form-control' type="text" name='name' ref={register} />
144
															<input className='form-control' type="text" name='name' ref={register} />
Línea 159... Línea 167...
159
													</div>
167
													</div>
160
												</div>
168
												</div>
161
												<div className="d-flex">
169
												<div className="d-flex">
162
													<div className="form-group w-100">
170
													<div className="form-group w-100">
163
														<label>Objetivo</label>
171
														<label>Objetivo</label>
-
 
172
														{
-
 
173
															initObjectives
-
 
174
															&&
164
														<CKEditor
175
															<CKEditor
165
															data={initObjectives}
176
																data={initObjectives}
166
															onChange={(e) => setValue('objectives', e.editor.getData())}
177
																onChange={(e) => setValue('objectives', e.editor.getData())}
167
															onInstanceReady={(e) => e.editor.setData(initObjectives)}
-
 
168
															config={config}
178
																config={config}
169
															name="objectives"
179
																name="objectives"
170
														/>
180
															/>
-
 
181
														}
171
													</div>
182
													</div>
172
												</div>
183
												</div>
173
												<div className="d-flex">
184
												<div className="d-flex">
174
													<div className="form-group w-100">
185
													<div className="form-group w-100">
175
														<label>Funciones</label>
186
														<label>Funciones</label>
-
 
187
														{
-
 
188
															initFunctions
-
 
189
															&&
176
														<CKEditor
190
															<CKEditor
177
															data={initFunctions}
191
																data={initFunctions}
178
															onChange={(e) => setValue('functions', e.editor.getData())}
192
																onChange={(e) => setValue('functions', e.editor.getData())}
179
															onInstanceReady={(e) => e.editor.setData(initFunctions)}
-
 
180
															config={config}
193
																config={config}
181
															name="functions"
194
																name="functions"
182
														/>
195
															/>
-
 
196
														}
183
													</div>
197
													</div>
184
												</div>
198
												</div>
185
											</div>
199
											</div>
186
										</div>
200
										</div>
187
										<div className="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">
201
										<div className="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">
-
 
202
											<div className="card p-2">
-
 
203
												<div className="d-flex justify-content-around">
-
 
204
													<select className='form-control' name="job_description_id_boss" ref={selectInput}>
-
 
205
														<option value="">Seleccione</option>
-
 
206
														{
-
 
207
															competencyOptions.map((competency) => {
-
 
208
																const competency_type = competencyTypeOptions.find(type => type.competency_type_id === competency.competency_type_id)
188
 
209
 
-
 
210
																return (
-
 
211
																	<option
-
 
212
																		key={competency.competency_id}
-
 
213
																		value={competency.competency_id}>
-
 
214
																		{`${competency_type} - ${competency.name}`}
-
 
215
																	</option>
-
 
216
																)
-
 
217
															})
-
 
218
														}
-
 
219
													</select>
-
 
220
													<button
-
 
221
														className='btn btn-primary'
-
 
222
														onClick={handleSetCompetencies}
-
 
223
													>
-
 
224
														Agregar Competencia
-
 
225
													</button>
-
 
226
												</div>
-
 
227
											</div>
189
										</div>
228
										</div>
190
										<div className="tab-pane fade" id="contact" role="tabpanel" aria-labelledby="contact-tab">
229
										<div className="tab-pane fade" id="contact" role="tabpanel" aria-labelledby="contact-tab">
Línea 191... Línea 230...
191
 
230
 
192
										</div>
231
										</div>