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

82 lines
1.9 KiB
JavaScript
Raw Permalink 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,
Fab,
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-08-23 02:53:58 +00:00
useEffect(() => {
const onRequestReservasData = async () => {
setIsRequesting(true);
try {
const jsonResponse = await fetch(`${API.BASE_URL}/reservation/allReservations`, {
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-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}>
<Button width='200' mb="4" mt="4" ml='85' backgroundColor='tertiary.600' onPress={() => navigation.navigate('area')} icon={<Icon mb="0.5" as={<MaterialCommunityIcons name={'plus'} />} color="white" size="sm" />}>
Reservar
</Button>
2022-08-17 16:36:33 +00:00
2022-08-23 02:53:58 +00:00
{
reservas.map(item => (
<ReservasCard
key={item._id}
date={item.date_entry}
startTime={item.start_time}
endTime={item.finish_time}
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
}