From c5dfdb480d0a980e559f75e0a0b505b14b0f4a26 Mon Sep 17 00:00:00 2001 From: Mariela Date: Mon, 1 Aug 2022 00:31:52 -0600 Subject: [PATCH] listar areas comunes en parte web --- .../web-react/src/components/AreasComunes.js | 250 +++++++++++++++++- 1 file changed, 248 insertions(+), 2 deletions(-) diff --git a/web-ui/web-react/src/components/AreasComunes.js b/web-ui/web-react/src/components/AreasComunes.js index 421c7cc1..51a3746c 100644 --- a/web-ui/web-react/src/components/AreasComunes.js +++ b/web-ui/web-react/src/components/AreasComunes.js @@ -36,9 +36,10 @@ const AreasComunes = () => { status: '1' }; - const [commonAreasList, setCommonAreasList] = useState([]); + const [commonAreaList, setCommonAreaList] = useState([]); const [commonArea, setCommonArea] = useState(emptyCommonArea); const [selectedCommonAreas, setSelectedCommonAreas] = useState(null); + const [globalFilter, setGlobalFilter] = useState(null); const [deleteCommonAreaDialog, setDeleteCommonAreaDialog] = useState(false); const [deleteCommonAreasDialog, setDeleteCommonAreasDialog] = useState(false); const [submitted, setSubmitted] = useState(false); @@ -48,9 +49,254 @@ 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()) + .then(data => data.message) + .then(data => { + setCommonAreaList(data) + }); } + useEffect(() => { + getCommonAreas(); + }, []); + + + const deleteCommonArea = () => { + /* fetch('http://localhost:4000/community/deleteCommunity/' + community._id, { + cache: 'no-cache', + method: 'DELETE', + 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 (response) { + + let _community = communities.filter(val => val._id !== community._id); + setCommunities(_community); + setDeleteCommunityDialog(false); + setCommunity(emptyCommunity); + toast.current.show({ severity: 'success', summary: 'Exito', detail: 'Comunidad de Viviendas Eliminada', life: 3000 }); + } + ) + .catch( + err => { + console.log('Ocurrió un error con el fetch', err) + toast.current.show({ severity: 'danger', summary: 'Error', detail: 'Comunidad de Viviendas no se pudo eliminar', life: 3000 }); + } + ); + */ + let _common_areas = commonAreaList.filter( + (val) => val._id !== commonArea._id, + ); + setCommonAreaList(_common_areas); + setDeleteCommonAreaDialog(false); + setCommonArea(emptyCommonArea); + toast.current.show({ + severity: 'success', + summary: 'Área Común Eliminada', + life: 3000, + }); + }; + + const deleteSelectedCommonAreas = () => { + let _commonareas = commonAreaList.filter( + (val) => !selectedCommonAreas.includes(val), + ); + /* selectedCommunities.map((item) => { + fetch('http://localhost:4000/user/deleteCommunity/' + item._id, { + cache: 'no-cache', + method: 'DELETE', + headers: { + 'Content-Type': 'application/json' + } + }) + })*/ + setCommonAreaList(_commonareas); + setDeleteCommonAreasDialog(false); + setSelectedCommonAreas(null); + toast.current.show({ + severity: 'success', + summary: 'Éxito', + detail: 'Áreas Comúnes Eliminadas', + life: 3000, + }); + }; + + const hideDeleteCommonAreaDialog = () => { + setDeleteCommonAreaDialog(false); + } + + const hideDeleteCommonAreasDialog = () => { + setDeleteCommonAreasDialog(false); + } + + const confirmDeleteCommonArea = (commonArea) => { + setCommonArea(commonArea); + setDeleteCommonAreaDialog(true); + } + + const confirmDeleteSelected = () => { + setDeleteCommonAreasDialog(true); + }; + + + + const actionsCommonArea = (rowData) => { + return ( +
+
+ ); + }; + + + const deleteCommonAreaDialogFooter = ( + <> +