Fixed bug in global date range setting.

This commit is contained in:
Mike Cao 2020-09-18 15:40:42 -07:00
parent 9eca86a4fc
commit 7d25fd6876
2 changed files with 12 additions and 5 deletions

View File

@ -30,7 +30,8 @@ export default function ProfileSettings() {
}
function handleDateChange(values) {
setItem(`umami.date-range`, values);
const { value } = values;
setItem(`umami.date-range`, value === 'custom' ? values : value);
dispatch(setDateRange(0, values));
}

View File

@ -5,14 +5,20 @@ import { getItem } from 'lib/web';
export default function useDateRange(websiteId, defaultDateRange = '24hour') {
const globalDefault = getItem('umami.date-range');
let globalDateRange;
if (globalDefault) {
globalDefault.startDate = parseISO(globalDefault.startDate);
globalDefault.endDate = parseISO(globalDefault.endDate);
if (typeof globalDefault === 'string') {
globalDateRange = getDateRange(globalDefault);
} else {
globalDateRange = {
...globalDefault,
startDate: parseISO(globalDefault.startDate),
endDate: parseISO(globalDefault.endDate),
};
}
return useSelector(
state =>
state.websites[websiteId]?.dateRange || globalDefault || getDateRange(defaultDateRange),
state.websites[websiteId]?.dateRange || globalDateRange || getDateRange(defaultDateRange),
);
}