mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-15 17:55:08 +01:00
27 lines
814 B
JavaScript
27 lines
814 B
JavaScript
|
import { getDateRangeValues } from 'lib/date';
|
||
|
import useApi from 'hooks/useApi';
|
||
|
import useDateRange from 'hooks/useDateRange';
|
||
|
import DateFilter from './DateFilter';
|
||
|
|
||
|
export default function WebsiteDateFilter({ websiteId, value }) {
|
||
|
const { get } = useApi();
|
||
|
const [dateRange, setDateRange] = useDateRange(websiteId);
|
||
|
const { startDate, endDate } = dateRange;
|
||
|
|
||
|
const handleChange = async value => {
|
||
|
if (value === 'all' && websiteId) {
|
||
|
const data = await get(`/websites/${websiteId}`);
|
||
|
|
||
|
if (data) {
|
||
|
setDateRange({ value, ...getDateRangeValues(new Date(data.createdAt), Date.now()) });
|
||
|
}
|
||
|
} else if (value !== 'all') {
|
||
|
setDateRange(value);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
return (
|
||
|
<DateFilter value={value} startDate={startDate} endDate={endDate} onChange={handleChange} />
|
||
|
);
|
||
|
}
|