From 2bce41dbc041b7c9251c46b8b124ca8fa488fb5f Mon Sep 17 00:00:00 2001 From: Mariela Date: Fri, 26 Aug 2022 00:02:17 -0600 Subject: [PATCH] change manejo de fechas --- .../web-react/src/components/Reservaciones.js | 79 +++++++++++-------- 1 file changed, 47 insertions(+), 32 deletions(-) diff --git a/web-ui/web-react/src/components/Reservaciones.js b/web-ui/web-react/src/components/Reservaciones.js index 90792960..c2868498 100644 --- a/web-ui/web-react/src/components/Reservaciones.js +++ b/web-ui/web-react/src/components/Reservaciones.js @@ -17,8 +17,8 @@ import { useCookies } from 'react-cookie'; const Reservations = () => { let emptyReservation = { _id: null, - start_time: '', - finish_time: '', + date: '', + time: '', user_id: '', user_name: '', common_area_id: '', @@ -71,8 +71,12 @@ const Reservations = () => { .then(data => data.message) .then(data => { data = data.filter( - (val) => val.status != -1, + (val) => val.status != -1 ) + data = data.filter( + (val) => val.bookable == 1, + ) + setAreas(data) }); } @@ -209,7 +213,7 @@ const Reservations = () => {

{' '} - Hora de Apertura + Fecha de Reserva

); @@ -219,7 +223,7 @@ const Reservations = () => {

{' '} {' '} - Hora de Cierre + Hora de Reserva

); @@ -283,7 +287,7 @@ const Reservations = () => { const handleTenants = (e) => { const getTenantId = e.target.value; - setAreaId(getTenantId); + setTenantId(getTenantId); } const aList = areas.map((item) => ({ @@ -305,14 +309,19 @@ const Reservations = () => { return date.toISOString() } - function validateTime(timeStart, timeFinish) { - if ((timeFinish - timeStart) == 1) { - return ( - <> - La hora de inicio debe ser la hora . - - ) + function validationTime() { + let value = true; + const [hourR, minuteR] = reservation.time.split(':'); + if (hourR != "") { + const [hourMin, minuteMin] = area.hourMin.split(':'); + const [hourMax, minuteMax] = area.hourMax.split(':'); + if ((parseInt(hourR) >= parseInt(hourMin)) && (parseInt(hourR) <= parseInt(hourMax))) { + value = false; + } + } else { + value = false; } + return value; } function convertToTime(timeString) { @@ -448,61 +457,67 @@ const Reservations = () => { {area && <>
- +
onInputChange(e, 'start_time')} + id="date" + onChange={(e) => onInputChange(e, 'date')} required autoFocus - min={area.hourMin} - max={area.hourMax} - type="time" + min={Date()} + type="date" lang='es' - value={reservation.start_time} + value={reservation.date} className={classNames({ - 'p-invalid': submitted && reservation.start_time === '', + 'p-invalid': submitted && reservation.date === '', })} /> +
- {submitted && reservation.start_time === '' && ( - Nombre es requirido. + {submitted && reservation.date === '' && ( + Fecha es requirida. )}
- +
onInputChange(e, 'finish_time')} + id="time" + value={reservation.time} + onChange={(e) => onInputChange(e, 'time')} required autoFocus type="time" + step='3600' className={classNames({ - 'p-invalid': submitted && reservation.finish_time === '', + 'p-invalid': submitted && (reservation.time === '' || validationTime()), })} />
- {submitted && reservation.finish_time === '' && ( - Nombre es requirido. + {submitted && reservation.time === '' && ( + Hora es requirido. )} + {submitted && validationTime() && ( + La hora de inicio debe set mayor de {area.hourMin} y menor de {area.hourMax} . + )} + +
}
- +
@@ -510,7 +525,7 @@ const Reservations = () => {