Merge pull request #153 from DeimosPr4/US-52-Verinformacióndeguardadeseguridad

US - ver perfil del guarda seguridad
This commit is contained in:
Eduardo Quiros 2022-08-03 14:42:06 +00:00 committed by GitHub
commit cbe1361f59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 469 additions and 57 deletions

View File

@ -58,7 +58,7 @@ const AdministradoresSistema = () => {
item.status_text = 'Inactivo'; item.status_text = 'Inactivo';
} }
}) })
setAdministrators(adminRes.message); setAdministrators(await data);
} }
useEffect(() => { useEffect(() => {
fetchP(); fetchP();
@ -262,7 +262,7 @@ const AdministradoresSistema = () => {
<div className="actions"> <div className="actions">
<Button <Button
icon={`${icono}`} icon={`${icono}`}
className={`p-button-rounded p-button-warning mt-2 mx-2`} className="p-button-rounded p-button-warning mt-2 mx-2"
onClick={() => confirmChangeStatusAdminSystem(rowData)} onClick={() => confirmChangeStatusAdminSystem(rowData)}
title={`${text}`} title={`${text}`}
/> />
@ -419,6 +419,7 @@ const AdministradoresSistema = () => {
</p> </p>
</> </>
); );
const headerStatus = ( const headerStatus = (
<> <>
<p> {' '} <p> {' '}
@ -613,12 +614,12 @@ const AdministradoresSistema = () => {
<InputText id="nombre" type="text" /> <InputText id="nombre" type="text" />
</div> </div>
<div className="field col-12 md:col-6"> <div className="field col-12 md:col-6">
<label htmlFor="apellidos">Apellidos</label> <label htmlFor="apellidos">Apellido(s)</label>
<InputText id="apellidos" type="text" /> <InputText id="apellidos" type="text" />
</div> </div>
<div className="field col-12 md:col-6"> <div className="field col-12 md:col-6">
<label htmlFor="correo_electronico">Correo electrónico</label> <label htmlFor="correo_electronico">Correo electrónico</label>
<InputText id="correo_electronico" type="text" /> <InputText id="correo_electronico" type="email" />
</div> </div>
<div className="field col-12 md:col-6"> <div className="field col-12 md:col-6">
<label htmlFor="identificacion">Identificación</label> <label htmlFor="identificacion">Identificación</label>

View File

@ -11,18 +11,11 @@ import { faUserAlt } from '@fortawesome/free-solid-svg-icons';
import { faPhoneAlt } from '@fortawesome/free-solid-svg-icons'; import { faPhoneAlt } from '@fortawesome/free-solid-svg-icons';
import { faAt } from '@fortawesome/free-solid-svg-icons'; import { faAt } from '@fortawesome/free-solid-svg-icons';
import { faIdCardAlt } from '@fortawesome/free-solid-svg-icons'; import { faIdCardAlt } from '@fortawesome/free-solid-svg-icons';
import { faEllipsis } from '@fortawesome/free-solid-svg-icons'; import { faCircleQuestion } from '@fortawesome/free-solid-svg-icons';
import { useCookies } from "react-cookie";
const GuardasSeguridad = () => { const GuardasSeguridad = () => {
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 = { let emptyGuarda = {
_id: null, _id: null,
dni: '', dni: '',
@ -32,16 +25,44 @@ const GuardasSeguridad = () => {
phone: '', phone: '',
password: '', password: '',
user_type: '1', user_type: '1',
status: '' status: '1',
status_text: '',
}; };
const [listaGuardas, setListaGuardas] = useState([]);
const [urlFetch, setUrlFetch] = useState('http://localhost:4000/user/findGuards/');
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);
const [cookies, setCookie] = useCookies();
const [changeStatusGuardDialog, setChangeStatusGuardDialog] = useState(false);
const [guardDialog, setGuardDialog] = useState(false);
const [submitted, setSubmitted] = useState(false);
async function listaGuardasF() { async function listaGuardasF() {
let nombres = await fetch(urlFetch, { method: 'GET' }); let nombres = await fetch((urlFetch + cookies.community_id), { method: 'GET' });
let listaGuardasRes = await nombres.json(); let listaGuardasRes = await nombres.json();
setListaGuardas(listaGuardasRes.message); let data = await listaGuardasRes.message.filter(
(val) => val.status != -1,
)
await data.map((item) => {
if (item.status == '1') {
item.status_text = 'Activo';
} else if (item.status == '0') {
item.status_text = 'Inactivo';
}
})
setListaGuardas(await data);
} }
useEffect(() => { useEffect(() => {
listaGuardasF(); listaGuardasF();
}, []) }, [])
@ -56,7 +77,7 @@ const GuardasSeguridad = () => {
password: document.getElementById('correo_electronico').value, password: document.getElementById('correo_electronico').value,
user_type: "4", //4 es guarda user_type: "4", //4 es guarda
status: "1", status: "1",
community_id: "62be68215692582bbfd77134" community_id: cookies.community_id
}; };
var data2 = { var data2 = {
dni: "11979037", dni: "11979037",
@ -66,7 +87,7 @@ const GuardasSeguridad = () => {
phone: 84664515, phone: 84664515,
password: "1203", password: "1203",
user_type: "2", user_type: "2",
status: "4", status: "1",
community_id: "62be68215692582bbfd77134" community_id: "62be68215692582bbfd77134"
} }
console.log('ssss'); console.log('ssss');
@ -74,7 +95,7 @@ const GuardasSeguridad = () => {
cache: 'no-cache', cache: 'no-cache',
method: 'POST', method: 'POST',
mode: 'cors', mode: 'cors',
body: JSON.stringify(data2), body: JSON.stringify(data),
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
} }
@ -89,7 +110,6 @@ const GuardasSeguridad = () => {
) )
.then( .then(
function (response) { function (response) {
console.log('fff');
listaGuardasF(); listaGuardasF();
} }
) )
@ -98,22 +118,51 @@ const GuardasSeguridad = () => {
); );
} }
const hideDeleteGuardaDialog = () => { const cambiarStatusUser = () => {
setDeleteGuardaDialog(false); if (guarda.status == '1') {
guarda.status = '0';
guarda.status_text = 'Inactivo';
} else if (guarda.status == '0') {
guarda.status = '1';
guarda.status_text = 'Activo';
}
var data = {
id: guarda._id,
status: guarda.status,
};
fetch('http://localhost:4000/user/changeStatus', {
cache: 'no-cache',
method: 'POST',
body: JSON.stringify(data),
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) {
setChangeStatusGuardDialog(false);
toast.current.show({
severity: 'success',
summary: 'Éxito',
detail: 'Guarda de Seguridad Actualizado',
life: 3000,
});
}
)
.catch(
err => console.log('Ocurrió un error con el fetch', err)
);
} }
const hideDeleteGuardasDialog = () => {
setDeleteGuardasDialog(false);
}
const confirmDeleteGuarda = (guarda) => {
setGuarda(guarda);
setDeleteGuardaDialog(true);
}
const confirmDeleteSelected = () => {
setDeleteGuardasDialog(true);
}
const deleteGuarda = () => { const deleteGuarda = () => {
@ -166,10 +215,70 @@ const GuardasSeguridad = () => {
toast.current.show({ severity: 'success', summary: 'Éxito', detail: 'Administradores del Sistema Eliminados', life: 3000 }); toast.current.show({ severity: 'success', summary: 'Éxito', detail: 'Administradores del Sistema Eliminados', life: 3000 });
} }
const actionsAdmin = (rowData) => { const hideDeleteGuardaDialog = () => {
setDeleteGuardaDialog(false);
}
const hideDeleteGuardasDialog = () => {
setDeleteGuardasDialog(false);
}
const confirmDeleteGuarda = (guarda) => {
setGuarda(guarda);
setDeleteGuardaDialog(true);
}
const confirmDeleteSelected = () => {
setDeleteGuardasDialog(true);
}
const hideChangeStatusGuardDialog = () => {
setChangeStatusGuardDialog(false);
};
const confirmChangeStatusGuard = (guard) => {
setGuarda(guard);
setChangeStatusGuardDialog(true);
};
const hideGuardDialog = () => {
setSubmitted(false);
setGuardDialog(false);
};
const infoGuard = (guard) => {
setGuarda(guard);
setGuardDialog(true);
};
const actionsGuard = (rowData) => {
let icono = '';
let text = '';
if (rowData.status == '0') {
icono = "pi pi-eye";
text = "Activar Guarda de Seguridad"
} else if (rowData.status == '1') {
icono = "pi pi-eye-slash";
text = "Inactivar Guarda de Seguridad"
}
return ( return (
<div className="actions"> <div className="actions">
<Button icon="pi pi-trash" className="p-button-rounded p-button-danger mt-2" onClick={() => confirmDeleteGuarda(rowData)} /> <Button
icon="pi pi-exclamation-circle"
className="p-button-rounded p-button-info mt-2 mx-2"
onClick={() => infoGuard(rowData)}
/>
<Button
icon={`${icono}`}
className="p-button-rounded p-button-warning mt-2 mx-2"
onClick={() => confirmChangeStatusGuard(rowData)}
title={`${text}`}
/>
<Button icon="pi pi-trash"
className="p-button-rounded p-button-danger mt-2 mx-2"
onClick={() => confirmDeleteGuarda(rowData)} />
</div> </div>
); );
} }
@ -178,7 +287,11 @@ const GuardasSeguridad = () => {
return ( return (
<React.Fragment> <React.Fragment>
<div className="my-2"> <div className="my-2">
<Button label="Eliminar" icon="pi pi-trash" className="p-button-danger" onClick={confirmDeleteSelected} disabled={!selectedGuardas || !selectedGuardas.length} /> <Button label="Eliminar"
icon="pi pi-trash"
className="p-button-danger"
onClick={confirmDeleteSelected}
disabled={!selectedGuardas || !selectedGuardas.length} />
</div> </div>
</React.Fragment> </React.Fragment>
) )
@ -187,7 +300,9 @@ const GuardasSeguridad = () => {
const rightToolbarTemplate = () => { const rightToolbarTemplate = () => {
return ( return (
<React.Fragment> <React.Fragment>
<Button label="Exportar" icon="pi pi-upload" className="p-button-help" /> <Button label="Exportar"
icon="pi pi-upload"
className="p-button-help" />
</React.Fragment> </React.Fragment>
) )
} }
@ -205,17 +320,47 @@ const GuardasSeguridad = () => {
const deleteAdminSystemDialogFooter = ( const deleteAdminSystemDialogFooter = (
<> <>
<Button label="No" icon="pi pi-times" className="p-button-text" onClick={hideDeleteGuardasDialog} /> <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} /> <Button label="" icon="pi pi-check" className="p-button-text" onClick={deleteGuarda} />
</> </>
); );
const deleteAdminsSystemDialogFooter = ( const deleteAdminsSystemDialogFooter = (
<> <>
<Button label="No" icon="pi pi-times" className="p-button-text" onClick={hideDeleteGuardasDialog} /> <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} /> <Button label="" icon="pi pi-check" className="p-button-text" onClick={deleteSelectedGuardas} />
</> </>
); );
const changeStatusGuardDialogFooter = (
<>
<Button
label="No"
icon="pi pi-times"
className="p-button-text"
onClick={hideChangeStatusGuardDialog}
/>
<Button
label="Sí"
icon="pi pi-check"
className="p-button-text"
onClick={cambiarStatusUser}
/>
</>
);
const guardDialogFooter = (
<>
<Button
label="Cerrar"
icon="pi pi-times"
className="p-button-text"
onClick={hideGuardDialog}
/>
</>
);
const headerName = ( const headerName = (
<> <>
<p>{' '} <p>{' '}
@ -261,6 +406,26 @@ const GuardasSeguridad = () => {
</> </>
) )
const headerStatus = (
<>
<p> {' '}
<FontAwesomeIcon icon={faCircleQuestion} style={{ color: "#D7A86E" }} />{' '}
Estado
</p>
</>
)
const statusBodyTemplate = (rowData) => {
return (
<>
<span
className={`status status-${rowData.status}`}
>
{rowData.status_text}
</span>
</>
);
};
return ( return (
<div className="grid"> <div className="grid">
@ -281,8 +446,85 @@ const GuardasSeguridad = () => {
</Column> </Column>
<Column field="email" sortable header={headerEmail} 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" header={headerPhone} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}></Column> <Column field="phone" header={headerPhone} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}></Column>
<Column style={{ flexGrow: 1, flexBasis: '130px', minWidth: '130px' }} body={actionsAdmin}></Column> <Column
field="status"
sortable
header={headerStatus}
body={statusBodyTemplate}
style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}>
</Column>
<Column style={{ flexGrow: 1, flexBasis: '80px', minWidth: '80px' }} body={actionsGuard}></Column>
</DataTable> </DataTable>
<Dialog
visible={guardDialog}
style={{ width: '650px' }}
header="Información del Guarda de Seguridad"
modal
className="p-fluid"
footer={guardDialogFooter}
onHide={hideGuardDialog}>
<div className='container text-center'>
<div className='row my-4'>
<div className=" col-4 md:col-4">
<p>Nombre</p>
<div className="p-0 col-2 md:col-2" style={{ margin: '0 auto' }}>
<div className="p-inputgroup align-items-center justify-content-evenly">
<i className="pi pi-user icon-khaki"></i>
<p>{guarda.name}</p>
</div>
</div>
</div>
<div className=" col-4 md:col-4">
<p>Apellido(s)</p>
<div className="p-0 col-6 md:col-6" style={{ margin: '0 auto' }}>
<div className="p-inputgroup align-items-center justify-content-evenly">
<i className="pi pi-user icon-khaki"></i>
<p>{guarda.last_name}</p>
</div>
</div>
</div>
<div className=" col-4 col-md-4 md:col-4">
<p>Identificación</p>
<div className="p-0 col-10 md:col-10" style={{ margin: '0 auto' }}>
<div className="p-inputgroup align-items-center justify-content-evenly">
<i className="pi pi-id-card icon-khaki"></i>
<p>{guarda.dni}</p>
</div>
</div>
</div>
</div>
<div className='row my-5 justify-content-center'>
</div>
<div className='row my-5 justify-content-center'>
<div className=" col-4 md:col-4">
<p>Teléfono</p>
<div className="p-0 col-10 md:col-10">
<div className="p-inputgroup align-items-center justify-content-evenly">
<i className="pi pi-phone icon-khaki"></i>
<p>{guarda.phone}</p>
</div>
</div>
</div>
<div className=" col-6 md:col-6">
<p>Correo Electrónico</p>
<div className="p-0 col-10 md:col-10" style={{ margin: '0 auto' }}>
<div className="p-inputgroup align-items-center justify-content-evenly">
<i className="pi pi-envelope icon-khaki"></i>
<p>{guarda.email}</p>
</div>
</div>
</div>
</div>
</div>
</Dialog>
<Dialog visible={deleteGuardaDialog} style={{ width: '450px' }} header="Confirmar" modal footer={deleteAdminSystemDialogFooter} onHide={hideDeleteGuardaDialog}> <Dialog visible={deleteGuardaDialog} style={{ width: '450px' }} header="Confirmar" modal footer={deleteAdminSystemDialogFooter} onHide={hideDeleteGuardaDialog}>
<div className="flex align-items-center justify-content-center"> <div className="flex align-items-center justify-content-center">
<i className="pi pi-exclamation-triangle mr-3" style={{ fontSize: '2rem' }} /> <i className="pi pi-exclamation-triangle mr-3" style={{ fontSize: '2rem' }} />
@ -292,7 +534,27 @@ const GuardasSeguridad = () => {
<Dialog visible={deleteGuardasDialog} style={{ width: '450px' }} header="Confirmar" modal footer={deleteAdminsSystemDialogFooter} onHide={hideDeleteGuardasDialog}> <Dialog visible={deleteGuardasDialog} style={{ width: '450px' }} header="Confirmar" modal footer={deleteAdminsSystemDialogFooter} onHide={hideDeleteGuardasDialog}>
<div className="flex align-items-center justify-content-center"> <div className="flex align-items-center justify-content-center">
<i className="pi pi-exclamation-triangle mr-3" style={{ fontSize: '2rem' }} /> <i className="pi pi-exclamation-triangle mr-3" style={{ fontSize: '2rem' }} />
{selectedGuardas && <span>¿Está seguro eliminar los adminsitradores del sistema seleccionados?</span>} {selectedGuardas && <span>¿Está seguro eliminar los guardas de seguridad seleccionados?</span>}
</div>
</Dialog>
<Dialog
visible={changeStatusGuardDialog}
style={{ width: '450px' }}
header="Confirmar"
modal
footer={changeStatusGuardDialogFooter}
onHide={hideChangeStatusGuardDialog}
>
<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 cambiar estado a <b>{guarda.name}</b>?
</span>
)}
</div> </div>
</Dialog> </Dialog>
</div> </div>
@ -306,12 +568,12 @@ const GuardasSeguridad = () => {
<InputText id="nombre" type="text" /> <InputText id="nombre" type="text" />
</div> </div>
<div className="field col-12 md:col-6"> <div className="field col-12 md:col-6">
<label htmlFor="apellidos">Apellidos</label> <label htmlFor="apellidos">Apellido(s)</label>
<InputText id="apellidos" type="text" /> <InputText id="apellidos" type="text" />
</div> </div>
<div className="field col-12 md:col-6"> <div className="field col-12 md:col-6">
<label htmlFor="correo_electronico">Correo electrónico</label> <label htmlFor="correo_electronico">Correo electrónico</label>
<InputText id="correo_electronico" type="text" /> <InputText id="correo_electronico" type="email" />
</div> </div>
<div className="field col-12 md:col-6"> <div className="field col-12 md:col-6">
<label htmlFor="identificacion">Identificación</label> <label htmlFor="identificacion">Identificación</label>
@ -319,7 +581,7 @@ const GuardasSeguridad = () => {
</div> </div>
<div className="field col-12"> <div className="field col-12">
<label htmlFor="telefono">Teléfono</label> <label htmlFor="telefono">Teléfono</label>
<InputText id="telefono" type="number" rows="4" /> <InputText id="telefono" type="tel" rows="4" />
</div> </div>
<Button label="Registrar" onClick={registrarGuarda}></Button> <Button label="Registrar" onClick={registrarGuarda}></Button>
</div> </div>

View File

@ -15,6 +15,7 @@ import { faAt } from '@fortawesome/free-solid-svg-icons';
import { faIdCardAlt } from '@fortawesome/free-solid-svg-icons'; import { faIdCardAlt } from '@fortawesome/free-solid-svg-icons';
import { faEllipsis } from '@fortawesome/free-solid-svg-icons'; import { faEllipsis } from '@fortawesome/free-solid-svg-icons';
import { faHashtag } from '@fortawesome/free-solid-svg-icons'; import { faHashtag } from '@fortawesome/free-solid-svg-icons';
import { faCircleQuestion } from '@fortawesome/free-solid-svg-icons';
import { useCookies } from "react-cookie"; import { useCookies } from "react-cookie";
@ -34,7 +35,8 @@ const Inquilinos = () => {
number_house: 'Sin número de vivienda', number_house: 'Sin número de vivienda',
user_type: '4', user_type: '4',
date_entry: new Date(), date_entry: new Date(),
status: '1' status: '1',
status_text: '',
}; };
const [tenants, setTenants] = useState([]); const [tenants, setTenants] = useState([]);
@ -50,6 +52,7 @@ const Inquilinos = () => {
const dt = useRef(null); const dt = useRef(null);
const [cookies, setCookie] = useCookies(); const [cookies, setCookie] = useCookies();
const [changeStatusTenantDialog, setChangeStatusTenantDialog] = useState(false);
async function tenantsList() { async function tenantsList() {
@ -57,9 +60,18 @@ const Inquilinos = () => {
.then((response) => response.json()) .then((response) => response.json())
.then(data => data.message) .then(data => data.message)
.then(data => { .then(data => {
data = data.filter(
(val) => val.status != -1,
)
data.map((item) => { data.map((item) => {
if(item.number_house ==""){ if (item.status == '1') {
item.status_text = 'Activo';
} else if (item.status == '0') {
item.status_text = 'Inactivo';
}
if (item.number_house == "") {
item.number_house = "Sin vivienda asignada"; item.number_house = "Sin vivienda asignada";
} }
}) })
@ -72,7 +84,9 @@ const Inquilinos = () => {
let response = await fetch('http://localhost:4000/community/allCommunities', { method: 'GET' }); let response = await fetch('http://localhost:4000/community/allCommunities', { method: 'GET' });
let resList = await response.json(); let resList = await response.json();
let list = await resList.message; let list = await resList.message;
list = await list.filter(
(val) => val.status != -1,
)
setCommunitiesList(await list); setCommunitiesList(await list);
} }
@ -189,6 +203,50 @@ const Inquilinos = () => {
}); });
}; };
const cambiarStatusUser = () => {
if (tenant.status == '1') {
tenant.status = '0';
tenant.status_text = 'Inactivo';
} else if (tenant.status == '0') {
tenant.status = '1';
tenant.status_text = 'Activo';
}
var data = {
id: tenant._id,
status: tenant.status,
};
fetch('http://localhost:4000/user/changeStatus', {
cache: 'no-cache',
method: 'POST',
body: JSON.stringify(data),
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) {
setChangeStatusTenantDialog(false);
toast.current.show({
severity: 'success',
summary: 'Éxito',
detail: 'Inquilino Actualizado',
life: 3000,
});
}
)
.catch(
err => console.log('Ocurrió un error con el fetch', err)
);
}
const hideDeleteTenantDialog = () => { const hideDeleteTenantDialog = () => {
setDeleteTenantDialog(false); setDeleteTenantDialog(false);
@ -207,11 +265,37 @@ const Inquilinos = () => {
setDeleteTenantsDialog(true); setDeleteTenantsDialog(true);
}; };
const hideChangeStatusTenantDialog = () => {
setChangeStatusTenantDialog(false);
};
const confirmChangeStatusTenant = (tenant) => {
setTenant(tenant);
setChangeStatusTenantDialog(true);
};
const actionsTenant = (rowData) => { const actionsTenant = (rowData) => {
let icono = '';
let text = '';
if (rowData.status == '0') {
icono = "pi pi-eye";
text = "Activar Inquilino"
} else if (rowData.status == '1') {
icono = "pi pi-eye-slash";
text = "Inactivar Inquilino"
}
return ( return (
<div className="actions"> <div className="actions">
<Button icon="pi pi-trash" className="p-button-rounded p-button-danger mt-2" onClick={() => confirmDeleteTenant(rowData)} /> <Button
icon={`${icono}`}
className="p-button-rounded p-button-warning mt-2 mx-2"
onClick={() => confirmChangeStatusTenant(rowData)}
title={`${text}`}
/>
<Button icon="pi pi-trash"
className="p-button-rounded p-button-danger mt-2 mx-2"
onClick={() => confirmDeleteTenant(rowData)} />
</div> </div>
); );
} }
@ -247,14 +331,32 @@ const Inquilinos = () => {
const deleteTenantDialogFooter = ( const deleteTenantDialogFooter = (
<> <>
<Button label="No" icon="pi pi-times" className="p-button-text" onClick={hideDeleteTenantDialog} /> <Button label="No" icon="pi pi-times" className="p-button-text" onClick={hideDeleteTenantDialog} />
<Button label="Yes" icon="pi pi-check" className="p-button-text" onClick={deleteTenant} /> <Button label="" icon="pi pi-check" className="p-button-text" onClick={deleteTenant} />
</> </>
); );
const deleteTenantsDialogFooter = ( const deleteTenantsDialogFooter = (
<> <>
<Button label="No" icon="pi pi-times" className="p-button-text" onClick={hideDeleteTenantsDialog} /> <Button label="No" icon="pi pi-times" className="p-button-text" onClick={hideDeleteTenantsDialog} />
<Button label="Yes" icon="pi pi-check" className="p-button-text" onClick={deleteSelectedTenants} /> <Button label="Sí" icon="pi pi-check" className="p-button-text" onClick={deleteSelectedTenants} />
</>
);
const changeStatusTenantDialogFooter = (
<>
<Button
label="No"
icon="pi pi-times"
className="p-button-text"
onClick={hideChangeStatusTenantDialog}
/>
<Button
label="Sí"
icon="pi pi-check"
className="p-button-text"
onClick={cambiarStatusUser}
/>
</> </>
); );
@ -296,6 +398,26 @@ const Inquilinos = () => {
</> </>
) )
const headerStatus = (
<>
<p> {' '}
<FontAwesomeIcon icon={faCircleQuestion} style={{ color: "#D7A86E" }} />{' '}
Estado
</p>
</>
)
const statusBodyTemplate = (rowData) => {
return (
<>
<span
className={`status status-${rowData.status}`}
>
{rowData.status_text}
</span>
</>
);
};
return ( return (
<div className="grid"> <div className="grid">
@ -317,7 +439,14 @@ const Inquilinos = () => {
<Column field="email" sortable header={headerEmail} 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" header={headerPhone} style={{ flexGrow: 1, flexBasis: '80px', minWidth: '80px', wordBreak: 'break-word' }}></Column> <Column field="phone" header={headerPhone} style={{ flexGrow: 1, flexBasis: '80px', minWidth: '80px', wordBreak: 'break-word' }}></Column>
<Column field="number_house" sortable header={headerNumberHouse} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word', justifyContent: 'center' }}></Column> <Column field="number_house" sortable header={headerNumberHouse} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word', justifyContent: 'center' }}></Column>
<Column style={{ flexGrow: 1, flexBasis: '130px', minWidth: '130px' }} body={actionsTenant}></Column> <Column
field="status"
sortable
header={headerStatus}
body={statusBodyTemplate}
style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}>
</Column>
<Column style={{ flexGrow: 1, flexBasis: '80px', minWidth: '80px' }} body={actionsTenant}></Column>
</DataTable> </DataTable>
<Dialog visible={deleteTenantDialog} style={{ width: '450px' }} header="Confirmar" modal footer={deleteTenantDialogFooter} onHide={hideDeleteTenantDialog}> <Dialog visible={deleteTenantDialog} style={{ width: '450px' }} header="Confirmar" modal footer={deleteTenantDialogFooter} onHide={hideDeleteTenantDialog}>
<div className="flex align-items-center justify-content-center"> <div className="flex align-items-center justify-content-center">
@ -328,7 +457,27 @@ const Inquilinos = () => {
<Dialog visible={deleteTenantsDialog} style={{ width: '450px' }} header="Confirmar" modal footer={deleteTenantsDialogFooter} onHide={hideDeleteTenantsDialog}> <Dialog visible={deleteTenantsDialog} style={{ width: '450px' }} header="Confirmar" modal footer={deleteTenantsDialogFooter} onHide={hideDeleteTenantsDialog}>
<div className="flex align-items-center justify-content-center"> <div className="flex align-items-center justify-content-center">
<i className="pi pi-exclamation-triangle mr-3" style={{ fontSize: '2rem' }} /> <i className="pi pi-exclamation-triangle mr-3" style={{ fontSize: '2rem' }} />
{selectedTentants && <span>¿Está seguro eliminar los Inquilinos seleccionados?</span>} {selectedTentants && <span>¿Está seguro eliminar los inquilinos seleccionados?</span>}
</div>
</Dialog>
<Dialog
visible={changeStatusTenantDialog}
style={{ width: '450px' }}
header="Confirmar"
modal
footer={changeStatusTenantDialogFooter}
onHide={hideChangeStatusTenantDialog}
>
<div className="flex align-items-center justify-content-center">
<i
className="pi pi-exclamation-triangle mr-3"
style={{ fontSize: '2rem' }}
/>
{tenant && (
<span>
¿Estás seguro que desea cambiar estado a <b>{tenant.name}</b>?
</span>
)}
</div> </div>
</Dialog> </Dialog>
</div> </div>
@ -342,7 +491,7 @@ const Inquilinos = () => {
<InputText type="text" className="form-control" id="nombre" /> <InputText type="text" className="form-control" id="nombre" />
</div> </div>
<div className="field col-12 md:col-6"> <div className="field col-12 md:col-6">
<label htmlFor="apellidos">Apellidos</label> <label htmlFor="apellidos">Apellido(s)</label>
<InputText type="text" className="form-control" id="apellidos" /> <InputText type="text" className="form-control" id="apellidos" />
</div> </div>
<div className="field col-12 md:col-6"> <div className="field col-12 md:col-6">