From 112813c216ca76d5ce16674f5afe5fecae631a3b Mon Sep 17 00:00:00 2001 From: Traym17 <51390112+Traym17@users.noreply.github.com> Date: Mon, 1 Aug 2022 23:37:10 -0600 Subject: [PATCH] =?UTF-8?q?Agregaci=C3=B3n=20de=20los=20botones=20para=20a?= =?UTF-8?q?ctualizar=20y=20desactivar=20una=20comunidad=20de=20viviendas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/ComunidadViviendas.js | 177 +++++++++++++++++- 1 file changed, 173 insertions(+), 4 deletions(-) diff --git a/web-ui/web-react/src/components/ComunidadViviendas.js b/web-ui/web-react/src/components/ComunidadViviendas.js index db3da58b..bb4e549d 100644 --- a/web-ui/web-react/src/components/ComunidadViviendas.js +++ b/web-ui/web-react/src/components/ComunidadViviendas.js @@ -45,6 +45,7 @@ const Communities = () => { const [globalFilter, setGlobalFilter] = useState(null); const [deleteCommunityDialog, setDeleteCommunityDialog] = useState(false); const [deleteCommunitiesDialog, setDeleteCommunitiesDialog] = useState(false); + const [editCommunityDialog, setEditCommunityDialog] = useState(false); const toast = useRef(null); const dt = useRef(null); @@ -54,7 +55,6 @@ const Communities = () => { const [tenants, setTenants] = useState([]); const [communityDialog, setCommunityDialog] = useState(false); - const [editcommunityDialog, setEditCommunityDialog] = useState(false); @@ -315,6 +315,93 @@ const Communities = () => { setEditCommunityDialog(true); }; + const hideEditCommunityDialog = () => { + setEditCommunityDialog(false); + }; + + const confirmEditCommunity = (community) => { + setCommunity(community); + setEditCommunityDialog(true); + }; + //desactivar o activar una comunidad + const cambiarDesactivarEstadoCommunity = () => { + var data = { + id: community._id, + status: "0", + }; + console.log(data); + + fetch('http://localhost:4000/community/changeStatus', { + cache: 'no-cache', + method: 'POST', + body: JSON.stringify(data), + 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) { + setEditCommunityDialog(false); + toast.current.show({ + severity: 'success', + summary: 'Éxito', + detail: 'Comunidad de Viviendas Actualizada', + life: 3000, + }); + } + ) + .catch( + err => console.log('Ocurrió un error con el fetch', err) + ); + } + //desactivar o activar una comunidad + const cambiarActivarEstadoCommunity = () => { + var data = { + id: community._id, + status: "1", + }; + console.log(data); + fetch('http://localhost:4000/community/changeStatus', { + cache: 'no-cache', + method: 'POST', + body: JSON.stringify(data), + 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) { + setEditCommunityDialog(false); + toast.current.show({ + severity: 'success', + summary: 'Éxito', + detail: 'Comunidad de Viviendas Actualizada', + life: 3000, + }); + } + ) + .catch( + err => console.log('Ocurrió un error con el fetch', err) + ); + } + + const deleteCommunity = () => { /* fetch('http://localhost:4000/community/deleteCommunity/' + community._id, { cache: 'no-cache', @@ -387,14 +474,24 @@ const Communities = () => { const actionsCommunity = (rowData) => { return (