From ef8b120d16ffea1219cebaaf48714806c7fedf37 Mon Sep 17 00:00:00 2001 From: Bony Sureliya <91757486+bonysureliya@users.noreply.github.com> Date: Mon, 20 Feb 2023 14:42:56 +0530 Subject: [PATCH] Use the actual current period on the usage page --- components/dashboard/src/components/UsageView.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/components/dashboard/src/components/UsageView.tsx b/components/dashboard/src/components/UsageView.tsx index c23f7d0afcbff0..3e17842d3fd5a0 100644 --- a/components/dashboard/src/components/UsageView.tsx +++ b/components/dashboard/src/components/UsageView.tsx @@ -41,9 +41,14 @@ function UsageView({ attributionId }: UsageViewProps) { const match = /#(\d{4}-\d{2}-\d{2}):(\d{4}-\d{2}-\d{2})/.exec(location.hash); if (match) { try { - setStartDate(dayjs(match[1], "YYYY-MM-DD")); - setEndDate(dayjs(match[2], "YYYY-MM-DD")); + const today = new Date(); + const prevMonth = new Date(today.getFullYear(), today.getMonth() - 1, today.getDate()); + const todayStr = today.toISOString().slice(0, 10); + const prevMonthStr = prevMonth.toISOString().slice(0, 10); + setStartDate(dayjs(prevMonthStr)); + setEndDate(dayjs(todayStr)); } catch (e) { + // Catches the Error console.error(e); } }