Rev 9791 | Rev 9812 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
import React, { useState } from 'react'
import { useForm } from 'react-hook-form'
import Datetime from 'react-datetime'
import SearchLocationInput from '../../../shared/SearchLocationInput'
import "react-datetime/css/react-datetime.css"
import DescriptionInput from '../../../shared/DescriptionInput'
import { useHistory } from 'react-router-dom'
const FormView = ({ actionLink, googleApiKey }) => {
const { handleSubmit, register, setValue } = useForm()
const [location, setLocation] = useState({})
const [isActive, setIsActive] = useState(false)
const [year, setYear] = useState(new Date())
const [locationLabel, setLocationLabel] = useState('')
const [jobsDescriptions, setJobsDescriptions] = useState([
{
value: "8ff86a9a-651c-4dd0-86c1-b9c0716d09e0",
label: "Programador Junior"
}
])
const [jobsCategory, setJobsCategory] = useState([
{
value: "7bd009b8-bd25-4602-bf85-9496af80afbd",
label: "Finanzas"
}
])
const [industry, setIndustry] = useState([
{
value: "307c261f-2d27-4b3c-a86a-6f69a596edb8",
label: "Bienes raíces"
}
])
const onSubmit = (data) => {
console.log(data)
}
return (
<section className="container">
<div className="row">
<div className="col-xs-12 col-md-12">
<form onSubmit={handleSubmit(onSubmit)}>
<div className="form-group">
<label>Nombre</label>
<input
type="text"
name="name"
className="form-control"
ref={register({ required: true, maxLength: 120 })}
/>
</div>
<div className="form-group">
<label>Cargo a evaluar</label>
<select name="job_description_id" className="form-control" ref={register({ required: true })}>
{
jobsDescriptions.map(({ label, value }) => (
<option value={value}>{label}</option>
))
}
</select>
</div>
<div className="form-group">
<label>Categoría de Empleo</label>
<select name="job_category_id" className="form-control" ref={register({ required: true })}>
{
jobsCategory.map(({ label, value }) => (
<option value={value}>{label}</option>
))
}
</select>
</div>
<div className="form-group">
<label>Ubicación</label>
<SearchLocationInput
value={locationLabel}
setValue={setLocationLabel}
googleApiKey={googleApiKey}
updateData={setLocation}
/>
</div>
<div className="form-group">
<label>Industria</label>
<select name="industry_id" className="form-control" ref={register({ required: true })}>
{
industry.map(({ label, value }) => (
<option value={value}>{label}</option>
))
}
</select>
</div>
<div className="form-group">
<label>Último día de aplicación</label>
<Datetime
dateFormat="DD-MM-YYYY"
timeFormat={false}
onChange={(e) =>
setYear(new Intl.DateTimeFormat({ year: 'numeric', month: 'numeric', day: 'numeric' }).format(e.toDate()))
}
inputProps={{ className: 'form-control' }}
closeOnSelect
/>
</div>
<div className="form-group">
<label>Descripción</label>
<DescriptionInput
setValue={setValue}
name="description"
/>
</div>
<div className="form-group">
<label>Estatus</label>
<div
className={`toggle btn btn-block btn-primary ${!isActive && "off"}`}
data-toggle="toggle"
role="button"
style={{ width: '130px' }}
onClick={() => setIsActive(!isActive)}
>
<input
type="checkbox"
checked={isActive}
/>
<div className="toggle-group">
<label for="status" className="btn btn-primary toggle-on">Activo</label>
<label for="status" className="btn btn-light toggle-off">Inactivo</label>
<span className="toggle-handle btn btn-light"></span>
</div>
</div>
</div>
<div className="form-group">
<button
type="submit"
className="btn btn-primary btn-form-save-close"
>
Guardar
</button>
<button
type="button"
className="btn btn-secondary btn-edit-cancel"
onClick={() => useHistory().goBack()}
>
Cancelar
</button>
</div>
</form>
</div>
</div>
</section>
)
}
export default FormView