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

183 lines
5.0 KiB
JavaScript
Raw Normal View History

2022-08-23 04:20:07 +00:00
import React, {useContext, useEffect, useState} from "react";
2022-08-17 22:47:48 +00:00
import {
Box,
Heading,
VStack,
2022-08-23 04:50:38 +00:00
FormControl,
2022-08-17 22:47:48 +00:00
Button,
2022-08-23 04:20:07 +00:00
Center,
2022-08-23 04:50:38 +00:00
Select, CheckIcon, ScrollView
2022-08-17 22:47:48 +00:00
} from "native-base";
2022-08-23 04:20:07 +00:00
import { UserContext } from "../context/UserContext";
import { API } from "../environment/api";
2022-08-23 04:50:38 +00:00
import {TimePicker} from 'react-native-simple-time-picker';
import { View, StyleSheet } from "react-native";
import { number } from "prop-types";
2022-08-17 22:47:48 +00:00
export default function AreaComun({navigation}){
2022-08-23 04:20:07 +00:00
const { user } = useContext(UserContext)
const [service, setService] = useState("");
const [areas, setAreas] = useState([])
const [isRequesting, setIsRequesting] = useState(false);
2022-08-23 04:50:38 +00:00
const [selectedHours, setSelectedHours] = useState(0);
const [selectedMinutes, setSelectedMinutes] = useState(0);
const [endSelectedHours, setEndSelectedHours] = useState(0);
const [endSelectedMinutes, setEndSelectedMinutes] = useState(0);
const date = new Date();
2022-08-23 04:50:38 +00:00
2022-08-23 04:20:07 +00:00
useEffect(() => {
const onRequestReservasData = async () => {
setIsRequesting(true);
2022-08-23 06:21:25 +00:00
2022-08-23 04:20:07 +00:00
try {
const jsonResponse = await fetch(`${API.BASE_URL}/commonArea/allCommonAreas`, {
method: "GET",
headers: {
'Content-Type': 'application/json'
}
})
const response = await jsonResponse.json();
console.log(response.message);
setAreas(response.message);
} catch (error) {
console.log("ERROR:" + error);
}
setIsRequesting(false)
}
onRequestReservasData()
}, [user])
2022-08-23 06:21:25 +00:00
const postReserva = async() => {
//console.log(date);
2022-08-23 06:21:25 +00:00
const data = {
"start_time": Number.parseInt(selectedHours) + ":" +selectedMinutes,
2022-08-23 06:21:25 +00:00
"finish_time": endSelectedHours + ":" +endSelectedMinutes,
"date_entry": date,
2022-08-23 06:21:25 +00:00
"user_id" : user._id,
2022-08-23 20:18:49 +00:00
"common_area_id": service,
"common_area_name": "",
"community_id": ""
2022-08-23 06:21:25 +00:00
}
console.log(data);
// try {
// const jsonDataResponse = await fetch(`${API.BASE_URL}/reservation/createReservation`, {
// cache: 'no-cache',
// method: 'POST',
// body: JSON.stringify(data),
// headers: {
// 'Content-Type': 'application/json'
// }
// })
// const response = await jsonResponse.json();
// console.log(response.message);
// } catch (error) {
// console.log("ERROR:" + error);
// }
}
2022-08-23 04:20:07 +00:00
2022-08-17 22:47:48 +00:00
return (
<Center>
<Box safeArea p="2" w="90%" maxW="290" py="8">
<Heading size="lg" color="coolGray.800" _dark={{
color: "warmGray.50"
}} fontWeight="semibold">
Katoikia
</Heading>
<Heading mt="1" color="coolGray.600" _dark={{
color: "warmGray.200"
}} fontWeight="medium" size="xs">
Reserve su área común
</Heading>
2022-08-23 04:50:38 +00:00
<ScrollView showsVerticalScrollIndicator={false}>
2022-08-17 22:47:48 +00:00
<VStack space={3} mt="5">
2022-08-23 04:20:07 +00:00
<FormControl isRequired>
<FormControl.Label>Área común</FormControl.Label>
<Select selectedValue={service} minWidth="200" accessibilityLabel="Choose Service" placeholder="Elija su área común" _selectedItem={{
bg: "teal.600",
endIcon: <CheckIcon size="5" />
}} mt={1} onValueChange={itemValue => setService(itemValue)}>
{areas.map(item => (
2022-08-23 06:21:25 +00:00
<Select.Item label={item.name} value={item.community_id} />
2022-08-23 04:20:07 +00:00
))}
</Select>
</FormControl>
<FormControl isRequired>
2022-08-17 22:47:48 +00:00
<FormControl.Label>Hora de inicio</FormControl.Label>
2022-08-23 06:21:25 +00:00
<View >
2022-08-23 04:50:38 +00:00
<TimePicker
selectedHours={selectedHours}
selectedMinutes={selectedMinutes}
onChange={(hours, minutes) => {
setSelectedHours(hours);
setSelectedMinutes(minutes);
}}/>
</View>
2022-08-17 22:47:48 +00:00
</FormControl>
2022-08-23 04:20:07 +00:00
<FormControl isRequired>
2022-08-17 22:47:48 +00:00
<FormControl.Label>Hora de finalización</FormControl.Label>
2022-08-23 06:21:25 +00:00
<View >
2022-08-23 04:50:38 +00:00
<TimePicker
selectedHours={selectedHours}
//initial Hourse value
selectedMinutes={selectedMinutes}
//initial Minutes value
onChange={(hours, minutes) => {
setEndSelectedHours(hours);
setEndSelectedMinutes(minutes);
}}/>
</View>
2022-08-17 22:47:48 +00:00
</FormControl>
2022-08-23 04:20:07 +00:00
2022-08-17 22:47:48 +00:00
2022-08-23 06:21:25 +00:00
<Button mt="2" backgroundColor="tertiary.600" onPress={()=> postReserva()}>
2022-08-17 22:47:48 +00:00
Reservar
</Button>
<Button mt="6" colorScheme="error" onPress={() => navigation.navigate('Comunicados')}>
Cancelar
</Button>
</VStack>
2022-08-23 04:50:38 +00:00
</ScrollView>
2022-08-17 22:47:48 +00:00
</Box>
</Center>
)
2022-08-23 04:50:38 +00:00
}
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 10,
justifyContent: 'center',
alignItems: 'center',
height: 40
}
});