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 (