Merge pull request #130 from DeimosPr4/UH-updateRegistroAdminComunidad

Cambio de estilo a los guardas de seguridad
This commit is contained in:
Eduardo Quiros 2022-07-26 23:05:32 -06:00 committed by GitHub
commit c574326bcc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 305 additions and 123 deletions

View File

@ -1,139 +1,321 @@
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( const [urlFetch,setUrlFetch]=useState('http://localhost:4000/user/findGuards/62be68215692582bbfd77134');
'http://localhost:4000/user/findGuards/62be68215692582bbfd77134', const [guarda, setGuarda] = useState(emptyGuarda);
); const [selectedGuardas, setSelectedGuardas] = useState(null);
async function fetchP() { const [globalFilter, setGlobalFilter] = useState(null);
let nombres = await fetch(urlFetch, { method: 'GET' }); const [deleteGuardaDialog, setDeleteGuardaDialog] = useState(false);
let pokemonesRes = await nombres.json(); const [deleteGuardasDialog, setDeleteGuardasDialog] = useState(false);
setPokemones(pokemonesRes.message); const toast = useRef(null);
console.log(pokemones); const dt = useRef(null);
} let emptyGuarda = {
useEffect(() => { _id: null,
fetchP(); dni: '',
}, []); name: '',
last_name: '',
function registrarGuarda() { email: '',
var data = { phone: '',
dni: document.getElementById('identificacion').value, password: '',
name: document.getElementById('nombre').value, user_type: '1',
last_name: document.getElementById('apellidos').value, status: ''
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: '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 (
<div className="grid"> async function listaGuardasF(){
<div className="col-12"> let nombres=await fetch(urlFetch, {method:'GET'});
<div className="card"> let listaGuardasRes= await nombres.json();
<h5>Guardas de seguridad</h5> setListaGuardas(listaGuardasRes.message);
<DataTable }
value={pokemones} useEffect(()=>{
scrollable listaGuardasF();
scrollHeight="400px" },[])
scrollDirection="both"
className="mt-3" function registrarGuarda() {
> var data = {
<Column dni: document.getElementById('identificacion').value,
field="name" name: document.getElementById('nombre').value,
header="Nombre" last_name: document.getElementById('apellidos').value,
style={{ flexGrow: 1, flexBasis: '160px' }} email: document.getElementById('correo_electronico').value,
></Column> phone: document.getElementById('telefono').value,
<Column password: document.getElementById('correo_electronico').value,
field="last_name" user_type: "4", //4 es guarda
header="Apellidos" status: "1",
style={{ flexGrow: 1, flexBasis: '160px' }} community_id:"62be68215692582bbfd77134"
alignFrozen="left" };
></Column> var data2={
<Column dni: "11979037",
field="dni" name: "Jorge",
header="Identificación" last_name: "Soto",
style={{ flexGrow: 1, flexBasis: '160px' }} email: "jorgesoto@gmail.com",
></Column> phone: 84664515,
<Column password: "1203",
field="email" user_type: "2",
header="Correo electrónico" status: "4",
style={{ flexGrow: 1, flexBasis: '160px' }} community_id:"62be68215692582bbfd77134"
></Column> }
<Column console.log('ssss');
field="phone" fetch('http://localhost:4000/user/createGuard', {
header="Telefóno" cache: 'no-cache',
style={{ flexGrow: 1, flexBasis: '160px' }} method: 'POST',
></Column> mode:'cors',
</DataTable> 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 (
<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> </div>
</div> );
<div className="col-12">
<div className="card"> const deleteAdminSystemDialogFooter = (
<h5>Registro de un guarda de seguridad</h5> <>
<div className="p-fluid formgrid grid"> <Button label="No" icon="pi pi-times" className="p-button-text" onClick={hideDeleteGuardasDialog} />
<div className="field col-12 md:col-6"> <Button label="Yes" icon="pi pi-check" className="p-button-text" onClick={deleteGuarda} />
<label htmlFor="nombre">Nombre</label> </>
<InputText id="nombre" type="text" /> );
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 (
<div className="grid">
<div className="col-12">
<Toast ref={toast} />
<div className="card">
<Toolbar className="mb-4" left={leftToolbarTemplate} right={rightToolbarTemplate}></Toolbar>
<DataTable ref={dt} value={listaGuardas} dataKey="_id" paginator rows={5} selection={selectedGuardas} onSelectionChange={(e) => setSelectedGuardas(e.value)}
responsiveLayout="scroll" header={header}
rowsPerPageOptions={[5, 10, 25]} className="datatable-responsive mt-3"
paginatorTemplate="FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink CurrentPageReport RowsPerPageDropdown"
currentPageReportTemplate="Mostrando {first} a {last} de {totalRecords}"
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>
<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 className="field col-12 md:col-6"> <div className="col-12">
<label htmlFor="apellidos">Apellidos</label> <div className="card">
<InputText id="apellidos" type="text" /> <h5>Registro de un guarda de seguridad</h5>
<div className="p-fluid formgrid grid">
<div className="field col-12 md:col-6">
<label htmlFor="nombre">Nombre</label>
<InputText id="nombre" type="text" />
</div>
<div className="field col-12 md:col-6">
<label htmlFor="apellidos">Apellidos</label>
<InputText id="apellidos" type="text" />
</div>
<div className="field col-12 md:col-6">
<label htmlFor="correo_electronico">Correo electrónico</label>
<InputText id="correo_electronico" type="text" />
</div>
<div className="field col-12 md:col-6">
<label htmlFor="identificacion">Identificación</label>
<InputText id="identificacion" type="text" />
</div>
<div className="field col-12">
<label htmlFor="telefono">Teléfono</label>
<InputText id="telefono" type="number" rows="4" />
</div>
<Button label="Registrar" onClick={registrarGuarda}></Button>
</div>
</div>
</div> </div>
<div className="field col-12 md:col-6">
<label htmlFor="correo_electronico">Correo electrónico</label>
<InputText id="correo_electronico" type="text" />
</div>
<div className="field col-12 md:col-6">
<label htmlFor="identificacion">Identificación</label>
<InputText id="identificacion" type="text" />
</div>
<div className="field col-12">
<label htmlFor="telefono">Teléfono</label>
<InputText id="telefono" type="number" rows="4" />
</div>
<Button label="Registrar" onClick={registrarGuarda}></Button>
</div>
</div> </div>
</div>
</div>
); );
}; };