Cambio de estilo a los guardas de seguridad

This commit is contained in:
Traym17 2022-07-25 19:03:32 -06:00
parent 9089aa8908
commit 8989178ed7
1 changed files with 226 additions and 22 deletions

View File

@ -1,21 +1,50 @@
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState, useRef } from 'react';
import { InputText } from 'primereact/inputtext'; import { InputText } from 'primereact/inputtext';
import { Button } from 'primereact/button'; import { Button } from 'primereact/button';
import { DataTable } from 'primereact/datatable'; import { DataTable } from 'primereact/datatable';
import { Column } from 'primereact/column'; 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 GuardasSeguridad = () => {
const [pokemones,setPokemones]=useState([]); const [listaGuardas,setListaGuardas]=useState([]);
const [urlFetch,setUrlFetch]=useState('http://localhost:4000/user/findGuards/62be68215692582bbfd77134'); const [urlFetch,setUrlFetch]=useState('http://localhost:4000/user/findGuards/62be68215692582bbfd77134');
async function fetchP(){ 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: ''
};
async function listaGuardasF(){
let nombres=await fetch(urlFetch, {method:'GET'}); let nombres=await fetch(urlFetch, {method:'GET'});
let pokemonesRes= await nombres.json(); let listaGuardasRes= await nombres.json();
setPokemones(pokemonesRes.message); setListaGuardas(listaGuardasRes.message);
console.log(pokemones);
} }
useEffect(()=>{ useEffect(()=>{
fetchP(); listaGuardasF();
},[]) },[])
function registrarGuarda() { function registrarGuarda() {
@ -31,18 +60,17 @@ const GuardasSeguridad = () => {
community_id:"62be68215692582bbfd77134" community_id:"62be68215692582bbfd77134"
}; };
var data2={ var data2={
dni: "98765", dni: "11979037",
name: "Danielito", name: "Jorge",
last_name: "Rodriguez", last_name: "Soto",
email: "danirodriguez@gmail.com", email: "jorgesoto@gmail.com",
phone: 84664515, phone: 84664515,
password: "1203", password: "1203",
user_type: "2", user_type: "2",
status: "4", status: "4",
community_id:"62be68215692582bbfd77134" community_id:"62be68215692582bbfd77134"
} }
console.log(data2); console.log('ssss');
fetch('http://localhost:4000/user/createGuard', { fetch('http://localhost:4000/user/createGuard', {
cache: 'no-cache', cache: 'no-cache',
method: 'POST', method: 'POST',
@ -62,7 +90,8 @@ const GuardasSeguridad = () => {
) )
.then( .then(
function (response) { function (response) {
fetchP(); console.log('fff');
listaGuardasF();
} }
) )
.catch( .catch(
@ -70,18 +99,193 @@ const GuardasSeguridad = () => {
); );
} }
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 (
<div className="actions">
<Button icon="pi pi-trash" className="p-button-rounded p-button-danger mt-2" onClick={() => confirmDeleteGuarda(rowData)} />
</div>
);
}
const leftToolbarTemplate = () => {
return (
<React.Fragment>
<div className="my-2">
<Button label="Eliminar" icon="pi pi-trash" className="p-button-danger" onClick={confirmDeleteSelected} disabled={!selectedGuardas || !selectedGuardas.length} />
</div>
</React.Fragment>
)
}
const rightToolbarTemplate = () => {
return (
<React.Fragment>
<Button label="Exportar" icon="pi pi-upload" className="p-button-help" />
</React.Fragment>
)
}
const header = (
<div className="flex flex-column md:flex-row md:justify-content-between md:align-items-center">
<h5 className="m-0">Guardas de seguridad</h5>
<span className="block mt-2 md:mt-0 p-input-icon-left">
<i className="pi pi-search" />
<InputText type="search" onInput={(e) => setGlobalFilter(e.target.value)} placeholder="Buscar..." />
</span>
</div>
);
const deleteAdminSystemDialogFooter = (
<>
<Button label="No" icon="pi pi-times" className="p-button-text" onClick={hideDeleteGuardasDialog} />
<Button label="Yes" icon="pi pi-check" className="p-button-text" onClick={deleteGuarda} />
</>
);
const deleteAdminsSystemDialogFooter = (
<>
<Button label="No" icon="pi pi-times" className="p-button-text" onClick={hideDeleteGuardasDialog} />
<Button label="Yes" icon="pi pi-check" className="p-button-text" onClick={deleteSelectedGuardas} />
</>
);
const headerName = (
<>
<p>Nombre</p>
</>
)
const headerLastName = (
<>
<p>Apellidos</p>
</>
)
const headerDNI = (
<>
<p>Identificación</p>
</>
)
const headerEmail = (
<>
<p>Correo Electrónico</p>
</>
)
const headerPhone = (
<>
<p>Teléfono</p>
</>
)
const headerOptions = (
<>
<p>Opciones</p>
</>
)
return ( return (
<div className="grid"> <div className="grid">
<div className="col-12"> <div className="col-12">
<Toast ref={toast} />
<div className="card"> <div className="card">
<h5>Guardas de seguridad</h5> <Toolbar className="mb-4" left={leftToolbarTemplate} right={rightToolbarTemplate}></Toolbar>
<DataTable value={pokemones} scrollable scrollHeight="400px" scrollDirection="both" className="mt-3"> <DataTable ref={dt} value={listaGuardas} dataKey="_id" paginator rows={5} selection={selectedGuardas} onSelectionChange={(e) => setSelectedGuardas(e.value)}
<Column field="name" header="Nombre" style={{ flexGrow: 1, flexBasis: '160px' }}></Column> responsiveLayout="scroll" header={header}
<Column field="last_name" header="Apellidos" style={{ flexGrow: 1, flexBasis: '160px' }} alignFrozen="left"></Column> rowsPerPageOptions={[5, 10, 25]} className="datatable-responsive mt-3"
<Column field="dni" header="Identificación" style={{ flexGrow: 1, flexBasis: '160px' }}></Column> paginatorTemplate="FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink CurrentPageReport RowsPerPageDropdown"
<Column field="email" header="Correo electrónico" style={{ flexGrow: 1, flexBasis: '160px' }}></Column> currentPageReportTemplate="Mostrando {first} a {last} de {totalRecords}"
<Column field="phone" header="Telefóno" style={{ flexGrow: 1, flexBasis: '160px' }}></Column> globalFilter={globalFilter} emptyMessage="No hay guardas registrados.">
<Column selectionMode="multiple" headerStyle={{ width: '3rem' }}></Column>
<Column field="name" sortable header={headerName} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}></Column>
<Column field="last_name" sortable header={headerLastName} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }} alignFrozen="left"></Column>
<Column field="dni" sortable header={headerDNI} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}>
</Column>
<Column field="email" sortable header={headerEmail} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}></Column>
<Column field="phone" sortable header={headerPhone} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}></Column>
<Column header={headerOptions} style={{ flexGrow: 1, flexBasis: '130px', minWidth: '130px' }} body={actionsAdmin}></Column>
</DataTable> </DataTable>
<Dialog visible={deleteGuardaDialog} style={{ width: '450px' }} header="Confirmar" modal footer={deleteAdminSystemDialogFooter} onHide={hideDeleteGuardaDialog}>
<div className="flex align-items-center justify-content-center">
<i className="pi pi-exclamation-triangle mr-3" style={{ fontSize: '2rem' }} />
{guarda && <span>¿Estás seguro que desea eliminar a <b>{guarda.name}</b>?</span>}
</div>
</Dialog>
<Dialog visible={deleteGuardasDialog} style={{ width: '450px' }} header="Confirmar" modal footer={deleteAdminsSystemDialogFooter} onHide={hideDeleteGuardasDialog}>
<div className="flex align-items-center justify-content-center">
<i className="pi pi-exclamation-triangle mr-3" style={{ fontSize: '2rem' }} />
{selectedGuardas && <span>¿Está seguro eliminar los adminsitradores del sistema seleccionados?</span>}
</div>
</Dialog>
</div> </div>
</div> </div>
<div className="col-12"> <div className="col-12">