Skip to content

Commit

Permalink
feature(hooks): use locale in useDateRange hook
Browse files Browse the repository at this point in the history
  • Loading branch information
gnarlex committed Mar 10, 2021
1 parent a1edcec commit 3cb748b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions hooks/useDateRange.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import { getItem, setItem } from 'lib/web';
import { setDateRange } from '../redux/actions/websites';
import { DATE_RANGE_CONFIG, DEFAULT_DATE_RANGE } from 'lib/constants';
import useForceUpdate from './useForceUpdate';
import useLocale from './useLocale';

export default function useDateRange(websiteId, defaultDateRange = DEFAULT_DATE_RANGE) {
const dispatch = useDispatch();
const [locale] = useLocale();
const dateRange = useSelector(state => state.websites[websiteId]?.dateRange);
const forceUpdate = useForceUpdate();

Expand All @@ -16,7 +18,7 @@ export default function useDateRange(websiteId, defaultDateRange = DEFAULT_DATE_

if (globalDefault) {
if (typeof globalDefault === 'string') {
globalDateRange = getDateRange(globalDefault);
globalDateRange = getDateRange(globalDefault, locale);
} else if (typeof globalDefault === 'object') {
globalDateRange = {
...globalDefault,
Expand All @@ -37,5 +39,5 @@ export default function useDateRange(websiteId, defaultDateRange = DEFAULT_DATE_
}
}

return [dateRange || globalDateRange || getDateRange(defaultDateRange), saveDateRange];
return [dateRange || globalDateRange || getDateRange(defaultDateRange, locale), saveDateRange];
}

0 comments on commit 3cb748b

Please sign in to comment.