Skip to content

Commit

Permalink
Update PropertyFilter.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
aelassas committed Apr 14, 2024
1 parent 2f928f7 commit 8f922ba
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion frontend/src/components/PropertyFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const PropertyFilter = ({
const [from, setFrom] = useState<Date | undefined>(filterFrom)
const [to, setTo] = useState<Date | undefined>(filterTo)
const [minDate, setMinDate] = useState<Date>()
const [maxDate, setMaxDate] = useState<Date>()
const [location, setLocation] = useState<movininTypes.Location | null | undefined>(filterLocation)

useEffect(() => {
Expand All @@ -39,6 +40,14 @@ const PropertyFilter = ({
}
}, [filterFrom])

useEffect(() => {
if (filterTo) {
const __maxDate = new Date(filterTo)
__maxDate.setDate(__maxDate.getDate() - 1)
setMaxDate(__maxDate)
}
}, [filterTo])

const handleLocationChange = (values: movininTypes.Option[]) => {
const _location = (values.length > 0 && values[0]) || null

Expand Down Expand Up @@ -78,6 +87,7 @@ const PropertyFilter = ({
label={commonStrings.FROM}
value={from}
minDate={new Date()}
maxDate={maxDate}
variant="standard"
required
onChange={(date) => {
Expand Down Expand Up @@ -106,7 +116,15 @@ const PropertyFilter = ({
variant="standard"
required
onChange={(date) => {
setTo(date || undefined)
if (date) {
setTo(date)
const _maxDate = new Date(date)
_maxDate.setDate(_maxDate.getDate() - 1)
setMaxDate(_maxDate)
} else {
setTo(undefined)
setMaxDate(undefined)
}
}}
language={UserService.getLanguage()}
/>
Expand Down

0 comments on commit 8f922ba

Please sign in to comment.