fix reservas create

This commit is contained in:
Maria Sanchez 2022-08-31 23:41:36 -06:00
parent e58ddbb4df
commit 90c4fc188e
3 changed files with 57 additions and 44 deletions

View File

@ -25,6 +25,9 @@ export default function AreaComun({navigation}){
const date = new Date(); const date = new Date();
const [mode, setMode] = useState('time'); const [mode, setMode] = useState('time');
const [startDate, setStartDate] = useState();
const [startTime, setStartTime] = useState()
useEffect(() => { useEffect(() => {
const onRequestReservasData = async () => { const onRequestReservasData = async () => {
@ -62,43 +65,54 @@ export default function AreaComun({navigation}){
const postReserva = async() => { const postReserva = async() => {
console.log(time); // console.log(startDate.split('"')[1]);
// console.log(startTime.split('.')[0]);
// const data = {
// "start_time": 7 + ":" +0, const data = {
// "finish_time": 10 + ":" +0,
// "status": 1,
// "date_entry": date,
// "user_id" : user._id,
// "common_area_id": service._id,
// "common_area_name": service.name,
// "community_id": service.community_id
// } "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`, { console.log(data);
// cache: 'no-cache', try {
// method: 'POST',
// body: JSON.stringify(data),
// headers: {
// 'Content-Type': 'application/json'
// }
// })
// const response = await jsonDataResponse.json(); const jsonDataResponse = await fetch(`${API.BASE_URL}/reservation/createReservation`, {
// console.log(response.message); cache: 'no-cache',
method: 'POST',
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json'
}
})
// } catch (error) { const response = await jsonDataResponse.json();
// console.log("ERROR:" + error); console.log(response.message);
// }
} catch (error) {
console.log("ERROR:" + error);
}
} }
const onChangeStart = (event, selectedDate) => { 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; const currentDate = selectedDate || time;
setTime(currentDate); setTime(currentDate);
@ -135,7 +149,7 @@ export default function AreaComun({navigation}){
<FormControl isRequired> <FormControl isRequired>
<FormControl.Label>Hora de inicio</FormControl.Label> <FormControl.Label>Hora de inicio</FormControl.Label>
<View > <View >
<DateTimePicker minimumDate={date} mode="datetime" is24Hour value={time} onChangeStart={onChangeStart}/> <DateTimePicker minimumDate={date} mode="datetime" is24Hour value={time} onChange={onChangeStart}/>
</View> </View>
</FormControl> </FormControl>

View File

@ -18,8 +18,8 @@ export default function Reservas({navigation}) {
const { user } = useContext(UserContext) const { user } = useContext(UserContext)
const [isRequesting, setIsRequesting] = useState(false); const [isRequesting, setIsRequesting] = useState(false);
const [reservas, setReservas] = useState([]); const [reservas, setReservas] = useState([]);
// const id = user._id; const id = user._id;
const id = "6301df20dac7dcf76dcecade"; // const id = "6301df20dac7dcf76dcecade";
console.log(user); console.log(user);
@ -74,8 +74,8 @@ export default function Reservas({navigation}) {
reservas.map(item => ( reservas.map(item => (
<ReservasCard <ReservasCard
key={item._id} key={item._id}
date={item.date_entry} date={item.date}
startTime={item.start_time} startTime={item.time}
status={item.status} status={item.status}
name={item.common_area_name} name={item.common_area_name}
/> />

View File

@ -11,15 +11,14 @@ import PropTypes from 'prop-types';
import React from 'react'; import React from 'react';
export const ReservasCard = ({ date, startTime, endTime, status, name}) => { export const ReservasCard = ({ date, startTime, name}) => {
const dateFormated = format(new Date(date), "dd LL yyyy")
try { const dateFormated = date.toString().split("T")[0]
} catch (error) {
}
console.log(dateFormated);
return ( return (
<ScrollView showsVerticalScrollIndicator={false}> <ScrollView showsVerticalScrollIndicator={false}>
@ -43,7 +42,7 @@ export const ReservasCard = ({ date, startTime, endTime, status, name}) => {
{name} {name}
</Heading> </Heading>
<Text fontSize="md" _light={{ <Text fontSize="md" _light={{
color: "success.600" color: "amber.600"
}} _dark={{ }} _dark={{
color: "violet.400" color: "violet.400"
}} fontWeight="500" ml="-0.5" mt="-1"> }} fontWeight="500" ml="-0.5" mt="-1">
@ -64,8 +63,8 @@ export const ReservasCard = ({ date, startTime, endTime, status, name}) => {
) )
} }
ReservasCard.propTypes = { // ReservasCard.propTypes = {
date: PropTypes.string.isRequired, // date: PropTypes.string.isRequired,
startTime: PropTypes.string.isRequired, // startTime: PropTypes.string.isRequired,
status: PropTypes.string.isRequired // status: PropTypes.string.isRequired
} // }