katoikia-app/mobile-ui/components/Reservas.js

89 lines
2.1 KiB
JavaScript
Raw Normal View History

2022-08-23 02:53:58 +00:00
import React, {useContext, useEffect, useState} from "react";
2022-08-17 16:36:33 +00:00
import {
Box,
ScrollView,
2022-09-01 04:58:53 +00:00
Text,
Icon,
Button,
Heading
2022-08-17 16:36:33 +00:00
} from "native-base";
2022-08-23 02:53:58 +00:00
import { API } from "../environment/api";
2022-08-17 16:36:33 +00:00
import { MaterialCommunityIcons } from '@expo/vector-icons';
2022-08-23 02:53:58 +00:00
import { UserContext } from "../context/UserContext";
import { ReservasCard } from "./ReservasCard";
2022-08-17 16:36:33 +00:00
export default function Reservas({navigation}) {
2022-08-23 02:53:58 +00:00
const { user } = useContext(UserContext)
const [isRequesting, setIsRequesting] = useState(false);
const [reservas, setReservas] = useState([]);
2022-09-01 05:41:36 +00:00
const id = user._id;
// const id = "6301df20dac7dcf76dcecade";
2022-09-01 04:58:53 +00:00
console.log(user);
2022-08-23 02:53:58 +00:00
useEffect(() => {
const onRequestReservasData = async () => {
setIsRequesting(true);
2022-09-01 04:58:53 +00:00
console.log(user);
2022-08-23 02:53:58 +00:00
try {
2022-09-01 04:11:13 +00:00
const jsonResponse = await fetch(`${API.BASE_URL}/reservation/findReservationUser/`+`${id}`, {
2022-08-23 02:53:58 +00:00
method: "GET",
headers: {
'Content-Type': 'application/json'
}
})
const response = await jsonResponse.json();
console.log(response);
setReservas(response.message);
} catch (error) {
console.log("ERROR:" + error);
}
setIsRequesting(false)
}
onRequestReservasData()
}, [user])
2022-09-01 04:58:53 +00:00
console.log(reservas);
2022-08-23 02:53:58 +00:00
2022-08-17 16:36:33 +00:00
return (
<Box>
<Heading fontSize="xl" p="4" pb="3">
Lista de reservas
</Heading>
2022-08-17 16:36:33 +00:00
<ScrollView showsVerticalScrollIndicator={false}>
2022-09-01 04:58:53 +00:00
<Button width='200' mb="4" mt="4" ml='85' backgroundColor='tertiary.600' onPress={() => navigation.navigate('Reservar')} icon={<Icon mb="0.5" as={<MaterialCommunityIcons name={'plus'} />} color="white" size="sm" />}>
Reservar
</Button>
2022-08-17 16:36:33 +00:00
2022-09-01 04:58:53 +00:00
{ reservas == [] ? <Text mt="9" ml='10'> No hay reservas relacionados a su usuario</Text> :
2022-08-23 02:53:58 +00:00
reservas.map(item => (
<ReservasCard
key={item._id}
2022-09-01 05:41:36 +00:00
date={item.date}
startTime={item.time}
2022-08-23 02:53:58 +00:00
status={item.status}
2022-08-24 17:15:27 +00:00
name={item.common_area_name}
2022-08-23 02:53:58 +00:00
/>
))
}
2022-08-17 16:36:33 +00:00
</ScrollView>
</Box>
);
2022-08-17 16:36:33 +00:00
}