Skip to content

Commit

Permalink
Fix usage page
Browse files Browse the repository at this point in the history
  • Loading branch information
MauAraujo committed May 15, 2024
1 parent e3325cf commit 8d41748
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions dashboard/src/main/home/project-settings/UsagePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function UsagePage(): JSX.Element {
const planStartDate = dayjs.utc(plan?.starting_on).startOf("month");

const [currentPeriod, setCurrentPeriod] = useState(
dayjs().utc().startOf("month")
dayjs().utc().format("MMMM YYYY")
);
const [options, setOptions] = useState<
Array<{ value: string; label: string }>
Expand All @@ -43,7 +43,7 @@ function UsagePage(): JSX.Element {

if (monthsElapsed <= 0) {
options.push({
value: currentPeriod.month().toString(),
value: currentPeriod,
label: dayjs().utc().format("MMMM YYYY"),
});
setShowCurrentPeriod(true);
Expand All @@ -54,7 +54,7 @@ function UsagePage(): JSX.Element {
for (let i = 0; i <= monthsElapsed; i++) {
const optionDate = planStartDate.add(i, "month");
options.push({
value: optionDate.month().toString(),
value: optionDate.format("MMMM YYYY"),
label: optionDate.format("MMMM YYYY"),
});
}
Expand All @@ -69,7 +69,8 @@ function UsagePage(): JSX.Element {

const periodUsage = usageList.find(
(usage) =>
dayjs(usage.from_datetime).utc().month() === currentPeriod.month()
dayjs(usage.from_datetime).utc().month() ===
dayjs(currentPeriod).month()
);

if (!periodUsage) {
Expand Down Expand Up @@ -105,10 +106,10 @@ function UsagePage(): JSX.Element {
<>
<Select
options={options}
value={currentPeriod.month().toString()}
value={currentPeriod}
setValue={(value) => {
setCurrentPeriod(dayjs.utc(value));
if (dayjs(value).isSame(dayjs(), "month")) {
setCurrentPeriod(value);
if (dayjs().format("MMMM YYYY") === value) {
setShowCurrentPeriod(true);
} else {
setShowCurrentPeriod(false);
Expand Down

0 comments on commit 8d41748

Please sign in to comment.