Skip to content

Commit 0d7715d

Browse files
Replace existing date picker with react-datepicker component
1 parent 66c6f22 commit 0d7715d

2 files changed

Lines changed: 69 additions & 5 deletions

File tree

src/components/JobCCDashboard/JobAnalytics/JobAnalytics.jsx

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ import {
4040
import styles from './JobAnalytics.module.css';
4141
import hasPermission from '../../../utils/permissions';
4242
import { ENDPOINTS } from '../../../utils/URL';
43+
import DatePicker from 'react-datepicker';
44+
import 'react-datepicker/dist/react-datepicker.css';
4345

4446
const ROLE_OPTIONS = [
4547
'All Roles',
@@ -151,6 +153,8 @@ function useMediaQuery(query) {
151153
return matches;
152154
}
153155

156+
const toIsoDate = d => d.toISOString().split('T')[0];
157+
154158
// ======================== API SERVICE ========================
155159
// ======================== API SERVICE ========================
156160
class AnalyticsService {
@@ -598,10 +602,48 @@ function DateRangeSelector({ dateRange, setDateRange, comparisonPeriod, setCompa
598602
</div>
599603
</div>
600604

601-
<div className={styles['selector-col']}>
605+
<div className={''}>
602606
<label className={styles['label']}>Custom Date Range</label>
603607
<div className={styles['dates-row']}>
604-
<input
608+
<DatePicker
609+
selected={dateRange?.start ? new Date(dateRange.start) : null}
610+
onChange={date => {
611+
setDateRange({
612+
...dateRange,
613+
start: date ? toIsoDate(date) : '',
614+
});
615+
setActive(null);
616+
}}
617+
selectsStart
618+
startDate={dateRange?.start || null}
619+
dateFormat="yyyy-MM-dd"
620+
isClearable
621+
placeholderText="Start date"
622+
className={styles.input}
623+
// wrapperClassName={styles.datePicker}
624+
// calendarClassName={styles.calendar}
625+
/>
626+
<span className={styles['to']}>to</span>
627+
<DatePicker
628+
selected={dateRange?.end ? new Date(dateRange.end) : null}
629+
onChange={date => {
630+
setDateRange({
631+
...dateRange,
632+
end: date ? toIsoDate(date) : '',
633+
});
634+
setActive(null);
635+
}}
636+
selectsEnd
637+
endDate={dateRange?.end || null}
638+
dateFormat="yyyy-MM-dd"
639+
minDate={dateRange?.start ? new Date(dateRange.start) : undefined}
640+
isClearable
641+
placeholderText="End date"
642+
className={styles.input}
643+
// wrapperClassName={styles.datePicker}
644+
// calendarClassName={styles.calendar}
645+
/>
646+
{/* <input
605647
type="date"
606648
className={styles['input']}
607649
value={dateRange?.start || ''}
@@ -619,7 +661,7 @@ function DateRangeSelector({ dateRange, setDateRange, comparisonPeriod, setCompa
619661
setDateRange({ ...dateRange, end: e.target.value });
620662
setActive(null);
621663
}}
622-
/>
664+
/> */}
623665
</div>
624666
</div>
625667

src/components/JobCCDashboard/JobAnalytics/JobAnalytics.module.css

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,20 @@
179179
filter: invert(1);
180180
}
181181

182+
.datePicker {
183+
padding: 10px 14px;
184+
border-radius: 8px;
185+
color: #111827;
186+
font-size: 0.875rem;
187+
}
188+
189+
.react-datepicker__close-icon::after {
190+
display: flex;
191+
align-items: center;
192+
justify-content: center;
193+
background-color: red!;
194+
}
195+
182196
/* Spin animation for refresh icon */
183197
.spin {
184198
animation: spin 1s linear infinite;
@@ -313,13 +327,14 @@
313327

314328
.dates-row {
315329
display: flex;
330+
justify-content: space-between;
316331
align-items: center;
317-
gap: 8px;
318332
}
319333

320334

321335
.to {
322336
color: #6b7280;
337+
margin-inline: 8px;
323338
}
324339

325340
.darkMode .to {
@@ -671,4 +686,11 @@
671686
/* Charts Grid Stroke */
672687
.grid-stroke line {
673688
stroke: var(--grid-stroke) !important;
674-
}
689+
}
690+
691+
/* .calendar {
692+
.react-datepicker__navigation-icon {
693+
background-color: red;
694+
color: blue;
695+
}
696+
} */

0 commit comments

Comments
 (0)