mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-15 17:55:08 +01:00
44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
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 { getDateRange } from 'lib/date';
|
|
import styles from './DateRangeSetting.module.css';
|
|
import useLocale from 'hooks/useLocale';
|
|
|
|
export default function DateRangeSetting() {
|
|
const { locale } = useLocale();
|
|
const [dateRange, setDateRange] = useDateRange();
|
|
const { startDate, endDate, value } = dateRange;
|
|
const options = filterOptions.filter(e => e.value !== 'all');
|
|
|
|
function handleChange(value) {
|
|
if (typeof value === 'string') {
|
|
setDateRange(getDateRange(value, locale));
|
|
} else {
|
|
setDateRange(value);
|
|
}
|
|
}
|
|
|
|
function handleReset() {
|
|
setDateRange(getDateRange(DEFAULT_DATE_RANGE, locale));
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<DateFilter
|
|
options={options}
|
|
value={value}
|
|
startDate={startDate}
|
|
endDate={endDate}
|
|
onChange={handleChange}
|
|
/>
|
|
<Button className={styles.button} size="small" onClick={handleReset}>
|
|
<FormattedMessage id="label.reset" defaultMessage="Reset" />
|
|
</Button>
|
|
</>
|
|
);
|
|
}
|