From 2ff3db6615445360a445c68400340a9717c31d8e Mon Sep 17 00:00:00 2001 From: Mariela Date: Sun, 28 Aug 2022 01:58:57 -0600 Subject: [PATCH 1/4] dialogos y funciones eliminar reserva --- .../web-react/src/components/Reservaciones.js | 180 ++++++++++++++++-- 1 file changed, 165 insertions(+), 15 deletions(-) diff --git a/web-ui/web-react/src/components/Reservaciones.js b/web-ui/web-react/src/components/Reservaciones.js index 8b570531..05b4aa21 100644 --- a/web-ui/web-react/src/components/Reservaciones.js +++ b/web-ui/web-react/src/components/Reservaciones.js @@ -94,7 +94,7 @@ const Reservations = () => { ) data.map((item) => { - item.date = formatDateString(item.date) + item.date = formatDateString(item.date) if (item.status == '1') { item.status_text = 'Activo'; @@ -134,7 +134,7 @@ const Reservations = () => { let _reservation = { ...reservation }; if (_reservation.date && _reservation.time && tenantId && areaId - && !validationTime() + && !validationTime() && !validationIsSameUser() && !validationIsReservation()) { _reservation.common_area_name = areas.find(item => item._id == areaId).name; let tenant = tenants.find(item => item._id == tenantId); @@ -175,7 +175,7 @@ const Reservations = () => { setAreaId('') setTenantId('') }) - + } else { setSubmitted(true); } @@ -222,7 +222,83 @@ const Reservations = () => { setReservation(emptyReservation); setReservationDialog(true); setSubmitted(false); + }; + + + const hideDeleteReservationDialog = () => { + setDeleteReservationDialog(false); + }; + + const hideDeleteReservationsDialog = () => { + setDeleteReservationsDialog(false); + }; + + + const deleteReservation = () => { + fetch('http://localhost:4000/reservation/deleteReservation' + reservation._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 _reservation = reservations.filter( + (val) => (val._id !== reservation._id || val.status != -1), + ); + + setReservations(_reservation); + setDeleteReservationDialog(false); + setReservation(emptyReservation); + toast.current.show({ + severity: 'success', + summary: 'Éxito', + detail: 'Reservación Eliminada', + life: 3000, + }); + }) + .catch((err) => { + console.log('Ocurrió un error con el fetch', err); + toast.current.show({ + severity: 'danger', + summary: 'Error', + detail: 'Reservación no se pudo Eliminar', + life: 3000, + }); + }); + }; + + const deleteSelectedReservations = () => { + let _reservations = reservations.filter( + (val) => (!selectedReservations.includes(val)), + ); + selectedReservations.map((item) => { + fetch('http://localhost:4000/reservation/deleteReservation/' + item._id, { + cache: 'no-cache', + method: 'DELETE', + headers: { + 'Content-Type': 'application/json', + }, + }); + }); + _reservations = _reservations.filter( + (val) => val.status != -1, + ) + setReservations(_reservations); + setDeleteReservationsDialog(false); + setSelectedReservations(null); + toast.current.show({ + severity: 'success', + summary: 'Éxito', + detail: 'Reservaciones Eliminadas', + life: 3000, + }); }; const leftToolbarTemplate = () => { @@ -272,6 +348,40 @@ const Reservations = () => { ); + const deleteReservationDialogFooter = ( + <> +