fix reservas create
This commit is contained in:
parent
e58ddbb4df
commit
90c4fc188e
|
@ -25,6 +25,9 @@ export default function AreaComun({navigation}){
|
|||
const date = new Date();
|
||||
const [mode, setMode] = useState('time');
|
||||
|
||||
const [startDate, setStartDate] = useState();
|
||||
const [startTime, setStartTime] = useState()
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
const onRequestReservasData = async () => {
|
||||
|
@ -62,43 +65,54 @@ export default function AreaComun({navigation}){
|
|||
|
||||
const postReserva = async() => {
|
||||
|
||||
console.log(time);
|
||||
// console.log(startDate.split('"')[1]);
|
||||
// console.log(startTime.split('.')[0]);
|
||||
|
||||
// const data = {
|
||||
|
||||
const data = {
|
||||
|
||||
// "start_time": 7 + ":" +0,
|
||||
// "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 {
|
||||
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 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);
|
||||
const response = await jsonDataResponse.json();
|
||||
console.log(response.message);
|
||||
|
||||
// } catch (error) {
|
||||
// console.log("ERROR:" + error);
|
||||
// }
|
||||
} 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);
|
||||
|
@ -135,7 +149,7 @@ export default function AreaComun({navigation}){
|
|||
<FormControl isRequired>
|
||||
<FormControl.Label>Hora de inicio</FormControl.Label>
|
||||
<View >
|
||||
<DateTimePicker minimumDate={date} mode="datetime" is24Hour value={time} onChangeStart={onChangeStart}/>
|
||||
<DateTimePicker minimumDate={date} mode="datetime" is24Hour value={time} onChange={onChangeStart}/>
|
||||
</View>
|
||||
</FormControl>
|
||||
|
||||
|
|
|
@ -18,8 +18,8 @@ export default function Reservas({navigation}) {
|
|||
const { user } = useContext(UserContext)
|
||||
const [isRequesting, setIsRequesting] = useState(false);
|
||||
const [reservas, setReservas] = useState([]);
|
||||
// const id = user._id;
|
||||
const id = "6301df20dac7dcf76dcecade";
|
||||
const id = user._id;
|
||||
// const id = "6301df20dac7dcf76dcecade";
|
||||
|
||||
console.log(user);
|
||||
|
||||
|
@ -74,8 +74,8 @@ export default function Reservas({navigation}) {
|
|||
reservas.map(item => (
|
||||
<ReservasCard
|
||||
key={item._id}
|
||||
date={item.date_entry}
|
||||
startTime={item.start_time}
|
||||
date={item.date}
|
||||
startTime={item.time}
|
||||
status={item.status}
|
||||
name={item.common_area_name}
|
||||
/>
|
||||
|
|
|
@ -11,15 +11,14 @@ import PropTypes from 'prop-types';
|
|||
|
||||
import React from 'react';
|
||||
|
||||
export const ReservasCard = ({ date, startTime, endTime, status, name}) => {
|
||||
const dateFormated = format(new Date(date), "dd LL yyyy")
|
||||
export const ReservasCard = ({ date, startTime, name}) => {
|
||||
|
||||
|
||||
const dateFormated = date.toString().split("T")[0]
|
||||
|
||||
|
||||
try {
|
||||
|
||||
} catch (error) {
|
||||
|
||||
}
|
||||
|
||||
console.log(dateFormated);
|
||||
|
||||
return (
|
||||
<ScrollView showsVerticalScrollIndicator={false}>
|
||||
|
@ -43,7 +42,7 @@ export const ReservasCard = ({ date, startTime, endTime, status, name}) => {
|
|||
{name}
|
||||
</Heading>
|
||||
<Text fontSize="md" _light={{
|
||||
color: "success.600"
|
||||
color: "amber.600"
|
||||
}} _dark={{
|
||||
color: "violet.400"
|
||||
}} fontWeight="500" ml="-0.5" mt="-1">
|
||||
|
@ -64,8 +63,8 @@ export const ReservasCard = ({ date, startTime, endTime, status, name}) => {
|
|||
)
|
||||
|
||||
}
|
||||
ReservasCard.propTypes = {
|
||||
date: PropTypes.string.isRequired,
|
||||
startTime: PropTypes.string.isRequired,
|
||||
status: PropTypes.string.isRequired
|
||||
}
|
||||
// ReservasCard.propTypes = {
|
||||
// date: PropTypes.string.isRequired,
|
||||
// startTime: PropTypes.string.isRequired,
|
||||
// status: PropTypes.string.isRequired
|
||||
// }
|
Loading…
Reference in New Issue