Skip to content

Commit ada3d73

Browse files
Merge pull request #4426 from OneCommunityGlobal/aseem-jobposting-analytics-custom-date-filter-state-handling
Aseem jobposting analytics custom date filter state handling
2 parents 7035915 + cf35141 commit ada3d73

3 files changed

Lines changed: 33 additions & 4 deletions

File tree

src/components/ApplicantsChart/ApplicantsChart.module.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@
9191
color: #9ca3af !important;
9292
opacity: 1 !important;
9393
}
94+
.disabledDay {
95+
color: #9ca3af !important; /* gray */
96+
pointer-events: none;
97+
cursor: not-allowed;
98+
}
9499

95100
:global(.text-light) :global(.hgn-datepicker-dark):focus,
96101
:global(.text-light) :global(.hgn-datepicker-dark):focus input,

src/components/ApplicantsChart/TimeFilter.jsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState, useEffect } from 'react';
1+
import { useState, useEffect, useRef } from 'react';
22
import DatePicker from 'react-datepicker';
33
import 'react-datepicker/dist/react-datepicker.css';
44
import styles from './ApplicationChart.module.css';
@@ -8,21 +8,31 @@ function TimeFilter({ onFilterChange, darkMode }) {
88
const [startDate, setStartDate] = useState(null);
99
const [endDate, setEndDate] = useState(null);
1010
const [error, setError] = useState('');
11+
const prevOptionRef = useRef(selectedOption); // To track previous selected filter option
1112

1213
useEffect(() => {
14+
if (selectedOption === 'custom' && prevOptionRef.current !== 'custom') {
15+
// Reset custom dates when switching to custom
16+
setStartDate(null);
17+
setEndDate(null);
18+
}
19+
1320
if (selectedOption === 'custom' && startDate && endDate) {
1421
if (startDate > endDate) {
1522
setError('Start date cannot be after end date.');
16-
return;
1723
} else {
1824
setError('');
1925
}
2026
} else {
2127
setError('');
2228
}
2329

30+
// Updated parent with current filter state
2431
onFilterChange({ selectedOption, startDate, endDate, error: '' });
25-
}, [selectedOption, startDate, endDate]); // Removed onFilterChange from dependencies
32+
33+
prevOptionRef.current = selectedOption; // Updatse previous option
34+
}, [selectedOption, startDate, endDate]);
35+
// Removed onFilterChange from dependencies
2636

2737
return (
2838
<div className={`${styles.TimeFilter}`}>

src/components/ApplicantsChart/index.jsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ function ApplicantsDashboard() {
1414
const [compareLabel, setCompareLabel] = useState('last week');
1515
const [loading, setLoading] = useState(false);
1616
const [error, setError] = useState(null);
17+
const today = new Date();
18+
today.setHours(0, 0, 0, 0);
1719

1820
// dark mode from Redux
1921
const darkMode = useSelector(state => state.theme.darkMode);
@@ -216,8 +218,20 @@ function ApplicantsDashboard() {
216218
<span style={{ color: darkMode ? '#e5e7eb' : '#000' }}>to</span>
217219
<DatePicker
218220
selected={endDate}
219-
onChange={handleEndDateChange}
221+
onChange={date => {
222+
if (!date) return;
223+
224+
const selected = new Date(date);
225+
selected.setHours(0, 0, 0, 0);
226+
227+
if (selected > today) return; // block future dates
228+
229+
handleEndDateChange(selected);
230+
}}
220231
placeholderText="End Date"
232+
maxDate={today}
233+
filterDate={date => date <= today}
234+
dayClassName={date => (date > today ? styles.disabledDay : undefined)}
221235
{...getDatePickerProps()}
222236
/>
223237
</>

0 commit comments

Comments
 (0)