agregar status en listar areas comunes

This commit is contained in:
Mariela 2022-08-01 01:23:33 -06:00
parent 6e24540d00
commit fc2dc8e2a6
2 changed files with 90 additions and 60 deletions

View File

@ -19,6 +19,9 @@ export class CommonArea {
@Prop() @Prop()
bookable: number; //saber si es necesario reservarlo o no bookable: number; //saber si es necesario reservarlo o no
@Prop()
status: string;
@Prop() @Prop()
community_id: string; community_id: string;
} }

View File

@ -29,6 +29,8 @@ const AreasComunes = () => {
community_id: '', community_id: '',
bookable: '1', bookable: '1',
bookable_text: '', bookable_text: '',
status: '1',
status_text: '',
}; };
const [commonAreaList, setCommonAreaList] = useState([]); const [commonAreaList, setCommonAreaList] = useState([]);
@ -51,9 +53,17 @@ const AreasComunes = () => {
if (data) { if (data) {
data.map(item => { data.map(item => {
if (item.bookable == '1') { if (item.bookable == '1') {
item.bookable_text = 'Disponible'; item.bookable_text = 'Obligatoria';
} else { } else {
item.bookable_text = 'Cerrado'; item.bookable_text = 'Libre';
}
if (item.status == '1') {
item.status_text = 'Activo';
} else if(item.status == '0') {
item.status_text = 'Inactivo';
} else {
item.status_text = 'Eliminado';
} }
}) })
} }
@ -67,7 +77,7 @@ const AreasComunes = () => {
const deleteCommonArea = () => { const deleteCommonArea = () => {
/* fetch('http://localhost:4000/community/deleteCommunity/' + community._id, { fetch('http://localhost:4000/commonArea/deleteCommonArea/' + commonArea._id, {
cache: 'no-cache', cache: 'no-cache',
method: 'DELETE', method: 'DELETE',
headers: { headers: {
@ -85,20 +95,6 @@ const AreasComunes = () => {
.then( .then(
function (response) { function (response) {
let _community = communities.filter(val => val._id !== community._id);
setCommunities(_community);
setDeleteCommunityDialog(false);
setCommunity(emptyCommunity);
toast.current.show({ severity: 'success', summary: 'Exito', detail: 'Comunidad de Viviendas Eliminada', life: 3000 });
}
)
.catch(
err => {
console.log('Ocurrió un error con el fetch', err)
toast.current.show({ severity: 'danger', summary: 'Error', detail: 'Comunidad de Viviendas no se pudo eliminar', life: 3000 });
}
);
*/
let _common_areas = commonAreaList.filter( let _common_areas = commonAreaList.filter(
(val) => val._id !== commonArea._id, (val) => val._id !== commonArea._id,
); );
@ -110,6 +106,15 @@ const AreasComunes = () => {
summary: 'Área Común Eliminada', summary: 'Área Común Eliminada',
life: 3000, life: 3000,
}); });
}
)
.catch(
err => {
console.log('Ocurrió un error con el fetch', err)
toast.current.show({ severity: 'danger', summary: 'Error', detail: 'Área Común no se pudo eliminar', life: 3000 });
}
);
}; };
const deleteSelectedCommonAreas = () => { const deleteSelectedCommonAreas = () => {
@ -247,13 +252,22 @@ const AreasComunes = () => {
<> <>
<p> {' '} <p> {' '}
<FontAwesomeIcon icon={faAt} style={{ color: "#D7A86E" }} />{' '} <FontAwesomeIcon icon={faAt} style={{ color: "#D7A86E" }} />{' '}
Reservable Reservación
</p>
</>
)
const headerStatus = (
<>
<p> {' '}
<FontAwesomeIcon icon={faAt} style={{ color: "#C08135" }} />{' '}
Estado
</p> </p>
</> </>
) )
const statusBodyTemplate = (rowData) => { const bookableBodyTemplate = (rowData) => {
return ( return (
<> <>
<span <span
@ -265,6 +279,18 @@ const AreasComunes = () => {
); );
}; };
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">
@ -281,7 +307,8 @@ const AreasComunes = () => {
<Column field="name" sortable header={headerName} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}></Column> <Column field="name" sortable header={headerName} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}></Column>
<Column field="hourMin" header={headerHourMin} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }} alignFrozen="left"></Column> <Column field="hourMin" header={headerHourMin} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }} alignFrozen="left"></Column>
<Column field="hourMax" header={headerHourMax} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}> </Column> <Column field="hourMax" header={headerHourMax} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}> </Column>
<Column field="bookable" sortable header={headerBookable} body={statusBodyTemplate} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}></Column> <Column field="bookable" sortable header={headerBookable} body={bookableBodyTemplate} 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: '130px', minWidth: '130px' }} body={actionsCommonArea}></Column> <Column style={{ flexGrow: 1, flexBasis: '130px', minWidth: '130px' }} body={actionsCommonArea}></Column>
</DataTable> </DataTable>
<Dialog visible={deleteCommonAreaDialog} style={{ width: '450px' }} header="Confirmar" modal footer={deleteCommonAreaDialogFooter} onHide={hideDeleteCommonAreaDialog}> <Dialog visible={deleteCommonAreaDialog} style={{ width: '450px' }} header="Confirmar" modal footer={deleteCommonAreaDialogFooter} onHide={hideDeleteCommonAreaDialog}>