2020-09-19 19:35:05 +02:00
|
|
|
import React from 'react';
|
|
|
|
import { FormattedMessage } from 'react-intl';
|
2022-01-21 04:54:58 +01:00
|
|
|
import DateFilter, { filterOptions } from 'components/common/DateFilter';
|
2022-12-27 01:57:59 +01:00
|
|
|
import { Button } from 'react-basics';
|
2020-09-19 19:35:05 +02:00
|
|
|
import useDateRange from 'hooks/useDateRange';
|
|
|
|
import { DEFAULT_DATE_RANGE } from 'lib/constants';
|
|
|
|
import styles from './DateRangeSetting.module.css';
|
|
|
|
|
|
|
|
export default function DateRangeSetting() {
|
|
|
|
const [dateRange, setDateRange] = useDateRange();
|
|
|
|
const { startDate, endDate, value } = dateRange;
|
2022-01-21 04:54:58 +01:00
|
|
|
const options = filterOptions.filter(e => e.value !== 'all');
|
2020-09-19 19:35:05 +02:00
|
|
|
|
2022-03-02 07:02:31 +01:00
|
|
|
function handleChange(value) {
|
|
|
|
setDateRange(value);
|
|
|
|
}
|
|
|
|
|
2020-09-19 19:35:05 +02:00
|
|
|
function handleReset() {
|
2022-03-02 07:02:31 +01:00
|
|
|
setDateRange(DEFAULT_DATE_RANGE);
|
2020-09-19 19:35:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2022-01-21 04:54:58 +01:00
|
|
|
<DateFilter
|
|
|
|
options={options}
|
|
|
|
value={value}
|
|
|
|
startDate={startDate}
|
|
|
|
endDate={endDate}
|
2022-03-02 07:02:31 +01:00
|
|
|
onChange={handleChange}
|
2022-01-21 04:54:58 +01:00
|
|
|
/>
|
2022-12-27 01:57:59 +01:00
|
|
|
<Button className={styles.button} size="sm" onClick={handleReset}>
|
2020-10-13 07:53:59 +02:00
|
|
|
<FormattedMessage id="label.reset" defaultMessage="Reset" />
|
2020-09-19 19:35:05 +02:00
|
|
|
</Button>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|