| 12040 | stevensc | 1 | import axios from 'axios'
 | 
        
           |  |  | 2 | import React, { useEffect, useState } from 'react'
 | 
        
           |  |  | 3 | import { useForm } from 'react-hook-form'
 | 
        
           |  |  | 4 | import { useDispatch } from 'react-redux'
 | 
        
           |  |  | 5 | import { addNotification } from '../../../redux/notification/notification.actions'
 | 
        
           |  |  | 6 | import DescriptionInput from '../../../shared/DescriptionInput'
 | 
        
           | 12012 | stevensc | 7 |   | 
        
           | 12081 | stevensc | 8 | const levelOptions = {
 | 
        
           |  |  | 9 | 	'1': 'Uno',
 | 
        
           |  |  | 10 | 	'2': 'Dos',
 | 
        
           |  |  | 11 | 	'3': 'Tres',
 | 
        
           |  |  | 12 | 	'4': 'Cuatro',
 | 
        
           |  |  | 13 | 	'5': 'Cinco'
 | 
        
           |  |  | 14 | }
 | 
        
           |  |  | 15 |   | 
        
           | 12040 | stevensc | 16 | const EditView = ({ actionLink }) => {
 | 
        
           |  |  | 17 |   | 
        
           |  |  | 18 | 	const { register, handleSubmit, setValue, watch } = useForm()
 | 
        
           | 12047 | stevensc | 19 | 	const [currentJobDescription, setCurretJobDescription] = useState('')
 | 
        
           |  |  | 20 | 	const [jobDescriptionOptions, setJobDescriptionOptions] = useState([])
 | 
        
           | 12081 | stevensc | 21 | 	const [competencyTypes, setCompetencyTypes] = useState([])
 | 
        
           |  |  | 22 | 	const [competenciesSelected, setCompetenciesSelected] = useState([])
 | 
        
           | 12047 | stevensc | 23 | 	const [status, setStatus] = useState('a')
 | 
        
           | 12040 | stevensc | 24 | 	const dispatch = useDispatch()
 | 
        
           |  |  | 25 |   | 
        
           |  |  | 26 | 	useEffect(() => {
 | 
        
           |  |  | 27 | 		register('description')
 | 
        
           |  |  | 28 | 	}, [])
 | 
        
           |  |  | 29 |   | 
        
           |  |  | 30 | 	useEffect(() => {
 | 
        
           |  |  | 31 | 		axios.get(actionLink)
 | 
        
           |  |  | 32 | 			.then(({ data }) => {
 | 
        
           |  |  | 33 | 				if (!data.success) {
 | 
        
           |  |  | 34 | 					return dispatch(addNotification({
 | 
        
           |  |  | 35 | 						style: 'danger',
 | 
        
           |  |  | 36 | 						msg: 'Ha ocurrido un error'
 | 
        
           |  |  | 37 | 					}))
 | 
        
           |  |  | 38 | 				}
 | 
        
           |  |  | 39 |   | 
        
           |  |  | 40 | 				setValue('name', data.data.name)
 | 
        
           |  |  | 41 | 				setValue('description', data.data.description)
 | 
        
           |  |  | 42 | 				setCurretJobDescription(data.data.job_description_id)
 | 
        
           |  |  | 43 | 				setStatus(data.data.status)
 | 
        
           |  |  | 44 | 			})
 | 
        
           |  |  | 45 | 	}, [actionLink])
 | 
        
           |  |  | 46 |   | 
        
           |  |  | 47 | 	useEffect(() => {
 | 
        
           |  |  | 48 | 		axios.get(`/settings/jobs-description/edit/${currentJobDescription}`)
 | 
        
           |  |  | 49 | 			.then(({ data }) => {
 | 
        
           |  |  | 50 | 				if (!data.success) {
 | 
        
           |  |  | 51 | 					return dispatch(addNotification({
 | 
        
           |  |  | 52 | 						style: 'danger',
 | 
        
           |  |  | 53 | 						msg: 'Ha ocurrido un error'
 | 
        
           |  |  | 54 | 					}))
 | 
        
           |  |  | 55 | 				}
 | 
        
           |  |  | 56 |   | 
        
           | 12047 | stevensc | 57 | 				setJobDescriptionOptions([...data.data.jobs_description, { job_description_id: data.data.uuid, name: data.data.name }])
 | 
        
           | 12081 | stevensc | 58 | 				setCompetenciesSelected(data.data.competencies_selected)
 | 
        
           |  |  | 59 | 				setCompetencyTypes(data.data.competency_types)
 | 
        
           | 12040 | stevensc | 60 | 			})
 | 
        
           |  |  | 61 | 	}, [currentJobDescription])
 | 
        
           |  |  | 62 |   | 
        
           | 12012 | stevensc | 63 | 	return (
 | 
        
           | 12040 | stevensc | 64 | 		<section className="content">
 | 
        
           |  |  | 65 | 			<div className="row" style={{ padding: 16 }}>
 | 
        
           |  |  | 66 | 				<div className="col-xs-12 col-md-12">
 | 
        
           |  |  | 67 | 					<form onSubmit={handleSubmit}>
 | 
        
           |  |  | 68 | 						<div className="form-group">
 | 
        
           | 12081 | stevensc | 69 | 							<label>Nombre</label>
 | 
        
           |  |  | 70 | 							<input type="text" name="name" className='form-control' ref={register({ required: true, maxLength: 50 })} />
 | 
        
           | 12040 | stevensc | 71 | 						</div>
 | 
        
           |  |  | 72 | 						<div className="form-group">
 | 
        
           |  |  | 73 | 							<label>Cargo a evaluar</label>
 | 
        
           | 12081 | stevensc | 74 | 							<select name="job_description_id" ref={register({ required: true })} className="form-control">
 | 
        
           | 12040 | stevensc | 75 | 								{
 | 
        
           |  |  | 76 | 									jobDescriptionOptions.map(({ name, job_description_id }) => (
 | 
        
           |  |  | 77 | 										<option selected={job_description_id === currentJobDescription} key={job_description_id} value={job_description_id}>{name}</option>
 | 
        
           |  |  | 78 | 									))
 | 
        
           |  |  | 79 | 								}
 | 
        
           |  |  | 80 | 							</select>
 | 
        
           |  |  | 81 | 						</div>
 | 
        
           |  |  | 82 | 						<div className="form-group">
 | 
        
           |  |  | 83 | 							<label htmlFor="form-description">Descripción</label>
 | 
        
           |  |  | 84 | 							<DescriptionInput
 | 
        
           |  |  | 85 | 								defaultValue={watch('description')}
 | 
        
           |  |  | 86 | 								name='description'
 | 
        
           |  |  | 87 | 								onChange={setValue}
 | 
        
           |  |  | 88 | 							/>
 | 
        
           |  |  | 89 | 						</div>
 | 
        
           |  |  | 90 | 						<div className="form-group">
 | 
        
           |  |  | 91 | 							<label htmlFor="form-status">Estatus</label>
 | 
        
           |  |  | 92 | 							<select name="form-status" className="form-control">
 | 
        
           |  |  | 93 | 								<option selected={status === 'i'} value="i">Inactivo</option>
 | 
        
           |  |  | 94 | 								<option selected={status === 'a'} value="a">Activo</option>
 | 
        
           |  |  | 95 | 							</select>
 | 
        
           |  |  | 96 | 						</div>
 | 
        
           |  |  | 97 | 						<br />
 | 
        
           |  |  | 98 | 						<div className="row">
 | 
        
           |  |  | 99 | 							<div className="col-xs-12 col-md-12">
 | 
        
           |  |  | 100 | 								<div className="panel-group" id="rows" />
 | 
        
           |  |  | 101 | 							</div>
 | 
        
           |  |  | 102 | 						</div>
 | 
        
           |  |  | 103 | 						<div className="form-group" id="competencies-to-job" style={{}}>
 | 
        
           |  |  | 104 | 							<div className="row">
 | 
        
           |  |  | 105 | 								<div className="col-xs-12 col-md-12">
 | 
        
           |  |  | 106 | 									<hr />
 | 
        
           |  |  | 107 | 									<h4 style={{ fontSize: 18, fontWeight: 'bold' }}>Competencias asociadas al cargo:</h4>
 | 
        
           |  |  | 108 | 									<br />
 | 
        
           | 12081 | stevensc | 109 | 									<div className="panel-group" id="rows-job-competencies" >
 | 
        
           |  |  | 110 | 										{
 | 
        
           | 12082 | stevensc | 111 | 											competenciesSelected.map((competency) => {
 | 
        
           |  |  | 112 | 												const type = competencyTypes.find((type) => type.competency_type_id === competency.competency_type_id)
 | 
        
           | 12081 | stevensc | 113 | 												return (
 | 
        
           | 12082 | stevensc | 114 | 													<div className="panel panel-default" key={competency.competency_id} id={`panel-${competency.competency_id}`}>
 | 
        
           | 12081 | stevensc | 115 | 														<div className="panel-heading">
 | 
        
           |  |  | 116 | 															<h4 className="panel-title" style={{ fontSize: 18 }}>
 | 
        
           | 12082 | stevensc | 117 | 																<a className="accordion-toggle" data-toggle="collapse" aria-expanded="true" href={`collapse-${competency.competency_id}`}>
 | 
        
           |  |  | 118 | 																	<span className={`competency-name-${competency.competency_id}`}>
 | 
        
           |  |  | 119 | 																		{`${type.name} - ${competency.name}`}
 | 
        
           | 12081 | stevensc | 120 | 																	</span>
 | 
        
           |  |  | 121 | 																</a>
 | 
        
           |  |  | 122 | 															</h4>
 | 
        
           |  |  | 123 | 														</div>
 | 
        
           |  |  | 124 | 														<div id="collapse-46d0f805-03ad-4c06-93c2-2a4ec87f6b97" className="panel-collapse in collapse show">
 | 
        
           |  |  | 125 | 															<div className="panel-body">
 | 
        
           |  |  | 126 | 																<div className="table-responsive">
 | 
        
           |  |  | 127 | 																	<table className="table table-bordered">
 | 
        
           |  |  | 128 | 																		<thead>
 | 
        
           |  |  | 129 | 																			<tr>
 | 
        
           |  |  | 130 | 																				<th style={{ width: '80%' }}>Conducta Observable</th>
 | 
        
           |  |  | 131 | 																				<th style={{ width: '20%' }}>Nivel</th>
 | 
        
           |  |  | 132 | 																			</tr>
 | 
        
           |  |  | 133 | 																		</thead>
 | 
        
           |  |  | 134 | 																		<tbody>
 | 
        
           |  |  | 135 | 																			{
 | 
        
           | 12082 | stevensc | 136 | 																				competency.behaviors?.map(({ behavior_id, description, level }) => (
 | 
        
           | 12081 | stevensc | 137 | 																					<tr key={behavior_id}>
 | 
        
           |  |  | 138 | 																						<td className="text-left">
 | 
        
           |  |  | 139 | 																							{description}
 | 
        
           |  |  | 140 | 																						</td>
 | 
        
           |  |  | 141 | 																						<td>
 | 
        
           |  |  | 142 | 																							{levelOptions[level]}
 | 
        
           |  |  | 143 | 																						</td>
 | 
        
           |  |  | 144 | 																					</tr>
 | 
        
           |  |  | 145 | 																				))
 | 
        
           |  |  | 146 | 																			}
 | 
        
           |  |  | 147 | 																		</tbody>
 | 
        
           |  |  | 148 | 																	</table>
 | 
        
           |  |  | 149 | 																</div>
 | 
        
           |  |  | 150 | 															</div>
 | 
        
           |  |  | 151 | 														</div>
 | 
        
           | 12040 | stevensc | 152 | 													</div>
 | 
        
           | 12081 | stevensc | 153 | 												)
 | 
        
           |  |  | 154 | 											})
 | 
        
           |  |  | 155 | 										}
 | 
        
           | 12040 | stevensc | 156 | 									</div>
 | 
        
           |  |  | 157 | 								</div>
 | 
        
           |  |  | 158 | 							</div>
 | 
        
           |  |  | 159 | 						</div>
 | 
        
           |  |  | 160 | 						<div className="form-group">
 | 
        
           |  |  | 161 | 							<button type="button" form="form-main" className="btn btn-info">Guardar & Continuar</button>
 | 
        
           |  |  | 162 | 							<button type="button" className="btn btn-primary">Guardar & Cerrar</button>
 | 
        
           |  |  | 163 | 							<button type="button" className="btn btn-secondary">Cancelar</button>
 | 
        
           |  |  | 164 | 						</div>
 | 
        
           |  |  | 165 | 					</form>
 | 
        
           |  |  | 166 | 				</div>
 | 
        
           | 12081 | stevensc | 167 | 			</div >
 | 
        
           |  |  | 168 | 		</section >
 | 
        
           | 12040 | stevensc | 169 |   | 
        
           | 12012 | stevensc | 170 | 	)
 | 
        
           |  |  | 171 | }
 | 
        
           |  |  | 172 |   | 
        
           |  |  | 173 | export default EditView
 |