From 7d25fd6876f9ff385ff9411977a475e497c518d5 Mon Sep 17 00:00:00 2001 From: Mike Cao Date: Fri, 18 Sep 2020 15:40:42 -0700 Subject: [PATCH] Fixed bug in global date range setting. --- components/settings/ProfileSettings.js | 3 ++- hooks/useDateRange.js | 14 ++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/components/settings/ProfileSettings.js b/components/settings/ProfileSettings.js index 69bc34e9..10386318 100644 --- a/components/settings/ProfileSettings.js +++ b/components/settings/ProfileSettings.js @@ -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)); } diff --git a/hooks/useDateRange.js b/hooks/useDateRange.js index e6ad6808..9a88a5a1 100644 --- a/hooks/useDateRange.js +++ b/hooks/useDateRange.js @@ -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), ); }