From fa4dc9f410180a46e2430943d594a76ad954c9bd Mon Sep 17 00:00:00 2001 From: Mariela Date: Tue, 2 Aug 2022 00:00:55 -0600 Subject: [PATCH] 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. + )} +
+
+ +
+
+ + +
+
+ + +
+
+
+ + +
+
+
+
);