2022-05-14 17:38:25 +03:00
|
|
|
import { endOfDay } from 'date-fns';
|
2023-02-18 12:40:37 +03:00
|
|
|
import type { DateRange } from '../helpers/dateIntervals';
|
2023-02-18 13:11:01 +03:00
|
|
|
import { DateInput } from './DateInput';
|
2020-01-14 21:59:25 +03:00
|
|
|
|
2020-12-15 00:58:15 +03:00
|
|
|
interface DateRangeRowProps extends DateRange {
|
2021-06-24 21:13:06 +03:00
|
|
|
onStartDateChange: (date: Date | null) => void;
|
|
|
|
onEndDateChange: (date: Date | null) => void;
|
2020-08-31 19:38:27 +03:00
|
|
|
disabled?: boolean;
|
|
|
|
}
|
2020-01-14 21:59:25 +03:00
|
|
|
|
2022-05-28 12:16:59 +03:00
|
|
|
export const DateRangeRow = (
|
2020-08-31 19:38:27 +03:00
|
|
|
{ startDate = null, endDate = null, disabled = false, onStartDateChange, onEndDateChange }: DateRangeRowProps,
|
|
|
|
) => (
|
2020-01-14 21:59:25 +03:00
|
|
|
<div className="row">
|
2020-04-04 00:00:57 +03:00
|
|
|
<div className="col-md-6">
|
2020-01-14 21:59:25 +03:00
|
|
|
<DateInput
|
|
|
|
selected={startDate}
|
2020-12-15 00:58:15 +03:00
|
|
|
placeholderText="Since..."
|
2020-01-14 21:59:25 +03:00
|
|
|
isClearable
|
2020-08-31 19:38:27 +03:00
|
|
|
maxDate={endDate ?? undefined}
|
2020-04-10 13:25:06 +03:00
|
|
|
disabled={disabled}
|
2020-01-14 22:12:30 +03:00
|
|
|
onChange={onStartDateChange}
|
2020-01-14 21:59:25 +03:00
|
|
|
/>
|
|
|
|
</div>
|
2020-04-04 00:00:57 +03:00
|
|
|
<div className="col-md-6">
|
2020-01-14 21:59:25 +03:00
|
|
|
<DateInput
|
2020-12-12 18:55:01 +03:00
|
|
|
className="mt-2 mt-md-0"
|
2020-01-14 21:59:25 +03:00
|
|
|
selected={endDate}
|
2020-12-15 00:58:15 +03:00
|
|
|
placeholderText="Until..."
|
2020-01-14 21:59:25 +03:00
|
|
|
isClearable
|
2020-08-31 19:38:27 +03:00
|
|
|
minDate={startDate ?? undefined}
|
2020-04-10 13:25:06 +03:00
|
|
|
disabled={disabled}
|
2022-05-14 17:36:45 +03:00
|
|
|
onChange={(date) => onEndDateChange(date && endOfDay(date))}
|
2020-01-14 21:59:25 +03:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|