From e449b28e873f0c0a0464d73eb765993b58bdb9dc Mon Sep 17 00:00:00 2001 From: Mariela Date: Tue, 2 Aug 2022 12:09:00 -0600 Subject: [PATCH] validaciones de comparacion para las horas que la hora de apertura no sea mayor a la de cierre --- .../web-react/src/components/AreasComunes.js | 46 ++++++++++++------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/web-ui/web-react/src/components/AreasComunes.js b/web-ui/web-react/src/components/AreasComunes.js index fca6f1e7..d539bc40 100644 --- a/web-ui/web-react/src/components/AreasComunes.js +++ b/web-ui/web-react/src/components/AreasComunes.js @@ -83,8 +83,7 @@ const AreasComunes = () => { const saveCommonArea = () => { if ( commonArea.name && - commonArea.hourMin && - commonArea.hourMax + commonArea.hourMin < commonArea.hourMax ) { let _common_areas = [...commonAreaList]; let _common_area = { ...commonArea }; @@ -104,23 +103,26 @@ const AreasComunes = () => { console.log('OcurriĆ³ un error con el servicio: ' + response.status); else return response.json(); }) + .then(function (data) { + return data.message; + }) .then((data) => { if (data) { - if (_common_area.bookable == '1') { - _common_area.bookable_text = 'Necesaria'; + if (data.bookable == '1') { + data.bookable_text = 'Necesaria'; } else { - _common_area.bookable_text = 'No es necesaria'; + data.bookable_text = 'No es necesaria'; } - if (_common_area.status == '1') { - _common_area.status_text = 'Activo'; - } else if (_common_area.status == '0') { - _common_area.status_text = 'Inactivo'; + if (data.status == '1') { + data.status_text = 'Activo'; + } else if (data.status == '0') { + data.status_text = 'Inactivo'; } else { - _common_area.status_text = 'Eliminado'; + data.status_text = 'Eliminado'; } } - _common_areas.push(_common_area); + _common_areas.push(data); toast.current.show({ severity: 'success', @@ -386,6 +388,16 @@ const AreasComunes = () => { }; + function compareTimesMinRequired(hour1, hour2){ + var timeFormat1 = Number(hour1.replace(/[:]/g,'')); + var timeFormat2 = Number(hour2.replace(/[:]/g,'')); + if(timeFormat1 <= timeFormat2){ + return true; + } else { + return false; + } + } + return (
@@ -452,11 +464,11 @@ const AreasComunes = () => { required autoFocus className={classNames({ - 'p-invalid': submitted && commonArea.hourMin === '', + 'p-invalid': submitted && compareTimesMinRequired(commonArea.hourMax, commonArea.hourMin), })} /> - {submitted && commonArea.hourMin === '' && ( - Hora de apertura es requirido. + {submitted && compareTimesMinRequired(commonArea.hourMax, commonArea.hourMin) && ( + La hora de apertura debe ser menor que la hora de cierre. )}
@@ -470,11 +482,11 @@ const AreasComunes = () => { required autoFocus className={classNames({ - 'p-invalid': submitted && commonArea.hourMax === '', + 'p-invalid': submitted && compareTimesMinRequired(commonArea.hourMax, commonArea.hourMin), })} /> - {submitted && commonArea.hourMax === '' && ( - Hora de apertura es requirido. + {submitted && compareTimesMinRequired(commonArea.hourMax, commonArea.hourMin) && ( + La hora de cierre debe ser mayor que la hora de apertura )}