Skip to content

Commit f3798b3

Browse files
committed
fix(CPDashboard): update datepicker with handleChange
1 parent f7f7bcb commit f3798b3

1 file changed

Lines changed: 18 additions & 20 deletions

File tree

src/components/CommunityPortal/CPDashboard.jsx

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { toast } from 'react-toastify';
99
export function CPDashboard() {
1010
const [events, setEvents] = useState([]);
1111
const [search, setSearch] = useState('');
12-
const [date, setDate] = useState(null);
1312
const [selectedDate, setSelectedDate] = useState('');
1413
const [dateError, setDateError] = useState('');
1514

@@ -43,20 +42,24 @@ export function CPDashboard() {
4342
setEvents(mockEvents);
4443
}, []);
4544

46-
const handleDateChange = e => {
47-
const value = e.target.value;
48-
setSelectedDate(value);
45+
const handleDateChange = date => {
46+
setDateError('');
47+
48+
if (!date) {
49+
setSelectedDate('');
50+
return;
51+
}
4952

5053
const today = new Date();
5154
today.setHours(0, 0, 0, 0); // midnight today
5255

53-
const chosen = new Date(value);
54-
55-
if (chosen < today) {
56+
if (date < today) {
5657
toast.error('Past dates are not supported. Please select a future date.');
5758
setSelectedDate('');
5859
return;
5960
}
61+
62+
setSelectedDate(date);
6063
};
6164

6265
return (
@@ -103,26 +106,21 @@ export function CPDashboard() {
103106
</div>
104107
<div style={{ width: '100%' }}>
105108
<DatePicker
106-
selected={date}
107-
onChange={d => setDate(d)}
109+
selected={selectedDate}
110+
onChange={date => handleDateChange(date)}
108111
placeholderText="Ending After"
109112
id="ending-after"
110113
className="date-filter"
111114
style={{ width: '100%' }}
112115
/>
116+
{dateError && (
117+
<p className="date-error-message" style={{ color: 'red', marginTop: '5px' }}>
118+
{dateError}
119+
</p>
120+
)}
113121
</div>
114-
<Input
115-
type="date"
116-
value={selectedDate}
117-
onChange={handleDateChange}
118-
className="date-filter"
119-
/>
120-
{dateError && (
121-
<p className="date-error-message" style={{ color: 'red', marginTop: '5px' }}>
122-
{dateError}
123-
</p>
124-
)}
125122
</div>
123+
126124
<div className="filter-item">
127125
<label htmlFor="online-only">Online</label>
128126
<div>

0 commit comments

Comments
 (0)