From 4afbb4388fbe41e22a807a24a54f29dbbf9b4ced Mon Sep 17 00:00:00 2001 From: Mariela Date: Fri, 22 Jul 2022 14:59:59 -0600 Subject: [PATCH 1/8] add functions --- .../src/components/AdministradoresSistema.js | 14 +-- .../src/components/ComunidadViviendas.js | 113 ++++++++++++++++++ 2 files changed, 116 insertions(+), 11 deletions(-) diff --git a/web-ui/web-react/src/components/AdministradoresSistema.js b/web-ui/web-react/src/components/AdministradoresSistema.js index 8a8ea049..58b21b3b 100644 --- a/web-ui/web-react/src/components/AdministradoresSistema.js +++ b/web-ui/web-react/src/components/AdministradoresSistema.js @@ -8,7 +8,7 @@ import { Dialog } from 'primereact/dialog'; import { Toolbar } from 'primereact/toolbar'; const AdministradoresSistema = () => { - +`` const [administrators, setAdministrators] = useState([]); const [urlFetch, setUrlFetch] = useState('http://localhost:4000/user/findAdminSistema/'); const [sysadmin, setSysAdmin] = useState(emptySysAdmin); @@ -19,7 +19,6 @@ const AdministradoresSistema = () => { const toast = useRef(null); const dt = useRef(null); - let emptySysAdmin = { _id: null, dni: '', @@ -123,10 +122,8 @@ const AdministradoresSistema = () => { function (response) { let _sysadmin = administrators.filter(val => val._id !== sysadmin._id); setAdministrators(_sysadmin); - setDeleteAdminSystemDialog(false); setSysAdmin(emptySysAdmin); - toast.current.show({ severity: 'success', summary: 'Exito', detail: 'Administrador del Sistema Eliminado', life: 3000 }); } ) @@ -155,7 +152,6 @@ const AdministradoresSistema = () => { toast.current.show({ severity: 'success', summary: 'Successful', detail: 'Products Deleted', life: 3000 }); } - const actionsAdmin = (rowData) => { return (
@@ -205,14 +201,13 @@ const AdministradoresSistema = () => {
+ ); + } + + const leftToolbarTemplate = () => { + return ( + +
+
+
+ ) + } + + const rightToolbarTemplate = () => { + return ( + + diff --git a/web-ui/web-react/src/components/ComunidadViviendas.js b/web-ui/web-react/src/components/ComunidadViviendas.js index f6beee33..dcee03df 100644 --- a/web-ui/web-react/src/components/ComunidadViviendas.js +++ b/web-ui/web-react/src/components/ComunidadViviendas.js @@ -6,7 +6,7 @@ import { Column } from 'primereact/column'; import { Dropdown } from 'primereact/dropdown'; import { Toast } from 'primereact/toast'; import classNames from 'classnames'; - +import { Toolbar } from 'primereact/toolbar'; const Communities = () => { @@ -36,9 +36,12 @@ const Communities = () => { const [districtId, setDistrictId] = useState(null); const [codeHouses, setCodeHouses] = useState(''); const [submitted, setSubmitted] = useState(false); + const [selectedCommunities, setSelectedCommunities] = useState(null); + const [globalFilter, setGlobalFilter] = useState(null); + const [deleteCommunityDialog, setDeleteCommunityDialog] = useState(false); + const [deleteCommunitiesDialog, setDeleteCommunitiesDialog] = useState(false); const toast = useRef(null); - const dt = useRef(null); - + const dt = useEffect(null); const p = provincesList.map((item) => ({ @@ -157,7 +160,7 @@ const Communities = () => { const saveCommunity = () => { - if (community.name && community.num_houses > 0 && provinciaId && cantonId && districtId && community.phone ) { + if (community.name && community.num_houses > 0 && provinciaId && cantonId && districtId && community.phone) { let _communities = [...communitiesList]; let _community = { ...community }; _community.province = provinciaId; @@ -229,78 +232,85 @@ const Communities = () => { } - const hideDeleteAdminSystemDialog = () => { - setDeleteAdminSystemDialog(false); + const hideDeleteCommunityDialog = () => { + setDeleteCommunityDialog(false); } - const hideDeleteAdminsSystemsDialog = () => { - setDeleteAdminsSystemDialog(false); + const hideDeleteCommunitiesDialog = () => { + setDeleteCommunitiesDialog(false); } - const confirmDeleteAdminSystem = (sysAdmin) => { - setSysAdmin(sysAdmin); - setDeleteAdminSystemDialog(true); + const confirmDeleteCommunity = (community) => { + setCommunity(community); + setDeleteCommunityDialog(true); } const confirmDeleteSelected = () => { - setDeleteAdminsSystemDialog(true); + setDeleteCommunitiesDialog(true); } - const deleteSysAdmin = () => { + const deleteCommunity = () => { - fetch('http://localhost:4000/user/deleteAdminSystem/' + sysadmin._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 _sysadmin = communities.filter(val => val._id !== community._id); - setAdministrators(_sysadmin); - setDeleteAdminSystemDialog(false); - setSysAdmin(emptySysAdmin); - toast.current.show({ severity: 'success', summary: 'Exito', detail: 'Administrador del Sistema Eliminado', life: 3000 }); - } - ) - .catch( - err => { - console.log('Ocurrió un error con el fetch', err) - toast.current.show({ severity: 'danger', summary: 'Error', detail: 'Administrador del Sistema no se pudo eliminar', life: 3000 }); - } - ); + /* 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 _community = communitiesList.filter(val => val._id !== community._id); + setCommunitiesList(_community); + setDeleteCommunityDialog(false); + setCommunity(emptyCommunity); + toast.current.show({ severity: 'success', summary: 'Éxito', detail: 'Comunidad de Viviendas Eliminada', life: 3000 }); } - const deleteSelectedAdminsSystem = () => { - let _communities = communitiesList.filter(val => !selectedAdministrators.includes(val)); - selectedAdministrators.map((item) => { - fetch('http://localhost:4000/user/deleteAdminSystem/' + item._id, { + const deleteSelectedCommunities = () => { + let _communities = communitiesList.filter(val => !selectedCommunities.includes(val)); + /* selectedCommunities.map((item) => { + fetch('http://localhost:4000/user/deleteCommunity/' + item._id, { cache: 'no-cache', method: 'DELETE', headers: { 'Content-Type': 'application/json' } }) - }) + })*/ setCommunitiesList(_communities); - setDeleteAdminsSystemDialog(false); - setSelectedAdministrators(null); - toast.current.show({ severity: 'success', summary: 'Successful', detail: 'Products Deleted', life: 3000 }); + setDeleteCommunitiesDialog(false); + setSelectedCommunities(null); + toast.current.show({ severity: 'success', summary: 'Éxito', detail: 'Comunidades de Viviendas Eliminada', life: 3000 }); } - const actionsAdmin = (rowData) => { + const actionsCommunity = (rowData) => { return (
-
); } @@ -309,7 +319,7 @@ const Communities = () => { return (
-
) @@ -318,14 +328,14 @@ const Communities = () => { const rightToolbarTemplate = () => { return ( -