validaciones de comparacion para las horas

que la hora de apertura no sea mayor a la de cierre
This commit is contained in:
Mariela 2022-08-02 12:09:00 -06:00
parent 89134ec7a6
commit e449b28e87
1 changed files with 29 additions and 17 deletions

View File

@ -83,8 +83,7 @@ const AreasComunes = () => {
const saveCommonArea = () => { const saveCommonArea = () => {
if ( if (
commonArea.name && commonArea.name &&
commonArea.hourMin && commonArea.hourMin < commonArea.hourMax
commonArea.hourMax
) { ) {
let _common_areas = [...commonAreaList]; let _common_areas = [...commonAreaList];
let _common_area = { ...commonArea }; let _common_area = { ...commonArea };
@ -104,23 +103,26 @@ const AreasComunes = () => {
console.log('Ocurrió un error con el servicio: ' + response.status); console.log('Ocurrió un error con el servicio: ' + response.status);
else return response.json(); else return response.json();
}) })
.then(function (data) {
return data.message;
})
.then((data) => { .then((data) => {
if (data) { if (data) {
if (_common_area.bookable == '1') { if (data.bookable == '1') {
_common_area.bookable_text = 'Necesaria'; data.bookable_text = 'Necesaria';
} else { } else {
_common_area.bookable_text = 'No es necesaria'; data.bookable_text = 'No es necesaria';
} }
if (_common_area.status == '1') { if (data.status == '1') {
_common_area.status_text = 'Activo'; data.status_text = 'Activo';
} else if (_common_area.status == '0') { } else if (data.status == '0') {
_common_area.status_text = 'Inactivo'; data.status_text = 'Inactivo';
} else { } else {
_common_area.status_text = 'Eliminado'; data.status_text = 'Eliminado';
} }
} }
_common_areas.push(_common_area); _common_areas.push(data);
toast.current.show({ toast.current.show({
severity: 'success', 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 ( return (
<div className="grid"> <div className="grid">
@ -452,11 +464,11 @@ const AreasComunes = () => {
required required
autoFocus autoFocus
className={classNames({ className={classNames({
'p-invalid': submitted && commonArea.hourMin === '', 'p-invalid': submitted && compareTimesMinRequired(commonArea.hourMax, commonArea.hourMin),
})} })}
/> />
{submitted && commonArea.hourMin === '' && ( {submitted && compareTimesMinRequired(commonArea.hourMax, commonArea.hourMin) && (
<small className="p-invalid">Hora de apertura es requirido.</small> <small className="p-invalid">La hora de apertura debe ser menor que la hora de cierre.</small>
)} )}
</div> </div>
<div className="field col-12 md:col-6"> <div className="field col-12 md:col-6">
@ -470,11 +482,11 @@ const AreasComunes = () => {
required required
autoFocus autoFocus
className={classNames({ className={classNames({
'p-invalid': submitted && commonArea.hourMax === '', 'p-invalid': submitted && compareTimesMinRequired(commonArea.hourMax, commonArea.hourMin),
})} })}
/> />
{submitted && commonArea.hourMax === '' && ( {submitted && compareTimesMinRequired(commonArea.hourMax, commonArea.hourMin) && (
<small className="p-invalid">Hora de apertura es requirido.</small> <small className="p-invalid">La hora de cierre debe ser mayor que la hora de apertura</small>
)} )}
</div> </div>
<div className="field col-12 md:col-6"> <div className="field col-12 md:col-6">