agregar columna de estado en la lista

This commit is contained in:
Mariela 2022-08-02 22:22:45 -06:00
parent 2424d78bf6
commit e0fe79a1e5
2 changed files with 57 additions and 23 deletions

View File

@ -41,14 +41,24 @@ const AdministradoresSistema = () => {
password: '', password: '',
user_type: '1', user_type: '1',
status: '1', status: '1',
status_text: '',
}; };
async function fetchP() { async function fetchP() {
let nombres = await fetch(urlFetch, { method: 'GET' }); let nombres = await fetch(urlFetch, { method: 'GET' });
let adminRes = await nombres.json(); let adminRes = await nombres.json();
let data = await adminRes.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';
}
})
setAdministrators(adminRes.message); setAdministrators(adminRes.message);
console.log(administrators);
} }
useEffect(() => { useEffect(() => {
fetchP(); fetchP();
@ -67,7 +77,6 @@ const AdministradoresSistema = () => {
status: "1" status: "1"
}; };
setSysAdmin(data) setSysAdmin(data)
// console.log(data);
fetch('http://localhost:4000/user/createAdminSystem/', { fetch('http://localhost:4000/user/createAdminSystem/', {
cache: 'no-cache', cache: 'no-cache',
@ -186,7 +195,7 @@ const AdministradoresSistema = () => {
let _sysadmin = administrators.filter( let _sysadmin = administrators.filter(
(val) => (val._id !== sysadmin._id || val.status != -1), (val) => (val._id !== sysadmin._id || val.status != -1),
); );
setAdministrators(_sysadmin); setAdministrators(_sysadmin);
setDeleteAdminSystemDialog(false); setDeleteAdminSystemDialog(false);
setSysAdmin(emptySysAdmin); setSysAdmin(emptySysAdmin);
@ -235,27 +244,33 @@ const AdministradoresSistema = () => {
}); });
}; };
const actionsAdmin = (rowData) => { const actionsAdmin = (rowData) => {
let icono = ''; let icono = '';
let text = '';
if (rowData.status == '0') { if (rowData.status == '0') {
icono = "pi pi-eye"; icono = "pi pi-eye";
text = "Activar Administrador"
} else if (rowData.status == '1') { } else if (rowData.status == '1') {
icono = "pi pi-eye-slash"; icono = "pi pi-eye-slash";
text = "Inactivar Administrador"
} }
return ( return (
<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}`}
/> />
<Button <Button
icon="pi pi-trash" icon="pi pi-trash"
className="p-button-rounded p-button-danger mt-2" className="p-button-rounded p-button-danger mt-2 mx-2"
onClick={() => confirmDeleteAdminSystem(rowData)} onClick={() => confirmDeleteAdminSystem(rowData)}
title="Eliminar Administrador"
/> />
</div> </div>
); );
@ -413,6 +428,18 @@ const AdministradoresSistema = () => {
</> </>
) )
const statusBodyTemplate = (rowData) => {
return (
<>
<span
className={`status status-${rowData.status}`}
>
{rowData.status_text}
</span>
</>
);
};
return ( return (
<div className="grid"> <div className="grid">
<div className="col-12"> <div className="col-12">
@ -502,8 +529,15 @@ const AdministradoresSistema = () => {
}} }}
></Column> ></Column>
<Column <Column
field="status"
style={{ flexGrow: 1, flexBasis: '130px', minWidth: '130px' }} 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={actionsAdmin} body={actionsAdmin}
></Column> ></Column>
</DataTable> </DataTable>

View File

@ -696,15 +696,15 @@ const Communities = () => {
const statusBodyTemplate = (rowData) => { const statusBodyTemplate = (rowData) => {
return ( return (
<> <>
<span <span
className={`status status-${rowData.status}`} className={`status status-${rowData.status}`}
> >
{rowData.status_text} {rowData.status_text}
</span> </span>
</> </>
); );
}; };
const tenantsBodyTemplate = (rowData) => { const tenantsBodyTemplate = (rowData) => {
let tenants = rowData.tenants; let tenants = rowData.tenants;
@ -790,12 +790,12 @@ const Communities = () => {
header={headerAdministrator} header={headerAdministrator}
style={{ flexGrow: 1, flexBasis: '180px' }} style={{ flexGrow: 1, flexBasis: '180px' }}
></Column> ></Column>
<Column <Column
field="status" field="status"
sortable sortable
header={headerStatus} header={headerStatus}
body={statusBodyTemplate} body={statusBodyTemplate}
style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}> style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}>
</Column> </Column>
<Column <Column
body={actionsCommunity} body={actionsCommunity}