diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index d4a5c20b..e1199d79 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -269,6 +269,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 693467df..0850e31c 100644 --- a/web-ui/web-react/src/components/AreasComunes.js +++ b/web-ui/web-react/src/components/AreasComunes.js @@ -15,16 +15,15 @@ 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 = () => { let emptyCommonArea = { _id: null, - dni: '', name: '', - hourMin: '', - hourMax: '', + hourMin: '00:00', + hourMax: '01:00', community_id: '', bookable: '1', bookable_text: '', @@ -32,6 +31,7 @@ const AreasComunes = () => { status_text: '', }; + const [commonAreaList, setCommonAreaList] = useState([]); const [commonArea, setCommonArea] = useState(emptyCommonArea); const [selectedCommonAreas, setSelectedCommonAreas] = useState(null); @@ -44,6 +44,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 +80,74 @@ 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(function (data) { + return data.message; + }) + .then((data) => { + if (data) { + if (data.bookable == '1') { + data.bookable_text = 'Necesaria'; + } else { + data.bookable_text = 'No es necesaria'; + } + + if (data.status == '1') { + data.status_text = 'Activo'; + } else if (data.status == '0') { + data.status_text = 'Inactivo'; + } else { + data.status_text = 'Eliminado'; + } + } + _common_areas.push(data); + + 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); + toast.current.show({ + severity: 'danger', + summary: 'Error', + detail: 'No se pudo registrar el área común', + life: 3000 + }); + + }); + } else { + setSubmitted(true); + } + }; + const deleteCommonArea = () => { fetch('http://localhost:4000/commonArea/deleteCommonArea/' + commonArea._id, { @@ -167,8 +237,6 @@ const AreasComunes = () => { setDeleteCommonAreasDialog(true); }; - - const actionsCommonArea = (rowData) => { return (
@@ -181,6 +249,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 +358,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 +387,18 @@ 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 (
@@ -341,6 +433,124 @@ 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 && 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 + )} +
+
+
+ +
+
+ + + +
+
+ + +
+
+
+ + +
+
+
+
);