Skip to content

Commit

Permalink
Fix crash issue when date filter start & end date mismatch
Browse files Browse the repository at this point in the history
- Adjust dates when start date greater than end date or vice versa
  • Loading branch information
royallsilwallz committed Jan 2, 2025
1 parent caec397 commit ecaebf2
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions frontend/src/components/partnerMapswipeStats/dateFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,28 @@ export const DateFilter = ({ isLoading, filters, setFilters }) => {
}));
}, [setFilters]);

const handleDateSelect = (key, date) => {
const handleDateSelect = (key, selectedDate) => {
let { fromDate, toDate } = filters;
const selectedDateValue = new Date(selectedDate).valueOf();
const toDateValue = new Date(toDate).valueOf();
const fromDateValue = new Date(fromDate).valueOf();
// adjust from and to date based on greater/lesser value
if (key === 'fromDate' && selectedDateValue > toDateValue) {
fromDate = toDate;
toDate = selectedDate;
} else if (key === 'toDate' && selectedDateValue < fromDateValue) {
toDate = fromDate;
fromDate = selectedDate;
} else if (key === 'toDate') {
toDate = selectedDate;
} else {
fromDate = selectedDate;
}
// set filters state
setFilters((prev) => ({
...prev,
[key]: date,
fromDate,
toDate,
}));
};

Expand Down

0 comments on commit ecaebf2

Please sign in to comment.