finalizar funcionalidad cambiar de estado

This commit is contained in:
Mariela 2022-08-02 22:09:24 -06:00
parent 89469a687c
commit 2424d78bf6
2 changed files with 95 additions and 54 deletions

View File

@ -11,7 +11,7 @@ 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';
const AdministradoresSistema = () => { const AdministradoresSistema = () => {
const [administrators, setAdministrators] = useState([]); const [administrators, setAdministrators] = useState([]);
@ -98,6 +98,51 @@ const AdministradoresSistema = () => {
); );
} }
const cambiarStatusUser = () => {
if (sysadmin.status == '1') {
sysadmin.status = '0';
sysadmin.status_text = 'Inactivo';
} else if (sysadmin.status == '0') {
sysadmin.status = '1';
sysadmin.status_text = 'Activo';
}
var data = {
id: sysadmin._id,
status: sysadmin.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) {
setChangeStatusAdminSystemDialog(false);
toast.current.show({
severity: 'success',
summary: 'Éxito',
detail: 'Administrador del Sistema Actualizado',
life: 3000,
});
}
)
.catch(
err => console.log('Ocurrió un error con el fetch', err)
);
}
const confirmDeleteAdminSystem = (sysAdmin) => { const confirmDeleteAdminSystem = (sysAdmin) => {
setSysAdmin(sysAdmin); setSysAdmin(sysAdmin);
setDeleteAdminSystemDialog(true); setDeleteAdminSystemDialog(true);
@ -115,13 +160,13 @@ const AdministradoresSistema = () => {
setDeleteAdminsSystemDialog(false); setDeleteAdminsSystemDialog(false);
}; };
const confirmChangeStatusAdminSystem = (sysAdmin) => { const hideChangeStatusAdminDialog = () => {
setSysAdmin(sysAdmin); setChangeStatusAdminSystemDialog(false);
setDeleteAdminSystemDialog(true);
}; };
const hideChangeStatusAdminSystemDialog = () => { const confirmChangeStatusAdminSystem = (sysAdmin) => {
setChangeStatusAdminSystemDialog(false); setSysAdmin(sysAdmin);
setChangeStatusAdminSystemDialog(true);
}; };
const deleteSysAdmin = () => { const deleteSysAdmin = () => {
@ -165,7 +210,7 @@ const AdministradoresSistema = () => {
const deleteSelectedAdminsSystem = () => { const deleteSelectedAdminsSystem = () => {
let _administrators = administrators.filter( let _administrators = administrators.filter(
(val) => (!selectedAdministrators.includes(val) || val.status != -1), (val) => (!selectedAdministrators.includes(val)),
); );
selectedAdministrators.map((item) => { selectedAdministrators.map((item) => {
fetch('http://localhost:4000/user/deleteAdminSystem/' + item._id, { fetch('http://localhost:4000/user/deleteAdminSystem/' + item._id, {
@ -176,7 +221,9 @@ const AdministradoresSistema = () => {
}, },
}); });
}); });
_administrators = _administrators.filter(
(val) => val.status != -1,
)
setAdministrators(_administrators); setAdministrators(_administrators);
setDeleteAdminsSystemDialog(false); setDeleteAdminsSystemDialog(false);
setSelectedAdministrators(null); setSelectedAdministrators(null);
@ -188,53 +235,21 @@ const AdministradoresSistema = () => {
}); });
}; };
const changeStatusAdminSystm = () => {
fetch('http://localhost:4000/user/statusAdminSystem/' + sysadmin._id, {
cache: 'no-cache',
method: 'POST',
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 _sysadmin = administrators.filter(
(val) => (val._id !== sysadmin._id || val.status != -1),
);
setAdministrators(_sysadmin);
setDeleteAdminSystemDialog(false);
setSysAdmin(emptySysAdmin);
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 actionsAdmin = (rowData) => { const actionsAdmin = (rowData) => {
let icono = '';
if (rowData.status == '0') {
icono = "pi pi-eye";
} else if (rowData.status == '1') {
icono = "pi pi-eye-slash";
}
return ( return (
<div className="actions"> <div className="actions">
<Button <Button
icon="pi pi-eye" icon={`${icono}`}
className="p-button-rounded p-button-warning mt-2" className={`p-button-rounded p-button-warning mt-2 mx-2`}
onClick={() => confirmChangeStatusAdminSystem(rowData)} onClick={() => confirmChangeStatusAdminSystem(rowData)}
/> />
<Button <Button
@ -330,13 +345,13 @@ const AdministradoresSistema = () => {
label="No" label="No"
icon="pi pi-times" icon="pi pi-times"
className="p-button-text" className="p-button-text"
onClick={hideChangeStatusAdminSystemDialog} onClick={hideChangeStatusAdminDialog}
/> />
<Button <Button
label="Yes" label="Yes"
icon="pi pi-check" icon="pi pi-check"
className="p-button-text" className="p-button-text"
onClick={changeStatusAdminSystm} onClick={cambiarStatusUser}
/> />
</> </>
); );
@ -389,6 +404,14 @@ const AdministradoresSistema = () => {
</p> </p>
</> </>
); );
const headerStatus = (
<>
<p> {' '}
<FontAwesomeIcon icon={faCircleQuestion} style={{ color: "#D7A86E" }} />{' '}
Estado
</p>
</>
)
return ( return (
<div className="grid"> <div className="grid">
@ -525,6 +548,26 @@ const AdministradoresSistema = () => {
)} )}
</div> </div>
</Dialog> </Dialog>
<Dialog
visible={changeStatusAdminSystemDialog}
style={{ width: '450px' }}
header="Confirmar"
modal
footer={changeStatusAdminSystemDialogFooter}
onHide={hideChangeStatusAdminDialog}
>
<div className="flex align-items-center justify-content-center">
<i
className="pi pi-exclamation-triangle mr-3"
style={{ fontSize: '2rem' }}
/>
{sysadmin && (
<span>
¿Estás seguro que desea cambiar estado a <b>{sysadmin.name}</b>?
</span>
)}
</div>
</Dialog>
</div> </div>
</div> </div>
<div className="col-12"> <div className="col-12">

View File

@ -12,9 +12,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faHome, faUserAlt } from '@fortawesome/free-solid-svg-icons'; import { faHome, faUserAlt } from '@fortawesome/free-solid-svg-icons';
import { faMapLocationDot } from '@fortawesome/free-solid-svg-icons'; import { faMapLocationDot } from '@fortawesome/free-solid-svg-icons';
import { faPhoneAlt } from '@fortawesome/free-solid-svg-icons'; import { faPhoneAlt } 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 { icon } from '@fortawesome/fontawesome-svg-core';
import { faCircleQuestion } from '@fortawesome/free-solid-svg-icons'; import { faCircleQuestion } from '@fortawesome/free-solid-svg-icons';
const Communities = () => { const Communities = () => {