diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index abc90be1..94b6fc14 100644 --- a/api-gateway/src/app.controller.ts +++ b/api-gateway/src/app.controller.ts @@ -155,6 +155,12 @@ export class AppController { return this.appService.deleteAdminSystem(id); } + @Delete('user/deleteAdminCommunity/:id') + deleteAdminCommunity(@Param('id') id: string) { + return this.appService.deleteAdminCommunity(id); + } + + @Post('user/changeStatus') changeStatusUser( @Body('id') pId: string, @@ -215,6 +221,8 @@ export class AppController { ) { return this.appService.changeStatusCommunity(pId, pStatus); } + + // #==== API Common Areas @Post('commonArea/createCommonArea') createCommonArea( @@ -254,6 +262,14 @@ export class AppController { return this.appService.deleteCommonArea(id); } + @Post('commonArea/changeStatus') + changeStatusCommonArea( + @Body('id') pId: string, + @Body('status') pStatus: string, + ) { + return this.appService.changeStatusCommonArea(pId, pStatus); + } + // #==== API GUEST //#API userService - create user @Post('guest/createGuest') diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index a5df9129..42e9bf22 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -193,6 +193,14 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } + deleteAdminCommunity(id: string) { + const pattern = { cmd: 'deleteAdminCommunity' }; + const payload = { id: id }; + return this.clientUserApp + .send(pattern, payload) + .pipe(map((message: string) => ({ message }))); + } + inicioSesion(pEmail: string, pPassword: string) { const pattern = { cmd: 'loginUser' }; const payload = { email: pEmail, password: pPassword }; @@ -343,6 +351,15 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } + changeStatusCommonArea(pId: string, pStatus: string) { + const pattern = { cmd: 'changeStatus' }; + const payload = { id: pId, status: pStatus }; + return this.clientCommonAreaApp + .send(pattern, payload) + .pipe(map((message: string) => ({ message }))); + } + + // ====================== GUESTS =============================== //POST parameter from API diff --git a/servicio-areas-comunes/src/common_areas/common_areas.controller.ts b/servicio-areas-comunes/src/common_areas/common_areas.controller.ts index b4374c7d..28b5ce7e 100644 --- a/servicio-areas-comunes/src/common_areas/common_areas.controller.ts +++ b/servicio-areas-comunes/src/common_areas/common_areas.controller.ts @@ -39,4 +39,12 @@ export class CommonAreasController { let _community_id = id['community_id']; return this.commonAreasService.findByCommunity(_community_id); } + + //cambiar de estado + @MessagePattern({ cmd: 'changeStatus' }) + changeStatus(@Payload() body: string) { + let pid = body['id']; + let pstatus = body['status']; + return this.commonAreasService.changeStatus(pid,pstatus); + } } diff --git a/servicio-areas-comunes/src/common_areas/common_areas.service.ts b/servicio-areas-comunes/src/common_areas/common_areas.service.ts index 9135b5a2..e617df0c 100644 --- a/servicio-areas-comunes/src/common_areas/common_areas.service.ts +++ b/servicio-areas-comunes/src/common_areas/common_areas.service.ts @@ -41,4 +41,10 @@ export class CommonAreasService { return this.commonAreaModel.find({ community_id: community_id }).exec(); } + async changeStatus(id: string, status: string) { + return this.commonAreaModel.findOneAndUpdate({ _id: id }, {status: status}, { + new: true, + }); + } + } diff --git a/servicio-usuarios/src/users/users.controller.ts b/servicio-usuarios/src/users/users.controller.ts index a32d265d..e8f261a4 100644 --- a/servicio-usuarios/src/users/users.controller.ts +++ b/servicio-usuarios/src/users/users.controller.ts @@ -112,11 +112,16 @@ export class UsersController { @MessagePattern({ cmd: 'deleteAdminSystem' }) deleteAdminSystem(@Payload() user: any) { - console.log('entró'); - return this.userService.deleteAdminSystem(user['id']); } + + @MessagePattern({ cmd: 'deleteAdminCommunity' }) + deleteAdminCommunity(@Payload() user: any) { + return this.userService.deleteAdminCommunity(user['id']); + } + + @MessagePattern({ cmd: 'changeStatus' }) changeStatus(@Payload() body: string) { diff --git a/servicio-usuarios/src/users/users.service.ts b/servicio-usuarios/src/users/users.service.ts index 2015ef45..0cd70023 100644 --- a/servicio-usuarios/src/users/users.service.ts +++ b/servicio-usuarios/src/users/users.service.ts @@ -185,6 +185,13 @@ export class UsersService { }); } + + deleteAdminCommunity(id: string) { + return this.userModel.findOneAndUpdate({ _id: id }, {status: '-1'}, { + new: true, + }); + } + async validateEmail(email: string) { let repo1 = this.userModel; return new Promise((resolve, reject) => { diff --git a/web-ui/web-react/package-lock.json b/web-ui/web-react/package-lock.json index e9ff9cd3..6699ac1c 100644 --- a/web-ui/web-react/package-lock.json +++ b/web-ui/web-react/package-lock.json @@ -17,7 +17,8 @@ "@fullcalendar/interaction": "^5.7.2", "@fullcalendar/react": "^5.7.0", "@fullcalendar/timegrid": "^5.7.2", - "axios": "^0.19.0", + "axios": "^0.19.2", + "bootstrap": "^5.2.0", "chart.js": "3.3.2", "classnames": "^2.2.6", "cors": "^2.8.5", @@ -2288,6 +2289,16 @@ "node": ">= 6" } }, + "node_modules/@popperjs/core": { + "version": "2.11.6", + "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.6.tgz", + "integrity": "sha512-50/17A98tWUfQ176raKiOGXuYpLyyVMkxxG6oylzL3BPOlA6ADGdK7EYunSa4I064xerltq9TGXs8HmOk5E+vw==", + "peer": true, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/popperjs" + } + }, "node_modules/@svgr/babel-plugin-add-jsx-attribute": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/@svgr/babel-plugin-add-jsx-attribute/-/babel-plugin-add-jsx-attribute-4.2.0.tgz", @@ -4210,6 +4221,24 @@ "resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz", "integrity": "sha512-JZOSA7Mo9sNGB8+UjSgzdLtokWAky1zbztM3WRLCbZ70/3cTANmQmOdR7y2g+J0e2WXywy1yS468tY+IruqEww==" }, + "node_modules/bootstrap": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-5.2.0.tgz", + "integrity": "sha512-qlnS9GL6YZE6Wnef46GxGv1UpGGzAwO0aPL1yOjzDIJpeApeMvqV24iL+pjr2kU4dduoBA9fINKWKgMToobx9A==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/twbs" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/bootstrap" + } + ], + "peerDependencies": { + "@popperjs/core": "^2.11.5" + } + }, "node_modules/brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -19688,6 +19717,12 @@ "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-1.1.3.tgz", "integrity": "sha512-shAmDyaQC4H92APFoIaVDHCx5bStIocgvbwQyxPRrbUY20V1EYTbSDchWbuwlMG3V17cprZhA6+78JfB+3DTPw==" }, + "@popperjs/core": { + "version": "2.11.6", + "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.6.tgz", + "integrity": "sha512-50/17A98tWUfQ176raKiOGXuYpLyyVMkxxG6oylzL3BPOlA6ADGdK7EYunSa4I064xerltq9TGXs8HmOk5E+vw==", + "peer": true + }, "@svgr/babel-plugin-add-jsx-attribute": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/@svgr/babel-plugin-add-jsx-attribute/-/babel-plugin-add-jsx-attribute-4.2.0.tgz", @@ -21217,6 +21252,12 @@ "resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz", "integrity": "sha512-JZOSA7Mo9sNGB8+UjSgzdLtokWAky1zbztM3WRLCbZ70/3cTANmQmOdR7y2g+J0e2WXywy1yS468tY+IruqEww==" }, + "bootstrap": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-5.2.0.tgz", + "integrity": "sha512-qlnS9GL6YZE6Wnef46GxGv1UpGGzAwO0aPL1yOjzDIJpeApeMvqV24iL+pjr2kU4dduoBA9fINKWKgMToobx9A==", + "requires": {} + }, "brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", diff --git a/web-ui/web-react/package.json b/web-ui/web-react/package.json index 12dd1f1d..4cb7843c 100644 --- a/web-ui/web-react/package.json +++ b/web-ui/web-react/package.json @@ -17,7 +17,8 @@ "@fullcalendar/interaction": "^5.7.2", "@fullcalendar/react": "^5.7.0", "@fullcalendar/timegrid": "^5.7.2", - "axios": "^0.19.0", + "axios": "^0.19.2", + "bootstrap": "^5.2.0", "chart.js": "3.3.2", "classnames": "^2.2.6", "cors": "^2.8.5", diff --git a/web-ui/web-react/src/App.js b/web-ui/web-react/src/App.js index ef05324a..2b95c37c 100644 --- a/web-ui/web-react/src/App.js +++ b/web-ui/web-react/src/App.js @@ -34,6 +34,8 @@ import GuardasSeguridad from './components/GuardasSeguridad'; import Communities from './components/ComunidadViviendas'; import Inquilinos from './components/Inquilinos'; import InquilinosCompletar from "./components/InquilinosCompletar.js"; +import RegistroComunicado from './components/RegistroComunicado'; +import "../node_modules/bootstrap/dist/css/bootstrap.min.css"; import Crud from './pages/Crud'; import EmptyPage from './pages/EmptyPage'; @@ -200,6 +202,9 @@ const App = () => { icon: PrimeIcons.BUILDING, to: '/areasComunes', }, + + { label: 'Comunicados', icon: PrimeIcons.COMMENTS, to: '/registroComunicado'}, + ] }, ] @@ -440,7 +445,6 @@ const App = () => { <> - ) @@ -453,7 +457,6 @@ const App = () => { - ) @@ -465,8 +468,7 @@ const App = () => { - - + ) } else { @@ -479,7 +481,6 @@ const App = () => { return ( <> } /> - @@ -502,8 +503,6 @@ const App = () => { - - ) diff --git a/web-ui/web-react/src/components/AdministradoresComunidad.js b/web-ui/web-react/src/components/AdministradoresComunidad.js index 826f0619..0ec73891 100644 --- a/web-ui/web-react/src/components/AdministradoresComunidad.js +++ b/web-ui/web-react/src/components/AdministradoresComunidad.js @@ -11,7 +11,7 @@ import { faHome, faUserAlt } from '@fortawesome/free-solid-svg-icons'; import { faPhoneAlt } from '@fortawesome/free-solid-svg-icons'; import { faAt } 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'; import { faHomeAlt } from '@fortawesome/free-solid-svg-icons'; import { Dropdown } from 'primereact/dropdown'; import classNames from 'classnames'; @@ -31,7 +31,8 @@ const AdministradoresComunidad = () => { community_name: '', user_type: '2', date_entry: new Date(), - status: '1' + status: '1', + status_text: '', }; const [listaAdmins, setListaAdmins] = useState([]); @@ -47,12 +48,23 @@ const AdministradoresComunidad = () => { const toast = useRef(null); const dt = useRef(null); + const [changeStatusAdminCommunityDialog, setChangeStatusAdminCommunityDialog] = useState(false); + async function listaAdmin() { - let nombres = await fetch('http://localhost:4000/user/findAdminComunidad/', { method: 'GET' }) + await fetch('http://localhost:4000/user/findAdminComunidad/', { method: 'GET' }) .then((response) => response.json()) .then((data) => { return Promise.all(data.message.map(item => { + + + if (item.status == '1') { + item.status_text = 'Activo'; + } else if (item.status == '0') { + item.status_text = 'Inactivo'; + } else { + item.status_text = 'Eliminado'; + } //item.full_name returns the repositorie name return fetch(`http://localhost:4000/community/findCommunityName/${item.community_id}`, { method: 'GET' }) .then((response2) => response2.json()) @@ -63,7 +75,13 @@ const AdministradoresComunidad = () => { }) })); }) - .then(data => setListaAdmins(data)); + .then(data => { + data = data.filter( + (val) => val.status != -1, + ); + console.log(data) + setListaAdmins(data); + }); } @@ -72,11 +90,16 @@ const AdministradoresComunidad = () => { async function getCommunites() { - let response = await fetch('http://localhost:4000/community/allCommunities', { method: 'GET' }); - let resList = await response.json(); - let list = await resList.message; + let response = await fetch('http://localhost:4000/community/allCommunities', { method: 'GET' }) + .then((response) => response.json()) + .then(data => data.message) + .then(data => { + data = data.filter( + (val) => val.status != -1, + ) + setCommunitiesList(data); - setCommunitiesList(await list); + }) } useEffect(() => { @@ -85,7 +108,7 @@ const AdministradoresComunidad = () => { useEffect(() => { getCommunites(); - },[]) + }, []) const cList = communitiesList.map((item) => ({ label: item.name, @@ -94,64 +117,56 @@ const AdministradoresComunidad = () => { const deleteAdminCommunity = () => { - /* fetch('http://localhost:4000/community/deleteCommunity/' + community._id, { - cache: 'no-cache', - method: 'DELETE', - 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 _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 _administrators = listaAdmins.filter( - (val) => val._id !== adminCommunity._id, - ); - setListaAdmins(_administrators); - setDeleteAdminCommunityDialog(false); - setAdminCommunity(emptyAdminCommunity); - toast.current.show({ - severity: 'success', - summary: 'Administrador de Comunidad Eliminada', - life: 3000, - }); + fetch('http://localhost:4000/user/deleteAdminCommunity/' + adminCommunity._id, { + cache: 'no-cache', + method: 'DELETE', + 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 _administrators = listaAdmins.filter( + (val) => val._id !== adminCommunity._id, + ); + setListaAdmins(_administrators); + setDeleteAdminCommunityDialog(false); + setAdminCommunity(emptyAdminCommunity); + toast.current.show({ severity: 'success', summary: 'Exito', detail: 'Administrador Comunidad Eliminada', life: 3000 }); + } + ) + .catch( + err => { + console.log('Ocurrió un error con el fetch', err) + toast.current.show({ severity: 'danger', summary: 'Error', detail: 'Administrador Comunidad no se pudo eliminar', life: 3000 }); + } + ); + + }; const deleteSelectedAdminsCommunity = () => { let _admins = listaAdmins.filter( (val) => !selectedAdminsCommunities.includes(val), ); - /* selectedCommunities.map((item) => { - fetch('http://localhost:4000/user/deleteCommunity/' + item._id, { + selectedAdminsCommunities.map((item) => { + fetch('http://localhost:4000/user/deleteAdminCommunity/' + item._id, { cache: 'no-cache', method: 'DELETE', headers: { 'Content-Type': 'application/json' } }) - })*/ + }) setListaAdmins(_admins); setDeleteAdminsCommunitiesDialog(false); setSelectedAdminsCommunities(null); @@ -163,6 +178,52 @@ const AdministradoresComunidad = () => { }); }; + + const cambiarStatusAdminCommuniy = () => { + if (adminCommunity.status == '1') { + adminCommunity.status = '0'; + adminCommunity.status_text = 'Inactivo'; + + } else if (adminCommunity.status == '0') { + adminCommunity.status = '1'; + adminCommunity.status_text = 'Activo'; + } + var data = { + id: adminCommunity._id, + status: adminCommunity.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) { + setChangeStatusAdminCommunityDialog(false); + toast.current.show({ + severity: 'success', + summary: 'Éxito', + detail: 'Administrador de Comunidad Actualizado', + life: 3000, + }); + } + ) + .catch( + err => console.log('Ocurrió un error con el fetch', err) + ); + } + const saveAdminCommunity = () => { if (adminCommunity.name && adminCommunity.dni && adminCommunity.last_name && adminCommunity.email && adminCommunity.phone) { @@ -228,11 +289,33 @@ const AdministradoresComunidad = () => { setDeleteAdminsCommunitiesDialog(true); }; + const hideChangeStatusAdmimCommunityDialog = () => { + setChangeStatusAdminCommunityDialog(false); + }; + const confirmChangeStatuAdminCommunity = (adminCommunity) => { + setAdminCommunity(adminCommunity); + setChangeStatusAdminCommunityDialog(true); + }; const actionsAdminCommunity = (rowData) => { + let icono = ''; + let text = ''; + if (rowData.status == '0') { + icono = "pi pi-eye"; + text = "Activar Administrador de Comunidad" + } else if (rowData.status == '1') { + icono = "pi pi-eye-slash"; + text = "Inactivar Administrador de Comunidad" + } return (
+
diff --git a/web-ui/web-react/src/components/AdministradoresSistema.js b/web-ui/web-react/src/components/AdministradoresSistema.js index 10f299f2..a301c3ed 100644 --- a/web-ui/web-react/src/components/AdministradoresSistema.js +++ b/web-ui/web-react/src/components/AdministradoresSistema.js @@ -44,7 +44,6 @@ const AdministradoresSistema = () => { status_text: '', }; - async function fetchP() { let nombres = await fetch(urlFetch, { method: 'GET' }); let adminRes = await nombres.json(); @@ -60,11 +59,11 @@ const AdministradoresSistema = () => { }) setAdministrators(await data); } + useEffect(() => { fetchP(); }, []) - function registrarAdmin() { var data = { dni: document.getElementById('identificacion').value, diff --git a/web-ui/web-react/src/components/AreasComunes.js b/web-ui/web-react/src/components/AreasComunes.js index 0850e31c..7b0b6fd8 100644 --- a/web-ui/web-react/src/components/AreasComunes.js +++ b/web-ui/web-react/src/components/AreasComunes.js @@ -43,6 +43,7 @@ const AreasComunes = () => { const dt = useRef(null); const [cookies, setCookie] = useCookies(); + const [changeStatusAreaDialog, setChangeStatusAreaDialog] = useState(false); @@ -220,6 +221,51 @@ const AreasComunes = () => { }); }; + const cambiarStatuscommonArea = () => { + if (commonArea.status == '1') { + commonArea.status = '0'; + commonArea.status_text = 'Inactivo'; + + } else if (commonArea.status == '0') { + commonArea.status = '1'; + commonArea.status_text = 'Activo'; + } + var data = { + id: commonArea._id, + status: commonArea.status, + }; + fetch('http://localhost:4000/commonArea/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) { + setChangeStatusAreaDialog(false); + toast.current.show({ + severity: 'success', + summary: 'Éxito', + detail: 'Área Común Actualizada', + life: 3000, + }); + } + ) + .catch( + err => console.log('Ocurrió un error con el fetch', err) + ); + } + const hideDeleteCommonAreaDialog = () => { setDeleteCommonAreaDialog(false); } @@ -237,9 +283,36 @@ const AreasComunes = () => { setDeleteCommonAreasDialog(true); }; + + + const hideChangeStatusAreaDialog = () => { + setChangeStatusAreaDialog(false); + }; + + const confirmChangeStatusArea = (commonArea) => { + setCommonArea(commonArea); + setChangeStatusAreaDialog(true); + }; + const actionsCommonArea = (rowData) => { + let icono = ''; + let text = ''; + if (rowData.status == '0') { + icono = "pi pi-eye"; + text = "Activar Área Común" + } else if (rowData.status == '1') { + icono = "pi pi-eye-slash"; + text = "Inactivar Área Común" + } + return (
+
+ +
+ + {commonArea && ( + + ¿Estás seguro que desea cambiar estado a {commonArea.name}? + + )} +
+
@@ -513,7 +622,7 @@ const AreasComunes = () => {
-
+
{ const tenantsBodyTemplate = (rowData) => { let tenants = rowData.tenants; - let name = findNameTenant(tenants.tenant_id); + let name = 'Sin inquilino'; + if (rowData.tenants) { + name = findNameTenant(tenants.tenant_id); + } + return ( <> {name} diff --git a/web-ui/web-react/src/components/RegistroComunicado.js b/web-ui/web-react/src/components/RegistroComunicado.js new file mode 100644 index 00000000..e2d756a9 --- /dev/null +++ b/web-ui/web-react/src/components/RegistroComunicado.js @@ -0,0 +1,165 @@ +import React, { useEffect, useState, useRef } from 'react'; +import { InputText } from 'primereact/inputtext'; +import { Button } from 'primereact/button'; +import { InputTextarea } from 'primereact/inputtextarea'; +import { useCookies } from "react-cookie"; +import { DataTable } from 'primereact/datatable'; +import { Column } from 'primereact/column'; +import { Toast } from 'primereact/toast'; +import { Dialog } from 'primereact/dialog'; +import { Toolbar } from 'primereact/toolbar'; +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import { faHome, faUserAlt } from '@fortawesome/free-solid-svg-icons'; +import { faCommentAlt } from '@fortawesome/free-solid-svg-icons'; +import { faPhoneAlt } from '@fortawesome/free-solid-svg-icons'; +import { faAt } from '@fortawesome/free-solid-svg-icons'; +import { faIdCardAlt } from '@fortawesome/free-solid-svg-icons'; +import { faEllipsis } from '@fortawesome/free-solid-svg-icons'; +import { faHomeAlt } from '@fortawesome/free-solid-svg-icons'; +import { Dropdown } from 'primereact/dropdown'; +import classNames from 'classnames'; +const RegistroComunicado = () => { + + let emptyComunicado = { + _id: null, + post: '', + user_id: '', + community_id: '' + }; + + useEffect(()=>{ + listaComunis(); + },[]) + + + const [comunicado, setComunicado] = useState(emptyComunicado); + const [comunicados,setComuicados]=useState([]); + const [comunicadoId, setComunicadoId] = useState(null); + const [submitted, setSubmitted] = useState(false); + const toast = useRef(null); + const dt = useRef(null); + const [cookies, setCookie] = useCookies(); + const [globalFilter, setGlobalFilter] = useState(null); + + async function listaComunis() { + let comunicadosA=await fetch('http://localhost:4000/post/allPosts', {method:'GET'}); + let comunicadosRes= await comunicadosA.json(); + setComuicados(comunicadosRes.message); + console.log(comunicadosRes.message); + } + + + const saveComunicado = () => { + var data = { + post: document.getElementById('txt_comunicado').value, + user_id: cookies.id, + community_id: cookies.community_id + }; + + fetch('http://localhost:4000/post/createPost', { + 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) { + + } + ) + .catch( + err => console.log('Ocurrió un error con el fetch', err) + ); + } + + const header = ( + + +
+
Comunicados de la comunidad
+ + + setGlobalFilter(e.target.value)} placeholder="Buscar..." /> + +
+
+ ); + const headerPost = ( + <> +

+ {' '} + {' '} + Descripción comunicado

+ + ) + + const leftToolbarTemplate = () => { + return ( + +
+
+
+ ) +} + +const rightToolbarTemplate = () => { + return ( + +
+
+
+
+ ); +}; + +export default React.memo(RegistroComunicado);