admin del sistema

This commit is contained in:
Mariela 2022-09-01 02:35:44 -06:00
parent bc8486e1ba
commit f440b7e181
1 changed files with 44 additions and 36 deletions

View File

@ -50,7 +50,7 @@ const AdministradoresSistema = () => {
const [adminDialog, setAdminDialog] = useState(false); const [adminDialog, setAdminDialog] = useState(false);
const [submitted, setSubmitted] = useState(false); const [submitted, setSubmitted] = useState(false);
const [editAdminDialog, setEditAdminDialog] = useState(false); const [formAdminDialog, setFormAdminDialog] = useState(false);
const [saveButtonTitle, setSaveButtonTitle] = useState("Registrar") const [saveButtonTitle, setSaveButtonTitle] = useState("Registrar")
@ -136,7 +136,7 @@ const AdministradoresSistema = () => {
life: 3000, life: 3000,
}); });
setAdministrators(_administrators) setAdministrators(_administrators)
setEditAdminDialog(false); setFormAdminDialog(false);
setSysAdmin(emptySysAdmin); setSysAdmin(emptySysAdmin);
} }
) )
@ -267,7 +267,23 @@ const AdministradoresSistema = () => {
const editAdmin = (sysadmin) => { const editAdmin = (sysadmin) => {
setSysAdmin({ ...sysadmin }); setSysAdmin({ ...sysadmin });
setSaveButtonTitle('Actualizar'); setSaveButtonTitle('Actualizar');
setFormAdminDialog(true)
}; };
const openNewAdmin = () => {
setSysAdmin(emptySysAdmin);
setFormAdminDialog(true)
setSubmitted(false);
};
const hideFormAdminDialog = () => {
setSubmitted(false);
setFormAdminDialog(false)
setSysAdmin(emptySysAdmin);
setSaveButtonTitle('Registrar');
};
const deleteSysAdmin = () => { const deleteSysAdmin = () => {
fetch('http://localhost:4000/user/deleteAdminSystem/' + sysadmin._id, { fetch('http://localhost:4000/user/deleteAdminSystem/' + sysadmin._id, {
@ -386,6 +402,12 @@ const AdministradoresSistema = () => {
return ( return (
<React.Fragment> <React.Fragment>
<div className="my-2"> <div className="my-2">
<Button
label="Agregar Administrador"
icon="pi pi-plus"
className="p-button-primary mr-2"
onClick={openNewAdmin}
/>
<Button <Button
label="Eliminar" label="Eliminar"
icon="pi pi-trash" icon="pi pi-trash"
@ -478,19 +500,19 @@ const AdministradoresSistema = () => {
); );
const editAdminDialogFooter = ( const formAdminDialogFooter = (
<> <>
<Button <Button
label="No" label={`${saveButtonTitle}`}
icon="pi pi-times" icon="pi pi-check"
className="p-button-text" className="p-button-primary"
onClick={hideChangeStatusAdminDialog} onClick={guardarAdmin}
/> />
<Button <Button
label="Yes" label="Cerrar"
icon="pi pi-check" icon="pi pi-times"
className="p-button-text" className="p-button-text"
onClick={editAdmin} onClick={hideFormAdminDialog}
/> />
</> </>
); );
@ -691,7 +713,7 @@ const AdministradoresSistema = () => {
</Column> </Column>
<Column <Column
style={{ flexGrow: 1, flexBasis: '80px', minWidth: '80px' }} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px' }}
body={actionsAdmin} body={actionsAdmin}
></Column> ></Column>
</DataTable> </DataTable>
@ -834,12 +856,14 @@ const AdministradoresSistema = () => {
)} )}
</div> </div>
</Dialog> </Dialog>
<Dialog
</div> visible={formAdminDialog}
</div> style={{ width: '650px' }}
<div className="col-12"> header="Mantenimiento Administrador del Sistema"
<div className="card"> modal
<h5>Mantenimiento Administrador del Sistema</h5> className="p-fluid"
footer={formAdminDialogFooter}
onHide={hideFormAdminDialog}>
<div className="p-fluid formgrid grid"> <div className="p-fluid formgrid grid">
<div className="field col-6 md:col-6"> <div className="field col-6 md:col-6">
<label htmlFor="name">Nombre</label> <label htmlFor="name">Nombre</label>
@ -953,29 +977,13 @@ const AdministradoresSistema = () => {
)} )}
</div> </div>
</div> </div>
<div style={{
display: "flex",
justifyContent: "center",
gap: "10px",
width: "100%"
}}>
<Button
label={`${saveButtonTitle}`}
onClick={guardarAdmin}
/>
{saveButtonTitle === 'Actualizar' && (
<Button
label="Cancelar"
onClick={cancelEdit}
className="p-button-danger" />)}
</div> </div>
</Dialog>
</div>
</div> </div>
</div> </div>
</div>
</div>
); );
}; };