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 = "6301df20dac7dcf76dcecade"; const user_type=user.user_type; //const user_type="4"; //const community_id="1"; const community_id=user.community_id; const [invitado, setInvitado] = useState([]); useEffect(() => { const onRequestInvitadosData = async () => { setIsRequesting(true); try { if(user_type=="3"){ const jsonResponse = await fetch(`${API.BASE_URL}/guest/findGuestCommunity/`+`${community_id}`, { method: "GET", headers: { 'Content-Type': 'application/json' } }) const response = await jsonResponse.json(); setInvitados(response.message); }else if(user_type=="4"){ const jsonResponse = await fetch(`${API.BASE_URL}/guest/findGuestUser/`+`${id}`, { method: "GET", headers: { 'Content-Type': 'application/json' } }) const response = await jsonResponse.json(); 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} {"Tipo de acceso: "+item.type_guest} {user_type == 3 && {deleteInvitado(item._id)}} />} } keyExtractor={item => item.id} /> ); }