2022-08-23 04:44:55 +00:00
|
|
|
import React, { useContext, useEffect, useState } from "react";
|
|
|
|
import { MaterialCommunityIcons } from '@expo/vector-icons';
|
|
|
|
import { UserContext } from "../context/UserContext";
|
|
|
|
import { API } from "../environment/api";
|
2022-08-19 04:30:47 +00:00
|
|
|
import {
|
2022-08-23 04:44:55 +00:00
|
|
|
Box, Button,
|
2022-08-23 17:58:35 +00:00
|
|
|
Center, FormControl, Heading, ScrollView, VStack,FlatList, HStack,Avatar,Spacer,Text, Icon
|
2022-08-19 04:30:47 +00:00
|
|
|
} from "native-base";
|
|
|
|
|
|
|
|
export default function Invitados({navigation}) {
|
2022-08-25 04:36:13 +00:00
|
|
|
|
|
|
|
|
2022-08-23 04:44:55 +00:00
|
|
|
const [isRequesting, setIsRequesting] = useState(false);
|
|
|
|
const [invitados, setInvitados] = useState([]);
|
2022-08-23 05:27:12 +00:00
|
|
|
const { user } = useContext(UserContext);
|
2022-08-30 02:45:34 +00:00
|
|
|
const id = user._id;
|
|
|
|
//const id = "6301df20dac7dcf76dcecade";
|
2022-08-25 04:36:13 +00:00
|
|
|
const [invitado, setInvitado] = useState([]);
|
2022-08-23 04:44:55 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
2022-08-23 05:27:12 +00:00
|
|
|
const onRequestInvitadosData = async () => {
|
2022-08-23 04:44:55 +00:00
|
|
|
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();
|
2022-08-23 06:21:25 +00:00
|
|
|
//console.log(response);
|
2022-08-23 04:44:55 +00:00
|
|
|
setInvitados(response.message);
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
setIsRequesting(false)
|
|
|
|
}
|
|
|
|
|
2022-08-23 05:27:12 +00:00
|
|
|
onRequestInvitadosData()
|
2022-08-23 04:44:55 +00:00
|
|
|
|
|
|
|
})
|
|
|
|
|
2022-08-25 04:36:13 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2022-08-19 04:30:47 +00:00
|
|
|
return (
|
|
|
|
|
2022-08-23 04:44:55 +00:00
|
|
|
<Box>
|
|
|
|
<Heading fontSize="xl" p="4" pb="3">
|
|
|
|
Lista de invitados
|
|
|
|
</Heading>
|
2022-08-23 17:58:35 +00:00
|
|
|
<Button width='200' mb="4" mt="4" ml='85' backgroundColor='tertiary.600' onPress={() => navigation.navigate('invitado')} icon={<Icon mb="0.5" as={<MaterialCommunityIcons name={'plus'} />} color="white" size="sm" />}>
|
|
|
|
Agregar invitado
|
|
|
|
</Button>
|
2022-08-23 04:44:55 +00:00
|
|
|
<FlatList data={invitados} renderItem={({
|
|
|
|
item
|
2022-08-23 05:27:12 +00:00
|
|
|
}) => <Box key={item._id} borderBottomWidth="1" _dark={{
|
2022-08-23 04:44:55 +00:00
|
|
|
borderColor: "gray.600"
|
|
|
|
}} borderColor="coolGray.200" pl="4" pr="5" py="2">
|
2022-08-23 05:27:12 +00:00
|
|
|
<HStack space={3} justifyContent="space-between" >
|
|
|
|
<MaterialCommunityIcons name="account" size={48} color="#D7A86E" />
|
2022-08-23 04:44:55 +00:00
|
|
|
<VStack>
|
|
|
|
<Text _dark={{
|
|
|
|
color: "warmGray.50"
|
|
|
|
}} color="coolGray.800" bold>
|
|
|
|
{item.name+" "+item.last_name}
|
|
|
|
</Text>
|
|
|
|
<Text color="coolGray.600" _dark={{
|
|
|
|
color: "warmGray.200"
|
|
|
|
}}>
|
2022-08-25 04:36:13 +00:00
|
|
|
{"Identificación: "+item.dni}
|
|
|
|
</Text>
|
|
|
|
<Text color="coolGray.600" _dark={{
|
|
|
|
color: "warmGray.200"
|
|
|
|
}}>
|
|
|
|
{"Teléfono: "+item.phone}
|
2022-08-23 04:44:55 +00:00
|
|
|
</Text>
|
|
|
|
<Text color="coolGray.600" _dark={{
|
|
|
|
color: "warmGray.200"
|
|
|
|
}}>
|
2022-08-25 04:36:13 +00:00
|
|
|
{"Número Placa: "+item.number_plate}
|
2022-08-23 04:44:55 +00:00
|
|
|
</Text>
|
2022-08-30 02:45:34 +00:00
|
|
|
<Text color="coolGray.600" _dark={{
|
|
|
|
color: "warmGray.200"
|
|
|
|
}}>
|
|
|
|
{"Tipo de acceso: "+item.type_guest}
|
|
|
|
</Text>
|
2022-08-25 04:36:13 +00:00
|
|
|
|
2022-08-23 04:44:55 +00:00
|
|
|
</VStack>
|
|
|
|
<Spacer />
|
2022-08-25 04:36:13 +00:00
|
|
|
<MaterialCommunityIcons name="delete" size={28} color="#7C0808" onPress={() =>{deleteInvitado(item._id)}} />
|
2022-08-23 04:44:55 +00:00
|
|
|
</HStack>
|
|
|
|
</Box>} keyExtractor={item => item.id} />
|
2022-08-23 05:27:12 +00:00
|
|
|
|
|
|
|
|
2022-08-23 17:58:35 +00:00
|
|
|
|
2022-08-23 05:27:12 +00:00
|
|
|
|
2022-08-23 04:44:55 +00:00
|
|
|
</Box>
|
2022-08-23 05:27:12 +00:00
|
|
|
|
|
|
|
|
2022-08-19 04:30:47 +00:00
|
|
|
);
|
|
|
|
|
2022-08-23 05:27:12 +00:00
|
|
|
|
2022-08-19 04:30:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
}
|