Merge pull request #219 from DeimosPr4/popups-registros

fixes finales
This commit is contained in:
Eduardo Quiros 2022-09-01 21:19:37 +00:00 committed by GitHub
commit a44fe8caa2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 895 additions and 680 deletions

View File

@ -82,7 +82,8 @@ export class UsersController {
@MessagePattern({ cmd: 'updateAdminCommunity' }) @MessagePattern({ cmd: 'updateAdminCommunity' })
updateAdminCommunity(@Payload() user: UserDocument) { updateAdminCommunity(@Payload() user: UserDocument) {
return this.userService.update(user._id, user); console.log(user)
return this.userService.updateAdminCommunity(user['_id'], user);
} }
@MessagePattern({ cmd: 'updateTenant' }) @MessagePattern({ cmd: 'updateTenant' })

View File

@ -134,6 +134,17 @@ export class UsersService {
}); });
} }
async updateAdminCommunity(id: string, user: UserDocument) {
return this.userModel.findOneAndUpdate({ _id: id }, {
name: user['name'], last_name: user['last_name'],
dni: user['dni'], email: user['email'], phone: user['phone'],
community_id: user['community_id']
}, {
new: true,
});
}
async updateTenant(id: string, user: UserDocument) { async updateTenant(id: string, user: UserDocument) {
await this.saveTenant(user.community_id, user.number_house, user.id); await this.saveTenant(user.community_id, user.number_house, user.id);

View File

@ -50,6 +50,7 @@ const AdministradoresComunidad = () => {
const [changeStatusAdminCommunityDialog, setChangeStatusAdminCommunityDialog] = useState(false); const [changeStatusAdminCommunityDialog, setChangeStatusAdminCommunityDialog] = useState(false);
const [saveButtonTitle, setSaveButtonTitle] = useState("Registrar"); const [saveButtonTitle, setSaveButtonTitle] = useState("Registrar");
const [adminDialog, setAdminDialog] = useState(false);
async function listaAdmin() { async function listaAdmin() {
@ -280,6 +281,7 @@ const AdministradoresComunidad = () => {
toast.current.show({ severity: 'success', summary: 'Exito', detail: 'Administrador de Comunidad de vivienda Creada', life: 3000 }); toast.current.show({ severity: 'success', summary: 'Exito', detail: 'Administrador de Comunidad de vivienda Creada', life: 3000 });
setListaAdmins(_administrators); setListaAdmins(_administrators);
setAdminDialog(false)
setAdminCommunity(emptyAdminCommunity); setAdminCommunity(emptyAdminCommunity);
@ -295,7 +297,6 @@ const AdministradoresComunidad = () => {
} else { } else {
console.log(`Actualizando admnistrador de comunidad: ${_admin}`) console.log(`Actualizando admnistrador de comunidad: ${_admin}`)
_admin.community_id = communityId; _admin.community_id = communityId;
console.log(`Actualizando admnistrador de comunidad: ${_admin}`)
fetch(`http://localhost:4000/user/updateAdminCommunity/${_admin._id}`, { fetch(`http://localhost:4000/user/updateAdminCommunity/${_admin._id}`, {
cache: 'no-cache', cache: 'no-cache',
@ -319,7 +320,7 @@ const AdministradoresComunidad = () => {
listaAdmin(); listaAdmin();
setCommunityId(''); setCommunityId('');
setAdminDialog(false)
setAdminCommunity(emptyAdminCommunity); setAdminCommunity(emptyAdminCommunity);
}) })
} }
@ -356,6 +357,8 @@ const AdministradoresComunidad = () => {
setAdminCommunity(admin); setAdminCommunity(admin);
setSaveButtonTitle('Actualizar'); setSaveButtonTitle('Actualizar');
setCommunityId(admin.community_id) setCommunityId(admin.community_id)
setAdminDialog(true)
} }
@ -365,6 +368,20 @@ const AdministradoresComunidad = () => {
setCommunityId(''); setCommunityId('');
} }
const openNewAdmin = () => {
setAdminCommunity(emptyAdminCommunity);
setAdminDialog(true)
setSubmitted(false);
};
const hideAdminDialog = () => {
setSubmitted(false);
setAdminDialog(false)
setAdminCommunity(emptyAdminCommunity);
setSaveButtonTitle('Registrar');
};
const actionsAdminCommunity = (rowData) => { const actionsAdminCommunity = (rowData) => {
let icono = ''; let icono = '';
let text = ''; let text = '';
@ -431,10 +448,33 @@ const AdministradoresComunidad = () => {
</> </>
); );
const adminDialogFooter = (
<>
<Button
label={`${saveButtonTitle}`}
icon="pi pi-check"
className="p-button-primary"
onClick={saveAdminCommunity}
/>
<Button
label="Cerrar"
icon="pi pi-times"
className="p-button-text"
onClick={hideAdminDialog}
/>
</>
);
const leftToolbarTemplate = () => { const leftToolbarTemplate = () => {
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 label="Eliminar" icon="pi pi-trash" className="p-button-danger" onClick={confirmDeleteSelected} disabled={!selectedAdminsCommunities || !selectedAdminsCommunities.length} /> <Button label="Eliminar" icon="pi pi-trash" className="p-button-danger" onClick={confirmDeleteSelected} disabled={!selectedAdminsCommunities || !selectedAdminsCommunities.length} />
</div> </div>
</React.Fragment> </React.Fragment>
@ -562,9 +602,9 @@ const AdministradoresComunidad = () => {
<Toast ref={toast} /> <Toast ref={toast} />
<div className="card"> <div className="card">
<Toolbar className="mb-4" left={leftToolbarTemplate} right={rightToolbarTemplate}></Toolbar> <Toolbar className="mb-4" left={leftToolbarTemplate} right={rightToolbarTemplate}></Toolbar>
<DataTable ref={dt} value={listaAdmins} dataKey="_id" paginator rows={5} selection={selectedAdminsCommunities} onSelectionChange={(e) => setSelectedAdminsCommunities(e.value)} <DataTable ref={dt} value={listaAdmins} dataKey="_id" paginator rows={10} selection={selectedAdminsCommunities} onSelectionChange={(e) => setSelectedAdminsCommunities(e.value)}
scrollable scrollHeight="400px" scrollDirection="both" header={header} scrollable scrollHeight="800px" scrollDirection="both" header={header}
rowsPerPageOptions={[5, 10, 25]} className="datatable-responsive mt-3" rowsPerPageOptions={[10, 20, 30]} className="datatable-responsive mt-3"
paginatorTemplate="FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink CurrentPageReport RowsPerPageDropdown" paginatorTemplate="FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink CurrentPageReport RowsPerPageDropdown"
currentPageReportTemplate="Mostrando {first} a {last} de {totalRecords} administradores de comunidades de viviendas" currentPageReportTemplate="Mostrando {first} a {last} de {totalRecords} administradores de comunidades de viviendas"
globalFilter={globalFilter} emptyMessage="No hay administradores de comunidades registrados."> globalFilter={globalFilter} emptyMessage="No hay administradores de comunidades registrados.">
@ -577,7 +617,7 @@ const AdministradoresComunidad = () => {
<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 field="community_name" sortable header={headerCommuntiy} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}></Column> <Column field="community_name" sortable header={headerCommuntiy} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}></Column>
<Column field="status" sortable header={headerStatus} body={statusBodyTemplate} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}></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={actionsAdminCommunity}></Column> <Column style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px' }} body={actionsAdminCommunity}></Column>
</DataTable> </DataTable>
<Dialog visible={deleteAdminCommunityDialog} style={{ width: '450px' }} header="Confirmar" modal footer={deleteAdminCommunityDialogFooter} onHide={hideDeleteAdminCommunityDialog}> <Dialog visible={deleteAdminCommunityDialog} style={{ width: '450px' }} header="Confirmar" modal footer={deleteAdminCommunityDialogFooter} onHide={hideDeleteAdminCommunityDialog}>
<div className="flex align-items-center justify-content-center"> <div className="flex align-items-center justify-content-center">
@ -611,11 +651,16 @@ const AdministradoresComunidad = () => {
)} )}
</div> </div>
</Dialog> </Dialog>
</div> <Dialog
</div> visible={adminDialog}
<div className="col-12"> style={{ width: '850px' }}
<div className="card"> header="Mantenimiento Administradores de la Comunidad"
<h5>Registro de un administrador de una comunidad de viviendas</h5> modal
className="p-fluid"
footer={adminDialogFooter}
onHide={hideAdminDialog}
>
{adminCommunity && (
<div className="p-fluid formgrid grid"> <div className="p-fluid formgrid grid">
<div className="field col-12 md:col-6"> <div className="field col-12 md:col-6">
<label htmlFor="name">Nombre</label> <label htmlFor="name">Nombre</label>
@ -650,8 +695,10 @@ const AdministradoresComunidad = () => {
</span> </span>
<InputText id="email" value={adminCommunity.email} <InputText id="email" value={adminCommunity.email}
onChange={(e) => onInputChange(e, 'email')} required autoFocus onChange={(e) => onInputChange(e, 'email')} required autoFocus
className={classNames({ 'p-invalid': submitted && className={classNames({
(adminCommunity.email === '' || findRepeated('email', adminCommunity.email) > 0) })} /> 'p-invalid': submitted &&
(adminCommunity.email === '' || findRepeated('email', adminCommunity.email) > 0)
})} />
</div> </div>
{submitted && adminCommunity.email === '' && <small className="p-invalid">Correo electrónico {submitted && adminCommunity.email === '' && <small className="p-invalid">Correo electrónico
es requirido.</small>} es requirido.</small>}
@ -669,8 +716,10 @@ const AdministradoresComunidad = () => {
</span> </span>
<InputText id="dni" value={adminCommunity.dni} <InputText id="dni" value={adminCommunity.dni}
onChange={(e) => onInputChange(e, 'dni')} required autoFocus onChange={(e) => onInputChange(e, 'dni')} required autoFocus
className={classNames({ 'p-invalid': submitted className={classNames({
&& (adminCommunity.dni === '' || findRepeated('dni', adminCommunity.dni) > 0)})} /> 'p-invalid': submitted
&& (adminCommunity.dni === '' || findRepeated('dni', adminCommunity.dni) > 0)
})} />
</div> </div>
{submitted && adminCommunity.dni === '' && <small className="p-invalid">Identificación es requirida.</small>} {submitted && adminCommunity.dni === '' && <small className="p-invalid">Identificación es requirida.</small>}
{submitted && findRepeated('dni', adminCommunity.dni) > 0 && {submitted && findRepeated('dni', adminCommunity.dni) > 0 &&
@ -703,24 +752,11 @@ const AdministradoresComunidad = () => {
{submitted && !communityId && <small className="p-invalid">Comunidad es requirida.</small>} {submitted && !communityId && <small className="p-invalid">Comunidad es requirida.</small>}
</div> </div>
</div> </div>
<div style={{
display: "flex",
justifyContent: "center",
gap: "10px",
width: "100%"
}}>
<Button
label={`${saveButtonTitle}`}
onClick={saveAdminCommunity}
/>
{saveButtonTitle === 'Actualizar' && (
<Button
label="Cancelar"
onClick={cancelEdit}
className="p-button-danger" />)}
</div>
</div> </div>
)}
</Dialog>
</div> </div>
</div> </div>
</div> </div>

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);
} }
) )
@ -164,6 +164,8 @@ const AdministradoresSistema = () => {
function (response) { function (response) {
_administrators.push(_admin); _administrators.push(_admin);
setAdministrators(_administrators) setAdministrators(_administrators)
setFormAdminDialog(false)
} }
) )
.catch( .catch(
@ -267,7 +269,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 +404,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 +502,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 +715,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 +858,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 +979,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>
); );
}; };

View File

@ -608,7 +608,6 @@ const AreasComunes = () => {
); );
}; };
function compareTimesMinRequired(hour1, hour2) { function compareTimesMinRequired(hour1, hour2) {
var timeFormat1 = Number(hour1.replace(/[:]/g, '')); var timeFormat1 = Number(hour1.replace(/[:]/g, ''));
var timeFormat2 = Number(hour2.replace(/[:]/g, '')); var timeFormat2 = Number(hour2.replace(/[:]/g, ''));
@ -619,10 +618,6 @@ const AreasComunes = () => {
} }
} }
return ( return (
<div className="grid"> <div className="grid">
<div className="col-12"> <div className="col-12">
@ -641,7 +636,7 @@ const AreasComunes = () => {
<Column field="hourMax" sortable header={headerHourMax} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}> </Column> <Column field="hourMax" sortable header={headerHourMax} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}> </Column>
<Column field="bookable" sortable header={headerBookable} body={bookableBodyTemplate} style={{ flexGrow: 1, flexBasis: '200px', minWidth: '200px', wordBreak: 'break-word' }}></Column> <Column field="bookable" sortable header={headerBookable} body={bookableBodyTemplate} style={{ flexGrow: 1, flexBasis: '200px', minWidth: '200px', wordBreak: 'break-word' }}></Column>
<Column field="status" sortable header={headerStatus} body={statusBodyTemplate} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}></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={actionsCommonArea}></Column> <Column style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px' }} body={actionsCommonArea}></Column>
</DataTable> </DataTable>
<Dialog <Dialog
visible={areaDialog} visible={areaDialog}

View File

@ -49,6 +49,7 @@ const Communities = () => {
const [editCommunityDialog, setEditCommunityDialog] = useState(false); const [editCommunityDialog, setEditCommunityDialog] = useState(false);
const toast = useRef(null); const toast = useRef(null);
const dt = useRef(null); const dt = useRef(null);
const [formCommunityDialog, setFormCommunityDialog] = useState(false);
//para el perfil de la comunidad //para el perfil de la comunidad
const [tenants, setTenants] = useState([]); const [tenants, setTenants] = useState([]);
@ -273,10 +274,37 @@ const Communities = () => {
if (response.status != 200) if (response.status != 200)
console.log('Ocurrió un error con el servicio: ' + response.status); console.log('Ocurrió un error con el servicio: ' + response.status);
else return response.json(); else return response.json();
}).catch((err) => console.log('Ocurrió un error con el fetch', err)); })
setSaveButtonLabel('Registrar'); .then(() => {
_community.province = provincesList.find(
(p) => p.code === _community.province,
).name;
_community.canton = cantonsList.find(
(p) => p.code === _community.canton,
).name;
_community.district = districtsList.find(
(p) => p.code === _community.district,
).name;
_communities.push(_community);
toast.current.show({
severity: 'success',
summary: 'Registro exitoso',
detail: 'Comunidad de vivienda Creada',
life: 3000,
});
setCommunitiesList(_communities);
setProvinciaId('');
setCantonId('');
setDistrictId('');
setCodeHouses('');
setFormCommunityDialog(false);
setCommunity(emptyCommunity); setCommunity(emptyCommunity);
} })
.catch((err) => console.log('Ocurrió un error con el fetch', err));
} else { } else {
setSubmitted(true); setSubmitted(true);
} }
@ -343,6 +371,16 @@ const Communities = () => {
setEditCommunityDialog(true); setEditCommunityDialog(true);
}; };
const openNewCommunity = () => {
setCommunity({ emptyCommunity });
setFormCommunityDialog(true);
};
const hideFormCommunityDialog = () => {
setCommunity({ emptyCommunity });
setFormCommunityDialog(false);
};
//desactivar o activar una comunidad //desactivar o activar una comunidad
const cambiarEstadoCommunity = () => { const cambiarEstadoCommunity = () => {
if (community.status == '1') { if (community.status == '1') {
@ -512,6 +550,12 @@ const Communities = () => {
return ( return (
<React.Fragment> <React.Fragment>
<div className="my-2"> <div className="my-2">
<Button
label="Agregar Comunidad"
icon="pi pi-plus"
className="p-button-primary mr-2"
onClick={openNewCommunity}
/>
<Button <Button
label="Eliminar" label="Eliminar"
icon="pi pi-trash" icon="pi pi-trash"
@ -561,6 +605,25 @@ const Communities = () => {
</> </>
); );
const formCommunityDialogFooter = (
<>
<Button
label={'Registrar'}
icon="pi pi-check"
className="p-button-primary"
onClick={saveCommunity}
/>
<Button
label="Cerrar"
icon="pi pi-times"
className="p-button-text"
onClick={hideFormCommunityDialog}
/>
</>
);
const deleteCommunityDialogFooter = ( const deleteCommunityDialogFooter = (
<> <>
<Button <Button
@ -673,8 +736,8 @@ const Communities = () => {
<> <>
<p> <p>
{' '} {' '}
<FontAwesomeIcon icon={faHashtag} style={{ color: '#D7A86E' }} /> Número <FontAwesomeIcon icon={faHashtag} style={{ color: '#D7A86E' }} />{' '}
de viviendas Cantidad de viviendas
</p> </p>
</> </>
); );
@ -713,6 +776,16 @@ const Communities = () => {
</> </>
); );
const headerCodeHouses = (
<>
<p>
{' '}
<FontAwesomeIcon icon={faHashtag} style={{ color: '#D7A86E' }} />{' '}
Código de vivienda
</p>
</>
);
const statusBodyTemplate = (rowData) => { const statusBodyTemplate = (rowData) => {
return ( return (
<> <>
@ -748,14 +821,14 @@ const Communities = () => {
value={communitiesList} value={communitiesList}
dataKey="_id" dataKey="_id"
paginator paginator
rows={5} rows={10}
selection={selectedCommunities} selection={selectedCommunities}
onSelectionChange={(e) => setSelectedCommunities(e.value)} onSelectionChange={(e) => setSelectedCommunities(e.value)}
scrollable scrollable
scrollHeight="400px" scrollHeight="800px"
scrollDirection="both" scrollDirection="both"
header={header} header={header}
rowsPerPageOptions={[5, 10, 25]} rowsPerPageOptions={[10, 20, 30]}
className="datatable-responsive mt-3" className="datatable-responsive mt-3"
paginatorTemplate="FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink CurrentPageReport RowsPerPageDropdown" paginatorTemplate="FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink CurrentPageReport RowsPerPageDropdown"
currentPageReportTemplate="Mostrando {first} a {last} de {totalRecords} comunidades de viviendas" currentPageReportTemplate="Mostrando {first} a {last} de {totalRecords} comunidades de viviendas"
@ -790,11 +863,6 @@ const Communities = () => {
header={headerDistrict} header={headerDistrict}
style={{ flexGrow: 1, flexBasis: '160px' }} style={{ flexGrow: 1, flexBasis: '160px' }}
></Column> ></Column>
<Column
field="phone"
header={headerPhone}
style={{ flexGrow: 1, flexBasis: '180px' }}
></Column>
<Column <Column
field="num_houses" field="num_houses"
sortable sortable
@ -821,7 +889,7 @@ const Communities = () => {
></Column> ></Column>
<Column <Column
body={actionsCommunity} body={actionsCommunity}
style={{ flexGrow: 2, flexBasis: '100px', flexDirection: 'row' }} style={{ flexGrow: 1, flexBasis: '160px' }}
></Column> ></Column>
</DataTable> </DataTable>
@ -837,13 +905,11 @@ const Communities = () => {
<div className="container text-center"> <div className="container text-center">
<div className="row my-4"> <div className="row my-4">
<div className=" col-12 md:col-12"> <div className=" col-12 md:col-12">
<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-home icon-khaki"></i> <i className="pi pi-home icon-khaki"></i>
<p><strong>Nombre</strong></p>
<div className="p-0 col-2 md:col-2" style={{ margin: '0 auto' }}>
<div className="p-inputgroup align-items-center justify-content-evenly">
<p>{community.name}</p> <p>{community.name}</p>
</div> </div>
</div> </div>
@ -851,25 +917,21 @@ const Communities = () => {
</div> </div>
<div className="row my-5"> <div className="row my-5">
<div className=" col-6 md:col-6"> <div className=" col-6 md:col-6">
<p>Administrador</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> <i className="pi pi-user icon-khaki"></i>
<p><strong>Administrador</strong></p>
<div className="p-0 col-6 md:col-6" style={{ margin: '0 auto' }}>
<div className="p-inputgroup align-items-center justify-content-evenly">
<p>{community.name_admin}</p> <p>{community.name_admin}</p>
</div> </div>
</div> </div>
</div> </div>
<div className=" col-6 md:col-6"> <div className=" col-6 md:col-6">
<p>Teléfono Administrativo</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-phone icon-khaki"></i> <i className="pi pi-phone icon-khaki"></i>
<p><strong>Teléfono Administrativo</strong></p>
<div className="p-0 col-6 md:col-6" style={{ margin: '0 auto' }}>
<div className="p-inputgroup align-items-center justify-content-evenly">
<p>{community.phone}</p> <p>{community.phone}</p>
</div> </div>
</div> </div>
@ -878,28 +940,31 @@ const Communities = () => {
<div className="row my-5"> <div className="row my-5">
<div className=" col-4 col-md-4 md:col-4"> <div className=" col-4 col-md-4 md:col-4">
<p>Provincia</p>
<div className="p-0 col-10 md:col-10">
<div className="p-inputgroup align-items-center justify-content-evenly">
<i className="pi pi-map-marker icon-khaki"></i> <i className="pi pi-map-marker icon-khaki"></i>
<p><strong>Provincia</strong></p>
<div className="p-0 col-12 md:col-12">
<div className="p-inputgroup align-items-center justify-content-evenly">
<p>{community.province}</p> <p>{community.province}</p>
</div> </div>
</div> </div>
</div> </div>
<div className=" col-4 md:col-4"> <div className=" col-4 md:col-4">
<p>Cantón</p>
<div className="p-0 col-10 md:col-10">
<div className="p-inputgroup align-items-center justify-content-evenly">
<i className="pi pi-map-marker icon-khaki"></i> <i className="pi pi-map-marker icon-khaki"></i>
<p><strong>Cantón</strong></p>
<div className="p-0 col-12 md:col-12">
<div className="p-inputgroup align-items-center justify-content-evenly">
<p>{community.canton}</p> <p>{community.canton}</p>
</div> </div>
</div> </div>
</div> </div>
<div className=" col-4 md:col-4"> <div className=" col-4 md:col-4">
<p>Distrito</p>
<div className="p-0 col-10 md:col-10">
<div className="p-inputgroup align-items-center justify-content-evenly">
<i className="pi pi-map-marker icon-khaki"></i> <i className="pi pi-map-marker icon-khaki"></i>
<p><strong>Distrito</strong></p>
<div className="p-0 col-12 md:col-12">
<div className="p-inputgroup align-items-center justify-content-evenly">
<p>{community.district}</p> <p>{community.district}</p>
</div> </div>
</div> </div>
@ -907,13 +972,11 @@ const Communities = () => {
</div> </div>
<div className="row my-5"> <div className="row my-5">
<div className=" col-12 md:col-12"> <div className=" col-12 md:col-12">
<p>Número de Viviendas</p>
<div
className="p-0 col-2 md:col-2"
style={{ margin: '0 auto' }}
>
<div className="p-inputgroup justify-content-evenly">
<i className="pi pi-hashtag icon-khaki"></i> <i className="pi pi-hashtag icon-khaki"></i>
<p><strong>Cantidad de viviendas</strong></p>
<div className="p-0 col-2 md:col-2" style={{ margin: '0 auto' }}>
<div className="p-inputgroup justify-content-evenly">
<p>{community.num_houses}</p> <p>{community.num_houses}</p>
</div> </div>
</div> </div>
@ -945,12 +1008,8 @@ const Communities = () => {
> >
<Column <Column
field="number_house" field="number_house"
header={headerNumberHouses} header={headerCodeHouses}
style={{ style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px' }}
flexGrow: 1,
flexBasis: '160px',
minWidth: '160px',
}}
></Column> ></Column>
<Column <Column
field="tenants" field="tenants"
@ -1032,11 +1091,14 @@ const Communities = () => {
)} )}
</div> </div>
</Dialog> </Dialog>
</div> <Dialog
</div> visible={formCommunityDialog}
<div className="col-12"> style={{ width: '850px' }}
<div className="card"> header="Mantenimiento de comunidad de viviendas"
<h5>Registro de comunidad de viviendas</h5> modal
footer={formCommunityDialogFooter}
onHide={hideFormCommunityDialog}
>
<div className="p-fluid formgrid grid"> <div className="p-fluid formgrid grid">
<div className="field col-12 md:col-12"> <div className="field col-12 md:col-12">
<label htmlFor="name">Nombre</label> <label htmlFor="name">Nombre</label>
@ -1209,24 +1271,9 @@ const Communities = () => {
)} )}
</div> </div>
</div> </div>
<div style={{
display: "flex",
justifyContent: "center",
gap: "10px",
width: "100%"
}} className="col-12 md:col-12 py-2">
<Button
label={saveButtonLabel}
icon="pi pi-check"
onClick={saveCommunity}
/>
{saveButtonLabel === 'Actualizar' && (
<Button
label="Cancelar"
onClick={cancelEdit}
className="p-button-danger" />)}
</div>
</div> </div>
</Dialog>
</div> </div>
</div> </div>
</div> </div>

View File

@ -46,6 +46,7 @@ const GuardasSeguridad = () => {
const [changeStatusGuardDialog, setChangeStatusGuardDialog] = useState(false); const [changeStatusGuardDialog, setChangeStatusGuardDialog] = useState(false);
const [guardDialog, setGuardDialog] = useState(false); const [guardDialog, setGuardDialog] = useState(false);
const [submitted, setSubmitted] = useState(false); const [submitted, setSubmitted] = useState(false);
const [formGuardDialog, setFormGuardDialog] = useState(false);
async function listaGuardasF() { async function listaGuardasF() {
@ -98,6 +99,8 @@ const GuardasSeguridad = () => {
return response.json(); return response.json();
}).then(() => { }).then(() => {
listaGuardasF(); listaGuardasF();
setFormGuardDialog(false)
setGuarda(emptyGuarda)
}).catch( }).catch(
err => console.log('Ocurrió un error con el fetch', err) err => console.log('Ocurrió un error con el fetch', err)
); );
@ -122,6 +125,8 @@ const GuardasSeguridad = () => {
detail: 'Guarda actualizado correctamente' detail: 'Guarda actualizado correctamente'
}); });
setGuarda(emptyGuarda); setGuarda(emptyGuarda);
setFormGuardDialog(false)
listaGuardasF(); listaGuardasF();
}) })
} }
@ -179,7 +184,7 @@ const GuardasSeguridad = () => {
console.log(`Ocurrió un error con el servicio: ${response.status}`); console.log(`Ocurrió un error con el servicio: ${response.status}`);
else else
return response.json(); return response.json();
}).then(function() { }).then(function () {
let _guarda = listaGuardas.filter(val => val._id !== guarda._id); let _guarda = listaGuardas.filter(val => val._id !== guarda._id);
setListaGuardas(_guarda); setListaGuardas(_guarda);
setDeleteGuardaDialog(false); setDeleteGuardaDialog(false);
@ -251,13 +256,29 @@ const GuardasSeguridad = () => {
const editGuard = (guard) => { const editGuard = (guard) => {
setGuarda(guard); setGuarda(guard);
console.log(guard); setFormGuardDialog(true)
setSaveButtonTitle("Actualizar"); setSaveButtonTitle("Actualizar");
} }
const cancelEdit = () => { const cancelEdit = () => {
setGuarda(emptyGuarda); setGuarda(emptyGuarda);
setSaveButtonTitle("Registrar"); setSaveButtonTitle("Registrar");
setFormGuardDialog(false)
}
const openNewGuard = () => {
setGuarda(emptyGuarda);
setFormGuardDialog(true)
setSubmitted(false);
};
const hideFormGuardDialog = () => {
setSubmitted(false);
setFormGuardDialog(false)
setGuarda(emptyGuarda);
setSaveButtonTitle('Registrar');
} }
const actionsGuard = (rowData) => { const actionsGuard = (rowData) => {
@ -300,6 +321,12 @@ const GuardasSeguridad = () => {
return ( return (
<React.Fragment> <React.Fragment>
<div className="my-2"> <div className="my-2">
<Button
label="Agregar Guarda"
icon="pi pi-plus"
className="p-button-primary mr-2"
onClick={openNewGuard}
/>
<Button label="Eliminar" <Button label="Eliminar"
icon="pi pi-trash" icon="pi pi-trash"
className="p-button-danger" className="p-button-danger"
@ -372,6 +399,22 @@ const GuardasSeguridad = () => {
</> </>
); );
const formGuardDialogFooter = (
<>
<Button
label={`${saveButtonTitle}`}
icon="pi pi-check"
className="p-button-primary"
onClick={registrarGuarda}
/>
<Button
label="Cerrar"
icon="pi pi-times"
className="p-button-text"
onClick={hideFormGuardDialog}
/>
</>
);
const headerName = ( const headerName = (
<> <>
@ -472,7 +515,7 @@ const GuardasSeguridad = () => {
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 style={{ flexGrow: 1, flexBasis: '80px', minWidth: '80px' }} body={actionsGuard}></Column> <Column style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px' }} body={actionsGuard}></Column>
</DataTable> </DataTable>
<Dialog <Dialog
visible={guardDialog} visible={guardDialog}
@ -484,30 +527,22 @@ const GuardasSeguridad = () => {
onHide={hideGuardDialog}> onHide={hideGuardDialog}>
<div className='container text-center'> <div className='container text-center'>
<div className='row my-4'> <div className='row my-4'>
<div className=" col-4 md:col-4"> <div className=" col-6 md:col-6">
<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> <i className="pi pi-user icon-khaki"></i>
<p>{guarda.name}</p> <p><strong>Nombre Completo</strong></p>
</div> <div className="p-0 col-12 md:col-12" style={{ margin: '0 auto' }}>
</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"> <div className="p-inputgroup align-items-center justify-content-evenly">
<i className="pi pi-user icon-khaki"></i> <p>{guarda.name + ' ' + guarda.last_name}</p>
<p>{guarda.last_name}</p> </div>
</div>
</div> </div>
</div> <div className=" col-6 col-md-6 md:col-6">
</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> <i className="pi pi-id-card icon-khaki"></i>
<p><strong>Identificación</strong></p>
<div className="p-0 col-12 md:col-12" style={{ margin: '0 auto' }}>
<div className="p-inputgroup align-items-center justify-content-evenly">
<p>{guarda.dni}</p> <p>{guarda.dni}</p>
</div> </div>
@ -517,21 +552,22 @@ const GuardasSeguridad = () => {
<div className='row my-5 justify-content-center'> <div className='row my-5 justify-content-center'>
</div> </div>
<div className='row my-5 justify-content-center'> <div className='row my-5 justify-content-center'>
<div className=" col-4 md:col-4"> <div className=" col-6 md:col-6">
<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> <i className="pi pi-phone icon-khaki"></i>
<p><strong>Teléfono</strong></p>
<div className="p-0 col-12 md:col-12">
<div className="p-inputgroup align-items-center justify-content-evenly">
<p>{guarda.phone}</p> <p>{guarda.phone}</p>
</div> </div>
</div> </div>
</div> </div>
<div className=" col-6 md:col-6"> <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> <i className="pi pi-envelope icon-khaki"></i>
<p><strong>Correo Electrónico</strong></p>
<div className="p-0 col-12 md:col-12" style={{ margin: '0 auto' }}>
<div className="p-inputgroup align-items-center justify-content-evenly">
<p>{guarda.email}</p> <p>{guarda.email}</p>
</div> </div>
@ -573,11 +609,14 @@ const GuardasSeguridad = () => {
)} )}
</div> </div>
</Dialog> </Dialog>
</div> <Dialog
</div> visible={formGuardDialog}
<div className="col-12"> style={{ width: '750px' }}
<div className="card"> header='Mantenimiento de Guarda de Seguridad'
<h5>Registro de un Guarda de Seguridad</h5> modal
footer={formGuardDialogFooter}
onHide={hideFormGuardDialog}
>
<div className="p-fluid formgrid grid"> <div className="p-fluid formgrid grid">
<div className="field col-12 md:col-6"> <div className="field col-12 md:col-6">
<label htmlFor="name">Nombre</label> <label htmlFor="name">Nombre</label>
@ -641,25 +680,12 @@ const GuardasSeguridad = () => {
&& <small className="p-invalid">Número de teléfono es requerido.</small>} && <small className="p-invalid">Número de teléfono es requerido.</small>}
</div> </div>
</div> </div>
<div style={{
display: "flex", </div>
justifyContent: "center", </Dialog>
gap: "10px",
width: "100%"
}}>
<Button
label={`${saveButtonTitle}`}
onClick={registrarGuarda}
/>
{saveButtonTitle === 'Actualizar' && (
<Button
label="Cancel"
onClick={cancelEdit}
className="p-button-danger" />)}
</div>
</div>
</div> </div>
</div> </div>
</div> </div>
); );
}; };

View File

@ -51,6 +51,8 @@ const Inquilinos = () => {
const dt = useRef(null) const dt = useRef(null)
const [cookies] = useCookies() const [cookies] = useCookies()
const [changeStatusTenantDialog, setChangeStatusTenantDialog] = useState(false) const [changeStatusTenantDialog, setChangeStatusTenantDialog] = useState(false)
const [tenantDialog, setTenantDialog] = useState(false)
async function tenantsList() { async function tenantsList() {
await fetch( await fetch(
@ -155,6 +157,8 @@ const Inquilinos = () => {
setTenants(_tenants) setTenants(_tenants)
setTenant(emptyTenant) setTenant(emptyTenant)
setHouseNumber('') setHouseNumber('')
setTenantDialog(false)
}) })
.catch((error) => console.log(`Ocurrió un error: ${error}`)) .catch((error) => console.log(`Ocurrió un error: ${error}`))
} else setSubmitted(true) } else setSubmitted(true)
@ -193,6 +197,8 @@ const Inquilinos = () => {
tenantsList() tenantsList()
setTenant(emptyTenant) setTenant(emptyTenant)
setHouseNumber('') setHouseNumber('')
setTenantDialog(false)
}) })
} }
} }
@ -352,17 +358,34 @@ const Inquilinos = () => {
const editTenant = (tenant) => { const editTenant = (tenant) => {
setTenant(tenant); setTenant(tenant);
console.log(tenant);
setSaveButtonTitle('Actualizar'); setSaveButtonTitle('Actualizar');
setHouseNumber(tenant.number_house); setHouseNumber(tenant.number_house);
setTenantDialog(true)
} }
const cancelEdit = () => { const cancelEdit = () => {
setTenant(emptyTenant); setTenant(emptyTenant);
setSaveButtonTitle('Registrar'); setSaveButtonTitle('Registrar');
setHouseNumber(''); setHouseNumber('');
setTenantDialog(false)
} }
const openNewTenant = () => {
setTenant(emptyTenant);
setTenantDialog(true)
setSubmitted(false);
};
const hideTenantDialog = () => {
setSubmitted(false);
setTenantDialog(false)
setTenant(emptyTenant);
setSaveButtonTitle('Registrar');
};
const actionsTenant = (rowData) => { const actionsTenant = (rowData) => {
let icono = '' let icono = ''
let text = '' let text = ''
@ -407,6 +430,12 @@ const Inquilinos = () => {
return ( return (
<React.Fragment> <React.Fragment>
<div className='my-2'> <div className='my-2'>
<Button
label="Agregar Inquilino"
icon="pi pi-plus"
className="p-button-primary mr-2"
onClick={openNewTenant}
/>
<Button <Button
label='Eliminar' label='Eliminar'
icon='pi pi-trash' icon='pi pi-trash'
@ -507,6 +536,23 @@ const Inquilinos = () => {
</> </>
); );
const tenantDialogFooter = (
<>
<Button
label={`${saveButtonTitle}`}
icon="pi pi-check"
className="p-button-primary"
onClick={saveTenant}
/>
<Button
label="Cerrar"
icon="pi pi-times"
className="p-button-text"
onClick={hideTenantDialog}
/>
</>
);
const headerName = ( const headerName = (
<> <>
<p> <p>
@ -610,14 +656,14 @@ const Inquilinos = () => {
value={tenants} value={tenants}
dataKey='_id' dataKey='_id'
paginator paginator
rows={5} rows={10}
selection={selectedTentants} selection={selectedTentants}
onSelectionChange={(e) => setSelectedTenants(e.value)} onSelectionChange={(e) => setSelectedTenants(e.value)}
scrollable scrollable
scrollHeight='400px' scrollHeight='800px'
scrollDirection='both' scrollDirection='both'
header={header} header={header}
rowsPerPageOptions={[5, 10, 25]} rowsPerPageOptions={[10, 20, 30]}
className='datatable-responsive mt-3' className='datatable-responsive mt-3'
paginatorTemplate='FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink CurrentPageReport RowsPerPageDropdown' paginatorTemplate='FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink CurrentPageReport RowsPerPageDropdown'
currentPageReportTemplate='Mostrando {first} a {last} de {totalRecords} inquilinos' currentPageReportTemplate='Mostrando {first} a {last} de {totalRecords} inquilinos'
@ -673,16 +719,7 @@ const Inquilinos = () => {
wordBreak: 'break-word', wordBreak: 'break-word',
}} }}
></Column> ></Column>
<Column
field='phone'
header={headerPhone}
style={{
flexGrow: 1,
flexBasis: '80px',
minWidth: '80px',
wordBreak: 'break-word',
}}
></Column>
<Column <Column
field='number_house' field='number_house'
sortable sortable
@ -707,7 +744,7 @@ const Inquilinos = () => {
wordBreak: 'break-word', wordBreak: 'break-word',
}} }}
></Column> ></Column>
<Column style={{ flexGrow: 1, flexBasis: '80px', minWidth: '80px' }} body={actionsTenant}></Column> <Column style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px' }} body={actionsTenant}></Column>
</DataTable> </DataTable>
<Dialog <Dialog
visible={infoDialogVisible} visible={infoDialogVisible}
@ -780,68 +817,67 @@ const Inquilinos = () => {
</Dialog> </Dialog>
<Dialog <Dialog
visible={deleteTenantDialog} visible={infoDialogVisible}
style={{ width: '450px' }} style={{ width: '650px' }}
header='Confirmar' header="Información del Inquilino"
modal modal
footer={deleteTenantDialogFooter} className="p-fluid"
onHide={hideDeleteTenantDialog} footer={infoDialogFooter}
> onHide={hideInfoDialog}>
<div className='flex align-items-center justify-content-center'> <div className='container text-center'>
<i <div className='row my-4 justify-content-center'>
className='pi pi-exclamation-triangle mr-3' <div className=" col-6 md:col-6">
style={{ fontSize: '2rem' }} <i className="pi pi-user icon-khaki"></i>
/> <p><strong>Nombre Completo</strong></p>
{tenant && ( <div className="p-0 col-12 md:col-12" style={{ margin: '0 auto' }}>
<span> <div className="p-inputgroup align-items-center justify-content-evenly">
¿Estás seguro que desea eliminar a <b>{tenant.name}</b>? <p>{tenant.name + ' ' + tenant.last_name} </p>
</span> </div>
)} </div>
</div>
<div className=" col-6 col-md-6 md:col-6">
<i className="pi pi-id-card icon-khaki"></i>
<p><strong>Identificación</strong></p>
<div className="p-0 col-10 md:col-10" style={{ margin: '0 auto' }}>
<div className="p-inputgroup align-items-center justify-content-evenly">
<p>{tenant.dni}</p>
</div>
</div>
</div>
</div>
<div className='row my-5 justify-content-center'>
<div className=" col-6 md:col-6">
<i className="pi pi-phone icon-khaki"></i>
<p><strong>Teléfono</strong></p>
<div className="p-0 col-12 md:col-12">
<div className="p-inputgroup align-items-center justify-content-evenly">
<p>{tenant.phone}</p>
</div>
</div>
</div>
<div className=" col-6 md:col-6">
<i className="pi pi-envelope icon-khaki"></i>
<p><strong>Correo Electrónico</strong></p>
<div className="p-0 col-12 md:col-12" style={{ margin: '0 auto' }}>
<div className="p-inputgroup align-items-center justify-content-evenly">
<p>{tenant.email}</p>
</div>
</div>
</div>
</div>
</div> </div>
</Dialog> </Dialog>
<Dialog <Dialog
visible={deleteTenantsDialog} visible={tenantDialog}
style={{ width: '450px' }} style={{ width: '750px' }}
header='Confirmar' header='Mantenimiento de inquilino'
modal modal
footer={deleteTenantsDialogFooter} footer={tenantDialogFooter}
onHide={hideDeleteTenantsDialog} onHide={hideTenantDialog}
> >
<div className='flex align-items-center justify-content-center'>
<i
className='pi pi-exclamation-triangle mr-3'
style={{ fontSize: '2rem' }}
/>
{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>
</Dialog>
</div>
</div>
<div className="col-12">
<div className="card">
<h5>Registro de un Inquilino</h5>
<div className="p-fluid formgrid grid"> <div className="p-fluid formgrid grid">
<div className="field col-12 md:col-6"> <div className="field col-12 md:col-6">
<label htmlFor="name">Nombre</label> <label htmlFor="name">Nombre</label>
@ -928,26 +964,52 @@ const Inquilinos = () => {
&& <small className="p-invalid">Casa es requerida.</small>} && <small className="p-invalid">Casa es requerida.</small>}
</div> </div>
</div> </div>
<div style={{
display: "flex",
justifyContent: "center", </div>
gap: "10px", </Dialog>
width: "100%" <Dialog
}}> visible={deleteTenantsDialog}
<Button style={{ width: '450px' }}
label={`${saveButtonTitle}`} header='Confirmar'
onClick={saveTenant} modal
footer={deleteTenantsDialogFooter}
onHide={hideDeleteTenantsDialog}
>
<div className='flex align-items-center justify-content-center'>
<i
className='pi pi-exclamation-triangle mr-3'
style={{ fontSize: '2rem' }}
/> />
{saveButtonTitle === 'Actualizar' && ( {selectedTentants && (
<Button <span>¿Está seguro eliminar los inquilinos seleccionados?</span>
label="Cancelar" )}
onClick={cancelEdit}
className="p-button-danger" />)}
</div>
</div>
</div> </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>
</div> </div>
</div >
</div >
) )
} }

View File

@ -171,41 +171,35 @@ const InvitadosComunidad = () => {
globalFilter={globalFilter} globalFilter={globalFilter}
emptyMessageTemplate="No se encontraron invitados" emptyMessageTemplate="No se encontraron invitados"
> >
<Column field="name" header="Nombre" sortable header={headerName} /> <Column field="name" sortable header={headerName} />
<Column <Column
field="last_name" field="last_name"
header="Apellido"
sortable sortable
header={headerLastName} header={headerLastName}
/> />
<Column field="dni" header="DNI" sortable header={headerDNI} /> <Column field="dni" sortable header={headerDNI} />
<Column <Column
field="number_plate" field="number_plate"
header="Placa"
sortable sortable
header={headerPlate} header={headerPlate}
/> />
<Column <Column
field="telefono" field="telefono"
header="Teléfono"
sortable sortable
header={headerPhone} header={headerPhone}
/> />
<Column <Column
field="email" field="email"
header="Email"
sortable sortable
header={headerEmail} header={headerEmail}
/> />
<Column <Column
field="date_entry" field="date_entry"
header="Fecha de registro"
sortable sortable
header={headerName} header={headerName}
/> />
<Column <Column
field="tenant_name" field="tenant_name"
header="Inquilino"
sortable sortable
header={headerTenant} header={headerTenant}
/> />

View File

@ -37,6 +37,9 @@ const RegistroComunicado = () => {
const dt = useRef(null); const dt = useRef(null);
const [cookies, setCookie] = useCookies(); const [cookies, setCookie] = useCookies();
const [globalFilter, setGlobalFilter] = useState(null); const [globalFilter, setGlobalFilter] = useState(null);
const [postDialog, setPostDialog] = useState(false);
async function listaComunis() { async function listaComunis() {
let comunicadosResponse = await fetch('http://localhost:4000/post/allPosts', { method: 'GET' }); let comunicadosResponse = await fetch('http://localhost:4000/post/allPosts', { method: 'GET' });
@ -127,6 +130,12 @@ const RegistroComunicado = () => {
return ( return (
<React.Fragment> <React.Fragment>
<div className="my-2"> <div className="my-2">
<Button
label="Agregar Comunicado"
icon="pi pi-plus"
className="p-button-primary mr-2"
onClick={openNewPost}
/>
<Button label="Eliminar" icon="pi pi-trash" className="p-button-danger" /> <Button label="Eliminar" icon="pi pi-trash" className="p-button-danger" />
</div> </div>
</React.Fragment> </React.Fragment>
@ -145,6 +154,8 @@ const RegistroComunicado = () => {
setComunicado(rowData); setComunicado(rowData);
setComunicadoId(rowData._id); setComunicadoId(rowData._id);
setSaveButtonLabel('Actualizar'); setSaveButtonLabel('Actualizar');
setPostDialog(true)
} }
const cancelEdit = () => { const cancelEdit = () => {
@ -177,6 +188,20 @@ const RegistroComunicado = () => {
setShowDeleteDialog(true); setShowDeleteDialog(true);
} }
const openNewPost = () => {
setComunicado(emptyComunicado);
setPostDialog(true)
setSubmitted(false);
};
const hidePostDialog = () => {
setSubmitted(false);
setPostDialog(false)
setComunicado(emptyComunicado);
setSaveButtonLabel('Registrar');
}
const deleteDialogFooter = ( const deleteDialogFooter = (
<> <>
<Button label="Cancelar" icon="pi pi-times" className="p-button-secondary" onClick={() => setShowDeleteDialog(false)} /> <Button label="Cancelar" icon="pi pi-times" className="p-button-secondary" onClick={() => setShowDeleteDialog(false)} />
@ -184,6 +209,23 @@ const RegistroComunicado = () => {
</> </>
); );
const postDialogFooter = (
<>
<Button
label={`${saveButtonLabel}`}
icon="pi pi-check"
className="p-button-primary"
onClick={saveComunicado}
/>
<Button
label="Cerrar"
icon="pi pi-times"
className="p-button-text"
onClick={hidePostDialog}
/>
</>
);
const deleteComunicado = () => { const deleteComunicado = () => {
fetch(`http://localhost:4000/post/deletePost/${comunicado._id}`, { fetch(`http://localhost:4000/post/deletePost/${comunicado._id}`, {
cache: 'no-cache', cache: 'no-cache',
@ -235,11 +277,14 @@ const RegistroComunicado = () => {
}} }}
body={actions} /> body={actions} />
</DataTable> </DataTable>
</div> <Dialog
</div> visible={postDialog}
<div className="col-12"> style={{ width: '650px' }}
<div className="card"> header="Mantenimiento del Comunicado"
<h5>Registro de un comunicado para la comunidad</h5> modal
className="p-fluid"
footer={postDialogFooter}
onHide={hidePostDialog}>
<div className="p-fluid formgrid grid"> <div className="p-fluid formgrid grid">
<div className="field col-12 md:col-12"> <div className="field col-12 md:col-12">
<label htmlFor="name">Contenido del comunicado</label> <label htmlFor="name">Contenido del comunicado</label>
@ -261,25 +306,13 @@ const RegistroComunicado = () => {
</div> </div>
</div> </div>
</div> </div>
<div style={{
display: "flex", </div>
justifyContent: "center",
gap: "10px", </Dialog>
width: "100%"
}}>
<Button
label={`${saveButtonLabel}`}
onClick={saveComunicado}
/>
{saveButtonLabel === 'Actualizar' && (
<Button
label="Cancelar"
onClick={cancelEdit}
className="p-button-danger" />)}
</div>
</div>
</div> </div>
</div> </div>
</div> </div>
); );
}; };