From c0adddd2ceef398ae867f8d3e02d4415caaa0ba0 Mon Sep 17 00:00:00 2001 From: Maria Sanchez Date: Thu, 1 Sep 2022 09:26:50 -0600 Subject: [PATCH] delete reservas --- mobile-ui/components/ReservasCard/index.js | 47 ++++++++++++++++++---- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/mobile-ui/components/ReservasCard/index.js b/mobile-ui/components/ReservasCard/index.js index d244c4ad..fdb79c58 100644 --- a/mobile-ui/components/ReservasCard/index.js +++ b/mobile-ui/components/ReservasCard/index.js @@ -8,10 +8,10 @@ import { Badge } from "native-base"; import PropTypes from 'prop-types'; - +import { MaterialCommunityIcons } from '@expo/vector-icons'; import React from 'react'; -export const ReservasCard = ({ date, startTime, name}) => { +export const ReservasCard = ({key, date, startTime, name}) => { const dateFormated = date.toString().split("T")[0] @@ -20,6 +20,38 @@ export const ReservasCard = ({ date, startTime, name}) => { console.log(dateFormated); + + const deleteReservas = async(key) => { + + const data = { + "_id": key + } + + try { + + await fetch(`http://localhost:4000/reservation/deleteReservation/`+`${key}`, { + + cache: 'no-cache', + method: 'DELETE', + body: JSON.stringify(data), + headers: { + 'Content-Type': 'application/json' + } + }) + .then(response => { + if (response.status != 201){ + console.log('ocurrio un error '); + }else{ + return response.json(); + } + }) + + } catch (error) { + console.log("ERROR: " + error); + } + + } + return ( @@ -57,14 +89,15 @@ export const ReservasCard = ({ date, startTime, name}) => { + {deleteReservas(key)}} /> ) } -// ReservasCard.propTypes = { -// date: PropTypes.string.isRequired, -// startTime: PropTypes.string.isRequired, -// status: PropTypes.string.isRequired -// } \ No newline at end of file +ReservasCard.propTypes = { + date: PropTypes.string.isRequired, + startTime: PropTypes.string.isRequired, + key: PropTypes.string.isRequired +} \ No newline at end of file