Skip to content

Commit 1583a70

Browse files
committed
Fix: rental dates not working properly in frontend and mobile app
1 parent 3caec3f commit 1583a70

File tree

4 files changed

+11
-29
lines changed

4 files changed

+11
-29
lines changed

frontend/src/components/DatePicker.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const DatePicker = ({
4141
useEffect(() => {
4242
if (minDateValue) {
4343
const _minDate = new Date(minDateValue)
44-
_minDate.setHours(10, 0, 0, 0)
44+
_minDate.setHours(12, 0, 0, 0)
4545
setMinDate(_minDate)
4646
} else {
4747
setMinDate(undefined)
@@ -58,7 +58,7 @@ const DatePicker = ({
5858
onChange={(_value) => {
5959
if (_value) {
6060
const date = _value as Date
61-
date.setHours(10, 0, 0, 0)
61+
date.setHours(12, 0, 0, 0)
6262
}
6363
setValue(_value)
6464

frontend/src/components/PropertyFilter.tsx

+4-14
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ const PropertyFilter = ({
3434
const [from, setFrom] = useState<Date | undefined>(filterFrom)
3535
const [to, setTo] = useState<Date | undefined>(filterTo)
3636
const [minDate, setMinDate] = useState<Date>()
37-
const [maxDate, setMaxDate] = useState<Date>()
3837
const [location, setLocation] = useState<movininTypes.Location | null | undefined>(filterLocation)
3938
const [fromError, setFromError] = useState(false)
4039
const [toError, setToError] = useState(false)
@@ -47,14 +46,6 @@ const PropertyFilter = ({
4746
}
4847
}, [filterFrom])
4948

50-
useEffect(() => {
51-
if (filterTo) {
52-
const __maxDate = new Date(filterTo)
53-
__maxDate.setDate(__maxDate.getDate() - 1)
54-
setMaxDate(__maxDate)
55-
}
56-
}, [filterTo])
57-
5849
const handleLocationChange = (values: movininTypes.Option[]) => {
5950
const _location = (values.length > 0 && values[0]) || null
6051

@@ -99,7 +90,6 @@ const PropertyFilter = ({
9990
label={commonStrings.FROM}
10091
value={from}
10192
minDate={_minDate}
102-
maxDate={maxDate}
10393
variant="standard"
10494
required
10595
onChange={(date) => {
@@ -109,6 +99,10 @@ const PropertyFilter = ({
10999
setFrom(date)
110100
setMinDate(__minDate)
111101
setFromError(false)
102+
103+
if (to && (to.getTime() - date.getTime() < 24 * 60 * 60 * 1000)) {
104+
setTo(undefined)
105+
}
112106
} else {
113107
setFrom(undefined)
114108
setMinDate(_minDate)
@@ -133,14 +127,10 @@ const PropertyFilter = ({
133127
required
134128
onChange={(date) => {
135129
if (date) {
136-
const _maxDate = new Date(date)
137-
_maxDate.setDate(_maxDate.getDate() - 1)
138130
setTo(date)
139-
setMaxDate(_maxDate)
140131
setToError(false)
141132
} else {
142133
setTo(undefined)
143-
setMaxDate(undefined)
144134
}
145135
}}
146136
onError={(err: DateTimeValidationError) => {

frontend/src/components/SearchForm.tsx

+4-6
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ const SearchForm = (
3333
const [from, setFrom] = useState<Date>()
3434
const [to, setTo] = useState<Date>()
3535
const [minDate, setMinDate] = useState<Date>(_minDate)
36-
const [maxDate, setMaxDate] = useState<Date>()
3736
const [fromError, setFromError] = useState(false)
3837
const [toError, setToError] = useState(false)
3938

@@ -94,7 +93,6 @@ const SearchForm = (
9493
label={commonStrings.FROM}
9594
value={from}
9695
minDate={_minDate}
97-
maxDate={maxDate}
9896
variant="outlined"
9997
required
10098
onChange={(date) => {
@@ -104,6 +102,10 @@ const SearchForm = (
104102
setFrom(date)
105103
setMinDate(__minDate)
106104
setFromError(false)
105+
106+
if (to && (to.getTime() - date.getTime() < 24 * 60 * 60 * 1000)) {
107+
setTo(undefined)
108+
}
107109
} else {
108110
setFrom(undefined)
109111
setMinDate(_minDate)
@@ -128,14 +130,10 @@ const SearchForm = (
128130
required
129131
onChange={(date) => {
130132
if (date) {
131-
const _maxDate = new Date(date)
132-
_maxDate.setDate(_maxDate.getDate() - 1)
133133
setTo(date)
134-
setMaxDate(_maxDate)
135134
setToError(false)
136135
} else {
137136
setTo(undefined)
138-
setMaxDate(undefined)
139137
}
140138
}}
141139
onError={(err: DateTimeValidationError) => {

mobile/screens/HomeScreen.tsx

+1-7
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ const HomeScreen = ({ navigation, route }: NativeStackScreenProps<StackParams, '
3232
const [from, setFrom] = useState<Date>()
3333
const [to, setTo] = useState<Date>()
3434
const [minDate, setMinDate] = useState(_minDate)
35-
const [maxDate, setMaxDate] = useState<Date>()
3635
const [language, setLanguage] = useState(env.DEFAULT_LANGUAGE)
3736
const [blur, setBlur] = useState(false)
3837
const [reload, setReload] = useState(false)
@@ -151,12 +150,11 @@ const HomeScreen = ({ navigation, route }: NativeStackScreenProps<StackParams, '
151150
label={i18n.t('FROM_DATE')}
152151
value={from}
153152
minDate={_minDate}
154-
maxDate={maxDate}
155153
onChange={(date: Date | undefined) => {
156154
if (date) {
157155
date.setHours(12, 0, 0, 0)
158156

159-
if (to && to.getTime() <= date.getTime()) {
157+
if (to && ((to.getTime() <= date.getTime()) || (date.getTime() > to.getTime()))) {
160158
setTo(undefined)
161159
}
162160

@@ -182,12 +180,8 @@ const HomeScreen = ({ navigation, route }: NativeStackScreenProps<StackParams, '
182180
if (date) {
183181
date.setHours(12, 0, 0, 0)
184182
setTo(date)
185-
const _maxDate = new Date(date)
186-
_maxDate.setDate(_maxDate.getDate() - 1)
187-
setMaxDate(_maxDate)
188183
} else {
189184
setTo(undefined)
190-
setMaxDate(undefined)
191185
}
192186
}}
193187
onPress={blurLocations}

0 commit comments

Comments
 (0)