import React, { useContext, useEffect, useState } from "react"; import { MaterialCommunityIcons } from '@expo/vector-icons'; import { UserContext } from "../context/UserContext"; import { API } from "../environment/api"; import { Box, Button, Center, FormControl, Heading, ScrollView, VStack,FlatList, HStack,Avatar,Spacer,Text, Icon } from "native-base"; export default function Invitados({navigation}) { const [isRequesting, setIsRequesting] = useState(false); const [invitados, setInvitados] = useState([]); const { user } = useContext(UserContext); //const id = user._id; const id = "62ff074949eb1e993a9d0fda"; const [invitado, setInvitado] = useState([]); useEffect(() => { const onRequestInvitadosData = async () => { setIsRequesting(true); try { const jsonResponse = await fetch(`${API.BASE_URL}/guest/findGuestUser/`+`${id}`, { method: "GET", headers: { 'Content-Type': 'application/json' } }) const response = await jsonResponse.json(); //console.log(response); setInvitados(response.message); } catch (error) { } setIsRequesting(false) } onRequestInvitadosData() }) const deleteInvitado = async(pid) => { const data = { "_id": pid } try { await fetch("http://localhost:4000/guest/updateGuest", { cache: 'no-cache', method: 'POST', 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 ( Lista de invitados {item.name+" "+item.last_name} {"Identificación: "+item.dni} {"Teléfono: "+item.phone} {"Número Placa: "+item.number_plate} {deleteInvitado(item._id)}} /> } keyExtractor={item => item.id} /> ); }