umami/components/settings/DateRangeSetting.js

37 lines
1.0 KiB
JavaScript
Raw Normal View History

import React from 'react';
import { FormattedMessage } from 'react-intl';
import DateFilter, { filterOptions } from 'components/common/DateFilter';
import Button from 'components/common/Button';
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;
const options = filterOptions.filter(e => e.value !== 'all');
2022-03-02 07:02:31 +01:00
function handleChange(value) {
setDateRange(value);
}
function handleReset() {
2022-03-02 07:02:31 +01:00
setDateRange(DEFAULT_DATE_RANGE);
}
return (
<>
<DateFilter
options={options}
value={value}
startDate={startDate}
endDate={endDate}
2022-03-02 07:02:31 +01:00
onChange={handleChange}
/>
<Button className={styles.button} size="small" onClick={handleReset}>
2020-10-13 07:53:59 +02:00
<FormattedMessage id="label.reset" defaultMessage="Reset" />
</Button>
</>
);
}