import React, {useContext, useEffect, useState} from "react"; import { Box, Heading, VStack, FormControl, Button, Center, Select, CheckIcon, ScrollView } from "native-base"; import { UserContext } from "../context/UserContext"; import { API } from "../environment/api"; import {TimePicker} from 'react-native-simple-time-picker'; import { View, StyleSheet } from "react-native"; import { number } from "prop-types"; import DateTimePicker from '@react-native-community/datetimepicker'; export default function AreaComun({navigation}){ const { user } = useContext(UserContext) const [service, setService] = useState(""); const [areas, setAreas] = useState([]) const [isRequesting, setIsRequesting] = useState(false); const [time, setTime] = useState(new Date()) const idComunidad = user.community_id const date = new Date(); const [mode, setMode] = useState('time'); const [startDate, setStartDate] = useState(); const [startTime, setStartTime] = useState() useEffect(() => { const onRequestReservasData = async () => { setIsRequesting(true); try { const jsonResponse = await fetch(`${API.BASE_URL}/commonArea/findByCommunity/` + `${idComunidad}`, { 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]) const postReserva = async() => { // console.log(startDate.split('"')[1]); // console.log(startTime.split('.')[0]); const data = { "time": startTime.split('.')[0], "date": startDate.split('"')[1], "user_id" : user._id, "common_area_id": service._id, "common_area_name": service.name, "community_id": service.community_id } 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 jsonDataResponse.json(); console.log(response.message); } catch (error) { console.log("ERROR:" + error); } } const onChangeStart = (event, selectedDate) => { // console.log(selectedDate); const dateString = JSON.stringify(selectedDate).toString().split("T") setStartDate(dateString[0]) setStartTime(dateString[1]) console.log(dateString); // console.log(Date.toString(selectedDate)); const currentDate = selectedDate || time; setTime(currentDate); }; return (
Katoikia Reserve su área común Área común Hora de inicio
) } const styles = StyleSheet.create({ container: { flex: 1, padding: 10, justifyContent: 'center', alignItems: 'center', height: 40 } });