From 2b80e2dc81fde4fbd72b0d3f1c425fa860a53aef Mon Sep 17 00:00:00 2001 From: aelassas Date: Fri, 22 Sep 2023 11:27:04 +0100 Subject: [PATCH] Fix date issues --- backend/src/components/BookingFilter.tsx | 24 ++++-- backend/src/components/DatePicker.tsx | 25 ++++-- backend/src/components/DateTimePicker.tsx | 19 +++-- backend/src/pages/CreateBooking.tsx | 36 +++++---- backend/src/pages/CreateUser.tsx | 10 ++- backend/src/pages/UpdateBooking.tsx | 35 +++++---- backend/src/pages/UpdateUser.tsx | 10 ++- frontend/src/components/BookingFilter.tsx | 24 ++++-- frontend/src/components/CarFilter.tsx | 33 +++++--- frontend/src/components/DatePicker.tsx | 22 ++++-- frontend/src/components/DateTimePicker.tsx | 16 ++-- frontend/src/pages/Checkout.tsx | 16 ++-- frontend/src/pages/Home.tsx | 32 ++++++-- frontend/src/pages/Settings.tsx | 8 +- frontend/src/pages/SignUp.tsx | 8 +- .../AutocompleteDropdown/RightButton.tsx | 2 +- mobile/components/BookingFilter.tsx | 30 +++++++- mobile/components/DateTimePicker.tsx | 34 ++++++++- mobile/lang/en.ts | 6 +- mobile/lang/fr.ts | 4 + mobile/screens/HomeScreen.tsx | 76 ++++++++++++------- 21 files changed, 336 insertions(+), 134 deletions(-) diff --git a/backend/src/components/BookingFilter.tsx b/backend/src/components/BookingFilter.tsx index 37ab45325..fddeeaec3 100644 --- a/backend/src/components/BookingFilter.tsx +++ b/backend/src/components/BookingFilter.tsx @@ -67,23 +67,37 @@ const BookingFilter = ({ { - setFrom(from) - setMinDate(from) + onChange={(date) => { + if (date) { + + if (to && to.getTime() <= date.getTime()) { + setTo(undefined) + } + + const minDate = new Date(date) + minDate.setDate(date.getDate() + 1) + setMinDate(minDate) + + setFrom(date) + } else { + setMinDate(undefined) + } }} language={language} variant="standard" + value={from} /> { - setTo(to) + onChange={(date) => { + setTo(date || undefined) }} language={language} variant="standard" + value={to} /> diff --git a/backend/src/components/DatePicker.tsx b/backend/src/components/DatePicker.tsx index a79981cb4..096afc237 100644 --- a/backend/src/components/DatePicker.tsx +++ b/backend/src/components/DatePicker.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react' +import React, { useEffect, useState } from 'react' import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns' import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider' import { DatePicker as MuiDatePicker } from '@mui/x-date-pickers/DatePicker' @@ -13,6 +13,7 @@ const DatePicker = ( required, language, variant, + readOnly, onChange } : { @@ -22,10 +23,15 @@ const DatePicker = ( required?: boolean language?: string variant?: TextFieldVariants - onChange: (value: Date) => void + readOnly?: boolean + onChange?: (value: Date | null) => void } ) => { - const [value, setValue] = useState(dateValue || null) + const [value, setValue] = useState(null) + + useEffect(() => { + setValue(dateValue || null) + }, [dateValue]) return ( @@ -33,11 +39,16 @@ const DatePicker = ( label={label} views={['year', 'month', 'day']} value={value} - onChange={(value) => { - const date = value as Date - setValue(date) + readOnly={readOnly} + onAccept={(value) => { + if (value) { + const date = value as Date + date.setHours(10, 0, 0, 0) + } + setValue(value) + if (onChange) { - onChange(date) + onChange(value) } }} minDate={minDate} diff --git a/backend/src/components/DateTimePicker.tsx b/backend/src/components/DateTimePicker.tsx index 3c6b8fead..7f279aadf 100644 --- a/backend/src/components/DateTimePicker.tsx +++ b/backend/src/components/DateTimePicker.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react' +import React, { useEffect, useState } from 'react' import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns' import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider' import { DateTimePicker as MuiDateTimePicker } from '@mui/x-date-pickers/DateTimePicker' @@ -13,6 +13,7 @@ const DateTimePicker = ( required, variant, language, + readOnly, onChange } : { @@ -22,22 +23,28 @@ const DateTimePicker = ( required?: boolean language?: string variant?: TextFieldVariants - onChange: (value: Date) => void + readOnly?: boolean + onChange: (value: Date | null) => void } ) => { const [value, setValue] = useState(dateTimeValue || null) + useEffect(() => { + setValue(dateTimeValue || null) + }, [dateTimeValue]) + return ( { - const date = value as Date - setValue(date) + readOnly={readOnly} + onAccept={(value) => { + setValue(value) + if (onChange) { - onChange(date) + onChange(value) } }} minDate={minDate} diff --git a/backend/src/pages/CreateBooking.tsx b/backend/src/pages/CreateBooking.tsx index 4385d4097..8bff20248 100644 --- a/backend/src/pages/CreateBooking.tsx +++ b/backend/src/pages/CreateBooking.tsx @@ -56,7 +56,7 @@ const CreateBooking = () => { const [collisionDamageWaiver, setCollisionDamageWaiver] = useState(false) const [fullInsurance, setFullInsurance] = useState(false) const [additionalDriver, setAdditionalDriver] = useState(false) - const [minDate, setMinDate] = useState(new Date()) + const [minDate, setMinDate] = useState() const [_fullName, set_FullName] = useState('') const [_email, set_Email] = useState('') const [_phone, set_Phone] = useState('') @@ -308,14 +308,22 @@ const CreateBooking = () => { { - setFrom(from) + onChange={(date) => { + if (date) { - const minDate = new Date(from) - minDate.setDate(minDate.getDate() + 1) - setMinDate(minDate) + if (to && to.getTime() <= date.getTime()) { + setTo(undefined) + } + + const minDate = new Date(date) + minDate.setDate(minDate.getDate() + 1) + setMinDate(minDate) + + setFrom(date) + } else { + setMinDate(undefined) + } }} language={UserService.getLanguage()} /> @@ -327,8 +335,8 @@ const CreateBooking = () => { value={to} minDate={minDate} required - onChange={(to: Date) => { - setTo(to) + onChange={(date) => { + setTo(date||undefined) }} language={UserService.getLanguage()} /> @@ -463,11 +471,13 @@ const CreateBooking = () => { { - const _birthDateValid = _validateBirthDate(_birthDate) + onChange={(_birthDate) => { + if (_birthDate) { + const _birthDateValid = _validateBirthDate(_birthDate) - set_BirthDate(_birthDate) - set_BirthDateValid(_birthDateValid) + set_BirthDate(_birthDate) + set_BirthDateValid(_birthDateValid) + } }} language={UserService.getLanguage()} /> diff --git a/backend/src/pages/CreateUser.tsx b/backend/src/pages/CreateUser.tsx index a97b18308..cebb258f6 100644 --- a/backend/src/pages/CreateUser.tsx +++ b/backend/src/pages/CreateUser.tsx @@ -356,11 +356,13 @@ const CreateUser = () => { label={strings.BIRTH_DATE} value={birthDate} required - onChange={(birthDate: Date) => { - const birthDateValid = validateBirthDate(birthDate) + onChange={(birthDate) => { + if (birthDate) { + const birthDateValid = validateBirthDate(birthDate) - setBirthDate(birthDate) - setBirthDateValid(birthDateValid) + setBirthDate(birthDate) + setBirthDateValid(birthDateValid) + } }} language={(user && user.language) || Env.DEFAULT_LANGUAGE} /> diff --git a/backend/src/pages/UpdateBooking.tsx b/backend/src/pages/UpdateBooking.tsx index 7fabd4428..61bcc3055 100644 --- a/backend/src/pages/UpdateBooking.tsx +++ b/backend/src/pages/UpdateBooking.tsx @@ -562,9 +562,9 @@ const UpdateBooking = () => { label={commonStrings.FROM} value={from} required - onChange={(from: Date) => { - if (from) { - booking.from = from + onChange={(date) => { + if (date) { + booking.from = date Helper.price( booking, @@ -572,8 +572,15 @@ const UpdateBooking = () => { (price) => { setBooking(booking) setPrice(price) - setFrom(from) - setMinDate(from) + setFrom(date) + + const minDate = new Date(date) + minDate.setDate(minDate.getDate() + 1) + setMinDate(minDate) + + if (to && to.getTime() <= date.getTime()) { + setTo(undefined) + } }, (err) => { toastErr(err) @@ -590,9 +597,9 @@ const UpdateBooking = () => { value={to} minDate={minDate} required - onChange={(to: Date) => { - if (to) { - booking.to = to + onChange={(date) => { + if (date) { + booking.to = date Helper.price( booking, @@ -600,7 +607,7 @@ const UpdateBooking = () => { (price) => { setBooking(booking) setPrice(price) - setTo(to) + setTo(date) }, (err) => { toastErr(err) @@ -740,10 +747,12 @@ const UpdateBooking = () => { label={commonStrings.BIRTH_DATE} value={_birthDate} required - onChange={(_birthDate: Date) => { - const _birthDateValid = _validateBirthDate(_birthDate) - set_BirthDate(_birthDate) - set_BirthDateValid(_birthDateValid) + onChange={(_birthDate) => { + if (_birthDate) { + const _birthDateValid = _validateBirthDate(_birthDate) + set_BirthDate(_birthDate) + set_BirthDateValid(_birthDateValid) + } }} language={UserService.getLanguage()} /> diff --git a/backend/src/pages/UpdateUser.tsx b/backend/src/pages/UpdateUser.tsx index 3c7dd34bb..6f71242e7 100644 --- a/backend/src/pages/UpdateUser.tsx +++ b/backend/src/pages/UpdateUser.tsx @@ -375,11 +375,13 @@ const UpdateUser = () => { label={cuStrings.BIRTH_DATE} value={birthDate} required - onChange={(birthDate: Date) => { - const birthDateValid = validateBirthDate(birthDate) + onChange={(birthDate) => { + if (birthDate) { + const birthDateValid = validateBirthDate(birthDate) - setBirthDate(birthDate) - setBirthDateValid(birthDateValid) + setBirthDate(birthDate) + setBirthDateValid(birthDateValid) + } }} language={(user && user.language) || Env.DEFAULT_LANGUAGE} /> diff --git a/frontend/src/components/BookingFilter.tsx b/frontend/src/components/BookingFilter.tsx index 24c9011c5..9e79ed35b 100644 --- a/frontend/src/components/BookingFilter.tsx +++ b/frontend/src/components/BookingFilter.tsx @@ -67,23 +67,37 @@ const BookingFilter = ({ { - setFrom(from) - setMinDate(from) + onChange={(date) => { + if (date) { + + if (to && to.getTime() <= date.getTime()) { + setTo(undefined) + } + + const minDate = new Date(date) + minDate.setDate(date.getDate() + 1) + setMinDate(minDate) + + setFrom(date) + } else { + setMinDate(undefined) + } }} language={language} variant="standard" + value={from} /> { - setTo(to) + onChange={(date) => { + setTo(date || undefined) }} language={language} variant="standard" + value={to} /> diff --git a/frontend/src/components/CarFilter.tsx b/frontend/src/components/CarFilter.tsx index 7420f71c4..8f69ace1d 100644 --- a/frontend/src/components/CarFilter.tsx +++ b/frontend/src/components/CarFilter.tsx @@ -25,8 +25,12 @@ const CarFilter = ( className?: string onSubmit: bookcarsTypes.CarFilterSubmitEvent }) => { - const [from, setFrom] = useState(filterFrom) - const [to, setTo] = useState(filterTo) + + const _minDate = new Date() + _minDate.setDate(_minDate.getDate() + 1) + + const [from, setFrom] = useState(filterFrom) + const [to, setTo] = useState(filterTo) const [minDate, setMinDate] = useState() const [pickupLocation, setPickupLocation] = useState(filterPickupLocation) const [dropOffLocation, setDropOffLocation] = useState(filterDropOffLocation) @@ -77,7 +81,7 @@ const CarFilter = ( const handleSubmit = (e: React.FormEvent) => { e.preventDefault() - if (!pickupLocation || !dropOffLocation) { + if (!pickupLocation || !dropOffLocation || !from || !to) { return } @@ -121,12 +125,21 @@ const CarFilter = ( minDate={new Date()} variant="standard" required - onChange={(from) => { - const minDate = new Date(from) - minDate.setDate(from.getDate() + 1) + onChange={(date) => { + if (date) { + + if (to && to.getTime() <= date.getTime()) { + setTo(undefined) + } + + const minDate = new Date(date) + minDate.setDate(date.getDate() + 1) + setMinDate(minDate) - setFrom(from) - setMinDate(minDate) + setFrom(date) + } else { + setMinDate(_minDate) + } }} language={UserService.getLanguage()} /> @@ -138,8 +151,8 @@ const CarFilter = ( minDate={minDate} variant="standard" required - onChange={(to) => { - setTo(to) + onChange={(date) => { + setTo(date || undefined) }} language={UserService.getLanguage()} /> diff --git a/frontend/src/components/DatePicker.tsx b/frontend/src/components/DatePicker.tsx index be7158348..096afc237 100644 --- a/frontend/src/components/DatePicker.tsx +++ b/frontend/src/components/DatePicker.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react' +import React, { useEffect, useState } from 'react' import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns' import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider' import { DatePicker as MuiDatePicker } from '@mui/x-date-pickers/DatePicker' @@ -24,10 +24,14 @@ const DatePicker = ( language?: string variant?: TextFieldVariants readOnly?: boolean - onChange: (value: Date) => void + onChange?: (value: Date | null) => void } ) => { - const [value, setValue] = useState(dateValue || null) + const [value, setValue] = useState(null) + + useEffect(() => { + setValue(dateValue || null) + }, [dateValue]) return ( @@ -36,11 +40,15 @@ const DatePicker = ( views={['year', 'month', 'day']} value={value} readOnly={readOnly} - onChange={(value) => { - const date = value as Date - setValue(date) + onAccept={(value) => { + if (value) { + const date = value as Date + date.setHours(10, 0, 0, 0) + } + setValue(value) + if (onChange) { - onChange(date) + onChange(value) } }} minDate={minDate} diff --git a/frontend/src/components/DateTimePicker.tsx b/frontend/src/components/DateTimePicker.tsx index ca63b3dcf..7f279aadf 100644 --- a/frontend/src/components/DateTimePicker.tsx +++ b/frontend/src/components/DateTimePicker.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react' +import React, { useEffect, useState } from 'react' import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns' import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider' import { DateTimePicker as MuiDateTimePicker } from '@mui/x-date-pickers/DateTimePicker' @@ -24,11 +24,15 @@ const DateTimePicker = ( language?: string variant?: TextFieldVariants readOnly?: boolean - onChange: (value: Date) => void + onChange: (value: Date | null) => void } ) => { const [value, setValue] = useState(dateTimeValue || null) + useEffect(() => { + setValue(dateTimeValue || null) + }, [dateTimeValue]) + return ( { - const date = value as Date - setValue(date) + onAccept={(value) => { + setValue(value) + if (onChange) { - onChange(date) + onChange(value) } }} minDate={minDate} diff --git a/frontend/src/pages/Checkout.tsx b/frontend/src/pages/Checkout.tsx index 55f345cb5..99724d8ff 100644 --- a/frontend/src/pages/Checkout.tsx +++ b/frontend/src/pages/Checkout.tsx @@ -929,10 +929,12 @@ const Checkout = () => { variant="outlined" required onChange={(birthDate) => { - const birthDateValid = validateBirthDate(birthDate) + if (birthDate) { + const birthDateValid = validateBirthDate(birthDate) - setBirthDate(birthDate) - setBirthDateValid(birthDateValid) + setBirthDate(birthDate) + setBirthDateValid(birthDateValid) + } }} language={language} /> @@ -1024,10 +1026,12 @@ const Checkout = () => { variant="outlined" required={adRequired} onChange={(_birthDate) => { - const _birthDateValid = _validateBirthDate(_birthDate) + if (_birthDate) { + const _birthDateValid = _validateBirthDate(_birthDate) - set_BirthDate(_birthDate) - set_BirthDateValid(_birthDateValid) + set_BirthDate(_birthDate) + set_BirthDateValid(_birthDateValid) + } }} language={language} /> diff --git a/frontend/src/pages/Home.tsx b/frontend/src/pages/Home.tsx index 863cfa490..c68909008 100644 --- a/frontend/src/pages/Home.tsx +++ b/frontend/src/pages/Home.tsx @@ -14,9 +14,13 @@ import '../assets/css/home.css' const Home = () => { const navigate = useNavigate() + + const _minDate = new Date() + _minDate.setDate(_minDate.getDate() + 1) + const [pickupLocation, setPickupLocation] = useState('') const [dropOffLocation, setDropOffLocation] = useState('') - const [minDate, setMinDate] = useState() + const [minDate, setMinDate] = useState(_minDate) const [from, setFrom] = useState() const [to, setTo] = useState() const [sameLocation, setSameLocation] = useState(true) @@ -32,7 +36,10 @@ const Home = () => { const to = new Date(from) to.setDate(to.getDate() + 3) - setMinDate(new Date()) + const minDate = new Date(from) + minDate.setDate(minDate.getDate() + 1) + + setMinDate(minDate) setFrom(from) setTo(to) }, []) @@ -114,8 +121,21 @@ const Home = () => { minDate={new Date()} variant="outlined" required - onChange={(from) => { - setFrom(from) + onChange={(date) => { + if (date) { + + if (to && to.getTime() <= date.getTime()) { + setTo(undefined) + } + + const minDate = new Date(date) + minDate.setDate(date.getDate() + 1) + setMinDate(minDate) + + setFrom(date) + } else { + setMinDate(_minDate) + } }} language={UserService.getLanguage()} /> @@ -127,8 +147,8 @@ const Home = () => { minDate={minDate} variant="outlined" required - onChange={(to) => { - setTo(to) + onChange={(date) => { + setTo(date || undefined) }} language={UserService.getLanguage()} /> diff --git a/frontend/src/pages/Settings.tsx b/frontend/src/pages/Settings.tsx index 2090c4408..2525ce25b 100644 --- a/frontend/src/pages/Settings.tsx +++ b/frontend/src/pages/Settings.tsx @@ -209,10 +209,12 @@ const Settings = () => { variant="standard" required onChange={(birthDate) => { - const birthDateValid = validateBirthDate(birthDate) + if (birthDate) { + const birthDateValid = validateBirthDate(birthDate) - setBirthDate(birthDate) - setBirthDateValid(birthDateValid) + setBirthDate(birthDate) + setBirthDateValid(birthDateValid) + } }} language={user.language} /> diff --git a/frontend/src/pages/SignUp.tsx b/frontend/src/pages/SignUp.tsx index db04e5fbb..17b175ada 100644 --- a/frontend/src/pages/SignUp.tsx +++ b/frontend/src/pages/SignUp.tsx @@ -320,10 +320,12 @@ const SignUp = () => { variant="outlined" required onChange={(birthDate) => { - const birthDateValid = validateBirthDate(birthDate) + if (birthDate) { + const birthDateValid = validateBirthDate(birthDate) - setBirthDate(birthDate) - setBirthDateValid(birthDateValid) + setBirthDate(birthDate) + setBirthDateValid(birthDateValid) + } }} language={language} /> diff --git a/mobile/components/AutocompleteDropdown/RightButton.tsx b/mobile/components/AutocompleteDropdown/RightButton.tsx index e0948bf08..fed6e76f9 100644 --- a/mobile/components/AutocompleteDropdown/RightButton.tsx +++ b/mobile/components/AutocompleteDropdown/RightButton.tsx @@ -55,7 +55,7 @@ const RightButtonComponent = ( > {!loading && showClear && ( - {ClearIconComponent ?? } + {ClearIconComponent ?? } )} {loading && } diff --git a/mobile/components/BookingFilter.tsx b/mobile/components/BookingFilter.tsx index 481d6709a..f19eabbe6 100644 --- a/mobile/components/BookingFilter.tsx +++ b/mobile/components/BookingFilter.tsx @@ -1,6 +1,6 @@ import React, { useEffect, useRef, useState } from 'react' import { StyleSheet, View, TextInput as ReactTextInput } from 'react-native' -import * as bookcarsTypes from '../miscellaneous/bookcarsTypes' +import * as bookcarsTypes from '../miscellaneous/bookcarsTypes' import i18n from '../lang/i18n' import Accordion from './Accordion' @@ -31,6 +31,8 @@ const BookingFilter = ( const [pickupLocation, setPickupLocation] = useState() const [dropOffLocation, setDropOffLocation] = useState() const [keyword, setKeyword] = useState('') + const [minDate, setMinDate] = useState() + const searchRef = useRef(null) const _init = async () => { @@ -89,7 +91,22 @@ const BookingFilter = ( size="small" label={i18n.t('FROM')} value={from} - onChange={(date) => setFrom(date)} + onChange={(date) => { + if (date) { + date.setHours(12, 0, 0, 0) + + if (to && to.getTime() <= date.getTime()) { + setTo(undefined) + } + + const minDate = new Date(date) + minDate.setDate(date.getDate() + 1) + setMinDate(minDate) + } else { + setMinDate(undefined) + } + setFrom(date) + }} onPress={blurLocations} /> @@ -101,8 +118,13 @@ const BookingFilter = ( size="small" label={i18n.t('TO')} value={to} - minimumDate={from} - onChange={(date) => setTo(date)} + minDate={minDate} + onChange={(date) => { + if (date) { + date.setHours(12, 0, 0, 0) + } + setTo(date) + }} onPress={blurLocations} /> diff --git a/mobile/components/DateTimePicker.tsx b/mobile/components/DateTimePicker.tsx index d4920a214..8d6b305df 100644 --- a/mobile/components/DateTimePicker.tsx +++ b/mobile/components/DateTimePicker.tsx @@ -4,6 +4,7 @@ import ReactDateTimePicker from '@react-native-community/datetimepicker' import { format } from 'date-fns' import { enUS, fr } from 'date-fns/locale' import * as bookcarsHelper from '../miscellaneous/bookcarsHelper' +import { MaterialIcons } from '@expo/vector-icons' import * as Env from '../config/env.config' @@ -18,7 +19,9 @@ const DateTimePicker = ( error, style, helperText, - minimumDate, + minDate, + readOnly, + hideClearButton, onPress, onChange }: { @@ -31,9 +34,11 @@ const DateTimePicker = ( error?: boolean style?: object helperText?: string - minimumDate?: Date + minDate?: Date + readOnly?: boolean + hideClearButton?: boolean onPress?: () => void - onChange?: (date: Date) => void + onChange?: (date: Date | undefined) => void } ) => { const [label, setLabel] = useState('') @@ -99,6 +104,12 @@ const DateTimePicker = ( fontWeight: '400', paddingLeft: 5, }, + clear: { + flex: 0, + position: 'absolute', + right: 10, + top: small ? 7 : 17, + }, }) return ( @@ -122,13 +133,28 @@ const DateTimePicker = ( > {label} + {!readOnly && value !== undefined && !hideClearButton && ( + { + setLabel(dateTimeLabel) + setValue(undefined) + if (onChange) { + onChange(undefined) + } + }} + /> + )} {helperText && {helperText}} {show && ( { setShow(false) if (event.type === 'set' && date) { diff --git a/mobile/lang/en.ts b/mobile/lang/en.ts index 91d2de1af..599450f1f 100644 --- a/mobile/lang/en.ts +++ b/mobile/lang/en.ts @@ -83,7 +83,7 @@ export const en = { FROM_TIME: 'Pickup time', TO_DATE: 'Drop-off date', TO_TIME: 'Drop-off time', - PICKUP_LOCATION_EMPTY: 'Please enter a pick up location.', + PICKUP_LOCATION_EMPTY: 'Please enter a pickup location.', DROP_OFF_LOCATION_EMPTY: 'Please enter a drop-off location.', HOME: 'Home', ABOUT: 'About', @@ -196,4 +196,8 @@ export const en = { PAY_ONLINE: 'Pay online', PAY_ONLINE_INFO: 'Amendments and cancellation under conditions', PAY_LATER_SUCCESS: 'Your booking were successfully done. We have sent you a confirmation email.', + FROM_DATE_EMPTY: 'Please enter the pickup date', + FROM_TIME_EMPTY: 'Please enter the pickup time', + TO_DATE_EMPTY: 'Please enter the drop-off date', + TO_TIME_EMPTY: 'Please enter the drop-off time', } diff --git a/mobile/lang/fr.ts b/mobile/lang/fr.ts index 9fafbed6f..1cdf36766 100644 --- a/mobile/lang/fr.ts +++ b/mobile/lang/fr.ts @@ -196,6 +196,10 @@ export const fr = { PAY_ONLINE: 'Payer en ligne', PAY_ONLINE_INFO: 'Modification et annulation sous conditions', PAY_LATER_SUCCESS: 'Votre réservation a été effectué avec succès. Nous vous avons envoyé un e-mail de confirmation.', + FROM_DATE_EMPTY: 'Veuillez saisir la date de prise en charge', + FROM_TIME_EMPTY: "Veuillez saisir l'heure de prise en charge", + TO_DATE_EMPTY: 'Veuillez saisir la date de restitution', + TO_TIME_EMPTY: "Veuillez saisir l'heure de restitution", } export default fr diff --git a/mobile/screens/HomeScreen.tsx b/mobile/screens/HomeScreen.tsx index acc477d4e..dae7d0e5d 100644 --- a/mobile/screens/HomeScreen.tsx +++ b/mobile/screens/HomeScreen.tsx @@ -34,8 +34,8 @@ const HomeScreen = ({ navigation, route }: NativeStackScreenProps(_fromDate) + const [fromTime, setFromTime] = useState(_fromTime) + const [toTime, setToTime] = useState(_toTime) + const [toDate, setToDate] = useState(_toDate) + const [minDate, setMinDate] = useState(_minDate) const [language, setLanguage] = useState(Env.DEFAULT_LANGUAGE) const [blur, setBlur] = useState(false) const [reload, setReload] = useState(false) @@ -121,11 +121,6 @@ const HomeScreen = ({ navigation, route }: NativeStackScreenProps { blurLocations() - const from = Helper.dateTime(fromDate, fromTime) - const to = Helper.dateTime(toDate, toTime) - console.log('from', from) - console.log('to', to) - if (!pickupLocation) { return Helper.toast(i18n.t('PICKUP_LOCATION_EMPTY')) } @@ -134,6 +129,25 @@ const HomeScreen = ({ navigation, route }: NativeStackScreenProps { - const minimumDate = new Date(date) - minimumDate.setDate(date.getDate() + 1) - setMinimumDate(minimumDate) - - if (toDate && toDate.getTime() < date.getTime()) { - const _toDate = new Date(date) - _toDate.setDate(date.getDate() + dateOffset) - setToDate(_toDate) + minDate={_fromDate} + onChange={(date) => { + if (date) { + + if (toDate && toDate.getTime() <= date.getTime()) { + setToDate(undefined) + } + + const minDate = new Date(date) + minDate.setDate(date.getDate() + 1) + setMinDate(minDate) + } else { + setMinDate(_minDate) } + setFromDate(date) }} onPress={blurLocations} @@ -210,7 +228,9 @@ const HomeScreen = ({ navigation, route }: NativeStackScreenProps setFromTime(time)} + onChange={(time) => { + setFromTime(time) + }} onPress={blurLocations} /> @@ -220,8 +240,10 @@ const HomeScreen = ({ navigation, route }: NativeStackScreenProps setToDate(date)} + minDate={minDate} + onChange={(date) => { + setToDate(date) + }} onPress={blurLocations} /> @@ -231,7 +253,9 @@ const HomeScreen = ({ navigation, route }: NativeStackScreenProps setToTime(time)} + onChange={(time) => { + setToTime(time) + }} onPress={blurLocations} />