Skip to content

Commit 4a6f82b

Browse files
bonysureliyagtsiolis
authored andcommitted
Use the actual current period on the usage page
1 parent 32bb8c1 commit 4a6f82b

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

components/dashboard/src/components/UsageView.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,13 @@ function UsageView({ attributionId }: UsageViewProps) {
4646
const location = useLocation();
4747
useEffect(() => {
4848
const match = /#(\d{4}-\d{2}-\d{2}):(\d{4}-\d{2}-\d{2})/.exec(location.hash);
49-
if (match) {
50-
try {
51-
setStartDate(dayjs(match[1], "YYYY-MM-DD"));
52-
setEndDate(dayjs(match[2], "YYYY-MM-DD"));
53-
} catch (e) {
54-
console.error(e);
49+
try {
50+
const today = new Date();
51+
const prevMonth = new Date(today.getFullYear(), today.getMonth() - 1, today.getDate());
52+
const todayStr = today.toISOString().slice(0, 10);
53+
const prevMonthStr = prevMonth.toISOString().slice(0, 10);
54+
setStartDate(dayjs(prevMonthStr));
55+
setEndDate(dayjs(todayStr));
5556
}
5657
}
5758
(async () => {

0 commit comments

Comments
 (0)