Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 14561 | Rev 15209 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
11139 stevensc 1
import React, { useState } from 'react'
11131 stevensc 2
import Datetime from 'react-datetime'
3
import { useForm } from 'react-hook-form'
14216 stevensc 4
import { useDispatch } from 'react-redux'
5
import { addNotification } from '../../../redux/notification/notification.actions'
11131 stevensc 6
import SearchLocationInput from '../../../shared/SearchLocationInput'
7
import SubmitModal from './SubmitModal'
8
 
9
const jobTypeOptions = [
10
	{ label: 'Tiempo completo', value: 'f' },
11
	{ label: 'Tiempo parcial', value: 'p' },
12
	{ label: 'Contratado', value: 'c' },
13
	{ label: 'Temporal', value: 't' },
14
]
15
 
14561 stevensc 16
const AddModal = ({ closeModal, dataLink, googleApiKey, jobCategoryOptions, onComplete }) => {
11131 stevensc 17
 
14216 stevensc 18
	const dispatch = useDispatch()
11131 stevensc 19
	const { register, watch } = useForm()
14217 stevensc 20
	const [year, setYear] = useState(Date.now())
11131 stevensc 21
	const [value, setValue] = useState('')
22
	const [data, setData] = useState({})
23
 
24
	return (
25
		<SubmitModal
26
			closeModal={closeModal}
27
			postLink={dataLink}
14561 stevensc 28
			onComplete={onComplete}
11131 stevensc 29
			submitData={{
30
				...data,
31
				title: watch('title'),
32
				employment_type: watch('employment_type'),
33
				last_date_of_application: year,
34
				job_category_id: watch('job_category-id'),
35
				add_location_search: value
36
			}}
37
			title="Nuevo empleo"
38
		>
39
			<div className="form-group">
40
				<label>Título</label>
11143 stevensc 41
				<input className='form-control' type='text' name='title' ref={register({ required: true })} />
11131 stevensc 42
			</div>
43
			<div className="form-group">
44
				<label>Tipo de empleo</label>
45
				<select
46
					className='form-control'
47
					name="employment_type"
48
					ref={register({ required: true })}
49
				>
50
					{
11141 stevensc 51
						jobTypeOptions.map(({ value, label }) => (
11131 stevensc 52
							<option key={value} value={value}>{label}</option>
53
						))
54
					}
55
				</select>
56
			</div>
57
			<div className="form-group">
11909 stevensc 58
				<label>Último día de aplicación</label>
11131 stevensc 59
				<Datetime
60
					dateFormat="DD-MM-YYYY"
61
					timeFormat={false}
14216 stevensc 62
					onChange={(e) => {
63
						if (Date.now() > new Date(e.toDate()).getTime()) {
14562 stevensc 64
							setYear(new Date(new Intl.DateTimeFormat('en-EN', year).format()))
14216 stevensc 65
							return dispatch(addNotification({
66
								style: 'danger',
67
								msg: 'La fecha no puede ser igual o anterior a la actual'
68
							}))
69
						}
11131 stevensc 70
						setYear(new Intl.DateTimeFormat({ year: 'numeric', month: 'numeric', day: 'numeric' }).format(e.toDate()))
14216 stevensc 71
					}}
14218 stevensc 72
					initialValue={new Date(new Intl.DateTimeFormat('en-EN', year).format())}
11131 stevensc 73
					inputProps={{ className: 'form-control' }}
74
					closeOnSelect
75
				/>
76
			</div>
77
			<div className="form-group">
78
				<label>Categoría de Empleo</label>
79
				<select
80
					className='form-control'
81
					name="job_category-id"
82
					ref={register({ required: true })}
83
				>
84
					{
11141 stevensc 85
						Object.entries(jobCategoryOptions).map(([value, name]) => (
11131 stevensc 86
							<option key={value} value={value}>{name}</option>
87
						))
88
					}
89
				</select>
90
			</div>
11144 stevensc 91
			<div className="form-group">
92
				<label>Ubicación</label>
93
				<SearchLocationInput
94
					value={value}
95
					setValue={setValue}
96
					googleApiKey={googleApiKey}
97
					updateData={setData}
98
				/>
99
			</div>
11131 stevensc 100
		</SubmitModal >
101
	)
102
}
103
 
104
export default AddModal