Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 12012 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 12012 Rev 12135
Línea 1... Línea 1...
1
import React from 'react'
1
import axios from 'axios'
-
 
2
import React, { useEffect, useState } from 'react'
-
 
3
import parse from 'html-react-parser'
-
 
4
import { useForm } from 'react-hook-form'
-
 
5
import { useDispatch } from 'react-redux'
-
 
6
import { useHistory } from 'react-router-dom'
-
 
7
import { addNotification } from '../../../redux/notification/notification.actions'
-
 
8
import DescriptionInput from '../../../shared/DescriptionInput'
-
 
9
 
-
 
10
const AddView = ({ actionLink, jobsDescription: jobDescriptionOptions }) => {
-
 
11
 
-
 
12
	// Hooks
-
 
13
	const history = useHistory()
-
 
14
	const { register, setValue, watch, reset } = useForm()
-
 
15
	const dispatch = useDispatch()
-
 
16
 
-
 
17
	// State
-
 
18
	const [currentJobDescription, setCurretJobDescription] = useState('')
-
 
19
	const [status, setStatus] = useState('a')
-
 
20
 
-
 
21
	const onSubmit = () => {
-
 
22
 
-
 
23
		const submitData = new FormData()
-
 
24
		submitData.append('name', watch('name'))
-
 
25
		submitData.append('description', watch('description'))
-
 
26
		submitData.append('status', status)
-
 
27
		submitData.append('job_description_id', currentJobDescription)
-
 
28
		submitData.append('content', '[]')
-
 
29
 
-
 
30
		axios.post(actionLink, submitData)
-
 
31
			.then(({ data }) => {
-
 
32
				if (!data.success) {
-
 
33
					return dispatch(addNotification({
-
 
34
						style: 'danger',
-
 
35
						msg: 'Ha ocurrido un error'
-
 
36
					}))
-
 
37
				}
-
 
38
 
-
 
39
				dispatch(addNotification({
-
 
40
					style: 'success',
-
 
41
					msg: data.data
-
 
42
				}))
-
 
43
			})
-
 
44
	}
-
 
45
 
-
 
46
	const submitAndClose = () => {
-
 
47
		onSubmit()
-
 
48
		reset()
-
 
49
		history.goBack()
-
 
50
	}
-
 
51
 
-
 
52
	useEffect(() => {
-
 
53
		register('description')
-
 
54
	}, [])
Línea 2... Línea -...
2
 
-
 
3
const AddView = () => {
55
 
-
 
56
	return (
-
 
57
		<section className="content">
-
 
58
			<div className="row" style={{ padding: 16 }}>
-
 
59
				<div className="col-xs-12 col-md-12">
-
 
60
					<div className="form-group">
-
 
61
						<label>Nombre</label>
4
	return (
62
						<input type="text" name="name" className='form-control' ref={register({ required: true, maxLength: 50 })} />
-
 
63
					</div>
-
 
64
					<div className="form-group">
-
 
65
						<label>Cargo a evaluar</label>
-
 
66
						<select name="job_description_id" className="form-control" onChange={(e) => setCurretJobDescription(e.target.value)}>
-
 
67
							{
-
 
68
								jobDescriptionOptions.map(({ name, job_description_id }) => (
-
 
69
									<option selected={job_description_id === currentJobDescription} key={job_description_id} value={job_description_id}>{name}</option>
-
 
70
								))
-
 
71
							}
-
 
72
						</select>
-
 
73
					</div>
-
 
74
					<div className="form-group">
-
 
75
						<label htmlFor="form-description">Descripción</label>
-
 
76
						<DescriptionInput
-
 
77
							defaultValue={typeof watch('description') === 'string' ? parse(watch('description')) : ''}
-
 
78
							name='description'
-
 
79
							onChange={setValue}
-
 
80
						/>
-
 
81
					</div>
-
 
82
					<div className="form-group">
-
 
83
						<label htmlFor="form-status">Estatus</label>
-
 
84
						<select name="form-status" className="form-control" onChange={(e) => setStatus(e.target.value)} value={status}>
-
 
85
							<option selected={status === 'i'} value="i">Inactivo</option>
-
 
86
							<option selected={status === 'a'} value="a">Activo</option>
-
 
87
						</select>
-
 
88
					</div>
-
 
89
					<br />
-
 
90
					<div className="d-flex" style={{ gap: '5px' }}>
-
 
91
						<button type="button" className="btn btn-info" onClick={onSubmit}>Guardar & Continuar</button>
-
 
92
						<button type="button" className="btn btn-primary" onClick={submitAndClose}>Guardar & Cerrar</button>
-
 
93
						<button type="button" className="btn btn-secondary" onClick={() => history.goBack()}>Cancelar</button>
-
 
94
					</div>
-
 
95
				</div>
-
 
96
			</div >
-
 
97
		</section >
5
		<div>AddView</div>
98
 
6
	)
99
	)
Línea 7... Línea 100...
7
}
100
}
8
 
101