From fa4dc9f410180a46e2430943d594a76ad954c9bd Mon Sep 17 00:00:00 2001 From: Mariela Date: Tue, 2 Aug 2022 00:00:55 -0600 Subject: [PATCH 1/5] formulario de registro --- .../web-react/src/components/AreasComunes.js | 171 +++++++++++++++++- 1 file changed, 167 insertions(+), 4 deletions(-) diff --git a/web-ui/web-react/src/components/AreasComunes.js b/web-ui/web-react/src/components/AreasComunes.js index 693467df..6eff36e4 100644 --- a/web-ui/web-react/src/components/AreasComunes.js +++ b/web-ui/web-react/src/components/AreasComunes.js @@ -15,7 +15,7 @@ import { faIdCardAlt } from '@fortawesome/free-solid-svg-icons'; import { faClipboardCheck } from '@fortawesome/free-solid-svg-icons'; import classNames from 'classnames'; import { useCookies } from "react-cookie"; - +import { RadioButton } from 'primereact/radiobutton'; const AreasComunes = () => { @@ -32,6 +32,7 @@ const AreasComunes = () => { status_text: '', }; + const [commonAreaList, setCommonAreaList] = useState([]); const [commonArea, setCommonArea] = useState(emptyCommonArea); const [selectedCommonAreas, setSelectedCommonAreas] = useState(null); @@ -44,6 +45,8 @@ const AreasComunes = () => { const [cookies, setCookie] = useCookies(); + + async function getCommonAreas() { await fetch(`http://localhost:4000/commonArea/findByCommunity/${cookies.community_id}`, { method: 'GET' }) .then((response) => response.json()) @@ -78,6 +81,71 @@ const AreasComunes = () => { getCommonAreas(); }, []); + const saveCommonArea = () => { + if ( + commonArea.name && + commonArea.hourMin && + commonArea.hourMax + ) { + let _common_areas = [...commonAreaList]; + let _common_area = { ...commonArea }; + _common_area.community_id = cookies.community_id; + + // console.log(houses) + fetch('http://localhost:4000/commonArea/createCommonArea', { + cache: 'no-cache', + method: 'POST', + body: JSON.stringify(_common_area), + headers: { + 'Content-Type': 'application/json', + }, + }) + .then(function (response) { + if (response.status != 201) + console.log('Ocurrió un error con el servicio: ' + response.status); + else return response.json(); + }) + .then((data) => { + + if (data) { + data.map(item => { + if (item.bookable == '1') { + item.bookable_text = 'Necesaria'; + } else { + item.bookable_text = 'No es necesarioa'; + } + + if (item.status == '1') { + item.status_text = 'Activo'; + } else if (item.status == '0') { + item.status_text = 'Inactivo'; + } else { + item.status_text = 'Eliminado'; + } + }) + } + + _common_area = data.filter( + (val) => val.status != -1, + ) + + _common_areas.push(_common_area); + toast.current.show({ + severity: 'success', + summary: 'Registro exitoso', + detail: 'Área Común Creada', + life: 3000, + }); + + setCommonAreaList(_common_areas); + setCommonArea(emptyCommonArea); + }) + .catch((err) => console.log('Ocurrió un error con el fetch', err)); + } else { + setSubmitted(true); + } + }; + const deleteCommonArea = () => { fetch('http://localhost:4000/commonArea/deleteCommonArea/' + commonArea._id, { @@ -167,8 +235,6 @@ const AreasComunes = () => { setDeleteCommonAreasDialog(true); }; - - const actionsCommonArea = (rowData) => { return (
@@ -181,6 +247,18 @@ const AreasComunes = () => { ); }; + const onBookableChange = (e) => { + let _commonArea = { ...commonArea }; + _commonArea['bookable'] = e.value; + setCommonArea(_commonArea); + }; + + const onInputChange = (e, name) => { + const val = (e.target && e.target.value) || ''; + let _commonArea = { ...commonArea }; + _commonArea[`${name}`] = val; + setCommonArea(_commonArea); + }; const deleteCommonAreaDialogFooter = ( <> @@ -278,7 +356,7 @@ const AreasComunes = () => { const bookableBodyTemplate = (rowData) => { let class_color = ''; - if(rowData.bookable == '1') { + if (rowData.bookable == '1') { class_color = '0'; } else { class_color = '1'; @@ -307,6 +385,8 @@ const AreasComunes = () => { ); }; + + return (
@@ -341,6 +421,89 @@ const AreasComunes = () => {
+
+
+
Registro de área común
+
+
+ + onInputChange(e, 'name')} + value={commonArea.name} + required + autoFocus + className={classNames({ + 'p-invalid': submitted && commonArea.name === '', + })} + /> + {submitted && commonArea.name === '' && ( + Nombre es requirido. + )} +
+
+ + onInputChange(e, 'hourMin')} + value={commonArea.hourMin} + required + autoFocus + className={classNames({ + 'p-invalid': submitted && commonArea.hourMin === '', + })} + /> + {submitted && commonArea.hourMin === '' && ( + Hora de apertura es requirido. + )} +
+
+ + onInputChange(e, 'hourMax')} + value={commonArea.hourMax} + required + autoFocus + className={classNames({ + 'p-invalid': submitted && commonArea.hourMax === '', + })} + /> + {submitted && commonArea.hourMax === '' && ( + Hora de apertura es requirido. + )} +
+
+ +
+
+ + +
+
+ + +
+
+
+ + +
+
+
+
); From ac0984d5af24f5ddb46bf0d61d0f670c86620bf9 Mon Sep 17 00:00:00 2001 From: Mariela Date: Tue, 2 Aug 2022 00:13:09 -0600 Subject: [PATCH 2/5] fix error de estado despues de registrar --- api-gateway/src/app.service.ts | 1 + .../web-react/src/components/AreasComunes.js | 48 +++++++++---------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index 52c79492..1ac8513c 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -261,6 +261,7 @@ export class AppService { hourMax: hourMax, bookable: bookable, community_id: community_id, + status: '1' }; return this.clientCommonAreaApp .send(pattern, payload) diff --git a/web-ui/web-react/src/components/AreasComunes.js b/web-ui/web-react/src/components/AreasComunes.js index 6eff36e4..3b40a941 100644 --- a/web-ui/web-react/src/components/AreasComunes.js +++ b/web-ui/web-react/src/components/AreasComunes.js @@ -21,7 +21,6 @@ const AreasComunes = () => { let emptyCommonArea = { _id: null, - dni: '', name: '', hourMin: '', hourMax: '', @@ -106,41 +105,42 @@ const AreasComunes = () => { else return response.json(); }) .then((data) => { - if (data) { - data.map(item => { - if (item.bookable == '1') { - item.bookable_text = 'Necesaria'; - } else { - item.bookable_text = 'No es necesarioa'; - } - - if (item.status == '1') { - item.status_text = 'Activo'; - } else if (item.status == '0') { - item.status_text = 'Inactivo'; - } else { - item.status_text = 'Eliminado'; - } - }) - } - - _common_area = data.filter( - (val) => val.status != -1, - ) + if (_common_area.bookable == '1') { + _common_area.bookable_text = 'Necesaria'; + } else { + _common_area.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'; + } else { + _common_area.status_text = 'Eliminado'; + } + } _common_areas.push(_common_area); + toast.current.show({ severity: 'success', summary: 'Registro exitoso', detail: 'Área Común Creada', life: 3000, }); - setCommonAreaList(_common_areas); setCommonArea(emptyCommonArea); }) - .catch((err) => console.log('Ocurrió un error con el fetch', err)); + .catch((err) => { + console.log('Ocurrió un error con el fetch', err); + toast.current.show({ + severity: 'danger', + summary: 'Error', + detail: 'No se pudo registrar el área común', + life: 3000 + }); + + }); } else { setSubmitted(true); } From 89134ec7a64d2ff2cf7ab69335bbd0fb20163992 Mon Sep 17 00:00:00 2001 From: Mariela Date: Tue, 2 Aug 2022 00:41:12 -0600 Subject: [PATCH 3/5] arreglar inputs de tiempos --- web-ui/web-react/src/components/AreasComunes.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/web-ui/web-react/src/components/AreasComunes.js b/web-ui/web-react/src/components/AreasComunes.js index 3b40a941..fca6f1e7 100644 --- a/web-ui/web-react/src/components/AreasComunes.js +++ b/web-ui/web-react/src/components/AreasComunes.js @@ -22,8 +22,8 @@ const AreasComunes = () => { let emptyCommonArea = { _id: null, name: '', - hourMin: '', - hourMax: '', + hourMin: '00:00', + hourMax: '01:00', community_id: '', bookable: '1', bookable_text: '', @@ -444,7 +444,9 @@ const AreasComunes = () => {
onInputChange(e, 'hourMin')} value={commonArea.hourMin} required @@ -460,7 +462,9 @@ const AreasComunes = () => {
onInputChange(e, 'hourMax')} value={commonArea.hourMax} required From e449b28e873f0c0a0464d73eb765993b58bdb9dc Mon Sep 17 00:00:00 2001 From: Mariela Date: Tue, 2 Aug 2022 12:09:00 -0600 Subject: [PATCH 4/5] 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 )}
From 2499c0ab645dca284775ef2b32e3fbca2d4919c9 Mon Sep 17 00:00:00 2001 From: Mariela Date: Tue, 2 Aug 2022 12:27:38 -0600 Subject: [PATCH 5/5] =?UTF-8?q?fix=20estilos=20de=20formulario=20de=20agre?= =?UTF-8?q?gar=20=C3=A1rea=20com=C3=BAn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web-react/src/components/AreasComunes.js | 131 +++++++++++------- 1 file changed, 81 insertions(+), 50 deletions(-) diff --git a/web-ui/web-react/src/components/AreasComunes.js b/web-ui/web-react/src/components/AreasComunes.js index d539bc40..0850e31c 100644 --- a/web-ui/web-react/src/components/AreasComunes.js +++ b/web-ui/web-react/src/components/AreasComunes.js @@ -388,10 +388,10 @@ const AreasComunes = () => { }; - function compareTimesMinRequired(hour1, hour2){ - var timeFormat1 = Number(hour1.replace(/[:]/g,'')); - var timeFormat2 = Number(hour2.replace(/[:]/g,'')); - if(timeFormat1 <= timeFormat2){ + function compareTimesMinRequired(hour1, hour2) { + var timeFormat1 = Number(hour1.replace(/[:]/g, '')); + var timeFormat2 = Number(hour2.replace(/[:]/g, '')); + if (timeFormat1 <= timeFormat2) { return true; } else { return false; @@ -439,60 +439,83 @@ const AreasComunes = () => {
- onInputChange(e, 'name')} - value={commonArea.name} - required - autoFocus - className={classNames({ - 'p-invalid': submitted && commonArea.name === '', - })} - /> - {submitted && commonArea.name === '' && ( - Nombre es requirido. - )} +
+ +
+ + + + onInputChange(e, 'name')} + value={commonArea.name} + required + autoFocus + className={classNames({ + 'p-invalid': submitted && commonArea.name === '', + })} + /> +
+ {submitted && commonArea.name === '' && ( + Nombre es requirido. + )} +
- onInputChange(e, 'hourMin')} - value={commonArea.hourMin} - required - autoFocus - className={classNames({ - 'p-invalid': submitted && compareTimesMinRequired(commonArea.hourMax, commonArea.hourMin), - })} - /> - {submitted && compareTimesMinRequired(commonArea.hourMax, commonArea.hourMin) && ( - La hora de apertura debe ser menor que la hora de cierre. - )} +
+
+ + + + onInputChange(e, 'hourMin')} + value={commonArea.hourMin} + required + autoFocus + className={classNames({ + 'p-invalid': submitted && compareTimesMinRequired(commonArea.hourMax, commonArea.hourMin), + })} + /> +
+ {submitted && compareTimesMinRequired(commonArea.hourMax, commonArea.hourMin) && ( + La hora de apertura debe ser menor que la hora de cierre. + )} +
- onInputChange(e, 'hourMax')} - value={commonArea.hourMax} - required - autoFocus - className={classNames({ - 'p-invalid': submitted && compareTimesMinRequired(commonArea.hourMax, commonArea.hourMin), - })} - /> - {submitted && compareTimesMinRequired(commonArea.hourMax, commonArea.hourMin) && ( - La hora de cierre debe ser mayor que la hora de apertura - )} +
+
+ + + + onInputChange(e, 'hourMax')} + value={commonArea.hourMax} + required + autoFocus + className={classNames({ + 'p-invalid': submitted && compareTimesMinRequired(commonArea.hourMax, commonArea.hourMin), + })} + /> +
+ {submitted && compareTimesMinRequired(commonArea.hourMax, commonArea.hourMin) && ( + La hora de cierre debe ser mayor que la hora de apertura + )} +
-
+
+ { onChange={onBookableChange} checked={commonArea.bookable === '1'} /> - +
{ onChange={onBookableChange} checked={commonArea.bookable === '0'} /> - +