diff --git a/web-ui/web-react/src/components/GuardasSeguridad.js b/web-ui/web-react/src/components/GuardasSeguridad.js index 836d8647..e7ff5192 100644 --- a/web-ui/web-react/src/components/GuardasSeguridad.js +++ b/web-ui/web-react/src/components/GuardasSeguridad.js @@ -1,139 +1,321 @@ -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'; +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' +import { faUserAlt } from '@fortawesome/free-solid-svg-icons'; +import { faPhoneAlt } from '@fortawesome/free-solid-svg-icons'; +import { faAt } from '@fortawesome/free-solid-svg-icons'; +import { faIdCardAlt } from '@fortawesome/free-solid-svg-icons'; +import { faEllipsis } from '@fortawesome/free-solid-svg-icons'; const GuardasSeguridad = () => { - const [pokemones, setPokemones] = useState([]); - const [urlFetch, setUrlFetch] = useState( - 'http://localhost:4000/user/findGuards/62be68215692582bbfd77134', - ); - async function fetchP() { - let nombres = await fetch(urlFetch, { method: 'GET' }); - let pokemonesRes = await nombres.json(); - setPokemones(pokemonesRes.message); - console.log(pokemones); - } - useEffect(() => { - fetchP(); - }, []); - - function registrarGuarda() { - var data = { - dni: document.getElementById('identificacion').value, - name: document.getElementById('nombre').value, - last_name: document.getElementById('apellidos').value, - email: document.getElementById('correo_electronico').value, - phone: document.getElementById('telefono').value, - password: document.getElementById('correo_electronico').value, - user_type: '4', //4 es guarda - status: '1', - community_id: '62be68215692582bbfd77134', + const [listaGuardas,setListaGuardas]=useState([]); + const [urlFetch,setUrlFetch]=useState('http://localhost:4000/user/findGuards/62be68215692582bbfd77134'); + const [guarda, setGuarda] = useState(emptyGuarda); + const [selectedGuardas, setSelectedGuardas] = useState(null); + const [globalFilter, setGlobalFilter] = useState(null); + const [deleteGuardaDialog, setDeleteGuardaDialog] = useState(false); + const [deleteGuardasDialog, setDeleteGuardasDialog] = useState(false); + const toast = useRef(null); + const dt = useRef(null); + let emptyGuarda = { + _id: null, + dni: '', + name: '', + last_name: '', + email: '', + phone: '', + password: '', + user_type: '1', + status: '' }; - var data2 = { - dni: '98765', - name: 'Danielito', - last_name: 'Rodriguez', - email: 'danirodriguez@gmail.com', - phone: 84664515, - password: '1203', - user_type: '2', - status: '4', - community_id: '62be68215692582bbfd77134', - }; - console.log(data2); - fetch('http://localhost:4000/user/createGuard', { - cache: 'no-cache', - method: 'POST', - mode: 'cors', - body: JSON.stringify(data2), - 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) { - fetchP(); - }) - .catch((err) => console.log('Ocurrió un error con el fetch', err)); - } - return ( -
-
-
-
Guardas de seguridad
- - - - - - - + + async function listaGuardasF(){ + let nombres=await fetch(urlFetch, {method:'GET'}); + let listaGuardasRes= await nombres.json(); + setListaGuardas(listaGuardasRes.message); + } + useEffect(()=>{ + listaGuardasF(); + },[]) + + function registrarGuarda() { + var data = { + dni: document.getElementById('identificacion').value, + name: document.getElementById('nombre').value, + last_name: document.getElementById('apellidos').value, + email: document.getElementById('correo_electronico').value, + phone: document.getElementById('telefono').value, + password: document.getElementById('correo_electronico').value, + user_type: "4", //4 es guarda + status: "1", + community_id:"62be68215692582bbfd77134" + }; + var data2={ + dni: "11979037", + name: "Jorge", + last_name: "Soto", + email: "jorgesoto@gmail.com", + phone: 84664515, + password: "1203", + user_type: "2", + status: "4", + community_id:"62be68215692582bbfd77134" + } +console.log('ssss'); + fetch('http://localhost:4000/user/createGuard', { + cache: 'no-cache', + method: 'POST', + mode:'cors', + body: JSON.stringify(data2), + 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) { + console.log('fff'); + listaGuardasF(); + } + ) + .catch( + err => console.log('Ocurrió un error con el fetch', err) + ); + } + + const hideDeleteGuardaDialog = () => { + setDeleteGuardaDialog(false); + } + + const hideDeleteGuardasDialog = () => { + setDeleteGuardasDialog(false); + } + + const confirmDeleteGuarda = (guarda) => { + setGuarda(guarda); + setDeleteGuardaDialog(true); + } + + const confirmDeleteSelected = () => { + setDeleteGuardasDialog(true); + } + + const deleteGuarda = () => { + + fetch('http://localhost:4000/user/deleteAdminSystem/' + guarda._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 _guarda = listaGuardas.filter(val => val._id !== guarda._id); + setListaGuardas(_guarda); + setDeleteGuardaDialog(false); + setGuarda(emptyGuarda); + toast.current.show({ severity: 'success', summary: 'Éxito', 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 deleteSelectedGuardas = () => { + let _guardas = listaGuardas.filter(val => !selectedGuardas.includes(val)); + selectedGuardas.map((item) => { + fetch('http://localhost:4000/user/deleteAdminSystem/' + item._id, { + cache: 'no-cache', + method: 'DELETE', + headers: { + 'Content-Type': 'application/json' + } + }) + }) + setListaGuardas(_guardas); + setDeleteGuardasDialog(false); + setSelectedGuardas(null); + toast.current.show({ severity: 'success', summary: 'Éxito', detail: 'Administradores del Sistema Eliminados', life: 3000 }); + } + + const actionsAdmin = (rowData) => { + return ( +
+
+ ); + } + + const leftToolbarTemplate = () => { + return ( + +
+
+
+ ) + } + + const rightToolbarTemplate = () => { + return ( + +
-
-
-
Registro de un guarda de seguridad
-
-
- - + ); + + const deleteAdminSystemDialogFooter = ( + <> + +
+
-
- - -
-
- - -
-
- - -
- -
-
- ); };