From ac1090b097ae6cb36eeeca2f541cd3262379c611 Mon Sep 17 00:00:00 2001 From: Traym17 <51390112+Traym17@users.noreply.github.com> Date: Sun, 24 Jul 2022 13:16:44 -0600 Subject: [PATCH] =?UTF-8?q?Alineaci=C3=B3n=20de=20las=20tablas=20de=20los?= =?UTF-8?q?=20admis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Alineación de las tablas del admin del sistema y del admin de las comunidades --- .../components/AdministradoresComunidad.js | 187 +++++++++++++++++- .../src/components/AdministradoresSistema.js | 4 +- 2 files changed, 179 insertions(+), 12 deletions(-) diff --git a/web-ui/web-react/src/components/AdministradoresComunidad.js b/web-ui/web-react/src/components/AdministradoresComunidad.js index 22eb4cc8..769ff58c 100644 --- a/web-ui/web-react/src/components/AdministradoresComunidad.js +++ b/web-ui/web-react/src/components/AdministradoresComunidad.js @@ -1,13 +1,36 @@ -import React, { useEffect, useState } from 'react'; +import React, { useEffect, useState, useRef } from 'react'; import { InputText } from 'primereact/inputtext'; import { Button } from 'primereact/button'; import { DataTable } from 'primereact/datatable'; import { Column } from 'primereact/column'; +import { Toast } from 'primereact/toast'; +import { Dialog } from 'primereact/dialog'; +import { Toolbar } from 'primereact/toolbar'; const AdministradoresComunidad = () => { const [listaAdmins,setListaAdmins]=useState([]); const [listaAdminComunidad,setListaAdminComunidad]=useState([]); + const [sysadmin, setSysAdmin] = useState(emptySysAdmin); + const [selectedAdministrators, setSelectedAdministrators] = useState(null); + const [globalFilter, setGlobalFilter] = useState(null); + const [deleteAdminSystemDialog, setDeleteAdminSystemDialog] = useState(false); + const [deleteAdminsSystemDialog, setDeleteAdminsSystemDialog] = useState(false); + const toast = useRef(null); + const dt = useRef(null); + + let emptySysAdmin = { + _id: null, + dni: '', + name: '', + last_name: '', + email: '', + phone: '', + password: '', + user_type: '1', + status: '' + }; + async function listaAdmin(){ let nombres=await fetch('http://localhost:4000/user/findAdminComunidad/', {method:'GET'}); @@ -28,23 +51,167 @@ const AdministradoresComunidad = () => { listaAdmin(); },[]) + const hideDeleteAdminSystemDialog = () => { + setDeleteAdminSystemDialog(false); + } + + const hideDeleteAdminsSystemsDialog = () => { + setDeleteAdminsSystemDialog(false); + } + + const confirmDeleteAdminSystem = (sysAdmin) => { + setSysAdmin(sysAdmin); + setDeleteAdminSystemDialog(true); + } + + const confirmDeleteSelected = () => { + setDeleteAdminsSystemDialog(true); + } + + const deleteSysAdmin = () => { + + 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 = listaAdmins.filter(val => val._id !== sysadmin._id); + setListaAdmins(_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 }); + } + ); + } + + const deleteSelectedAdminsSystem = () => { + let _administrators = listaAdmins.filter(val => !selectedAdministrators.includes(val)); + selectedAdministrators.map((item) => { + fetch('http://localhost:4000/user/deleteAdminSystem/' + item._id, { + cache: 'no-cache', + method: 'DELETE', + headers: { + 'Content-Type': 'application/json' + } + }) + }) + setListaAdmins(_administrators); + setDeleteAdminsSystemDialog(false); + setSelectedAdministrators(null); + toast.current.show({ severity: 'success', summary: 'Successful', detail: 'Products Deleted', life: 3000 }); + } + + + const actionsAdmin = (rowData) => { + return ( +
+
+ ); + } + + const leftToolbarTemplate = () => { + return ( + +
+
+
+ ) + } + + const rightToolbarTemplate = () => { + return ( + +