Skip to content

Commit 7fb9fdc

Browse files
author
Laurie T. Malau
committed
drive-by extract svg
1 parent 9254d7a commit 7fb9fdc

File tree

1 file changed

+41
-8
lines changed

1 file changed

+41
-8
lines changed

components/dashboard/src/teams/TeamUsage.tsx

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ function TeamUsage() {
2929
const [errorMessage, setErrorMessage] = useState("");
3030
const today = new Date();
3131
const startOfCurrentMonth = new Date(today.getFullYear(), today.getMonth(), 1);
32-
const timestampOfStart = startOfCurrentMonth.getTime();
33-
const [startDateOfBillMonth] = useState(timestampOfStart);
32+
const timestampStartOfCurrentMonth = startOfCurrentMonth.getTime();
33+
const [startDateOfBillMonth, setStartDateOfBillMonth] = useState(timestampStartOfCurrentMonth);
34+
const [endDateOfBillMonth, setEndDateOfBillMonth] = useState(Date.now());
3435

3536
useEffect(() => {
3637
if (!team) {
@@ -41,8 +42,8 @@ function TeamUsage() {
4142
try {
4243
const billedUsageResult = await getGitpodService().server.listBilledUsage(
4344
attributionId,
44-
startDateOfBillMonth, // TODO: set based on selected month
45-
Date.now(), // TODO: set based on selected month
45+
startDateOfBillMonth,
46+
endDateOfBillMonth,
4647
);
4748
setBilledUsage(billedUsageResult);
4849
} catch (error) {
@@ -51,7 +52,7 @@ function TeamUsage() {
5152
}
5253
}
5354
})();
54-
}, [team]);
55+
}, [team, startDateOfBillMonth, endDateOfBillMonth]);
5556

5657
if (!showUsageBasedPricingUI) {
5758
return <Redirect to="/" />;
@@ -83,6 +84,32 @@ function TeamUsage() {
8384
return totalCredits;
8485
};
8586

87+
const handleCurrentMonthClick = (start: any, end: any) => {
88+
setStartDateOfBillMonth(start);
89+
setEndDateOfBillMonth(end);
90+
};
91+
92+
const getBillingHistory = () => {
93+
let rows = [];
94+
for (let i = 1; i < 7; i++) {
95+
const endDateVar = i + 2;
96+
const startDate = new Date(today.getFullYear(), today.getMonth() - i);
97+
const endDate = new Date(today.getFullYear(), today.getMonth(), endDateVar);
98+
const timeStampOfStartDate = startDate.getTime();
99+
const timeStampOfEndDate = endDate.getTime();
100+
rows.push(
101+
<div
102+
key={`billing${i}`}
103+
className="text-lg text-gray-600 font-semibold truncate cursor-pointer"
104+
onClick={() => handleCurrentMonthClick(timeStampOfStartDate, timeStampOfEndDate)}
105+
>
106+
{startDate.toLocaleString("default", { month: "long" })} {startOfCurrentMonth.getFullYear()}
107+
</div>,
108+
);
109+
}
110+
return rows;
111+
};
112+
86113
const lastResultOnCurrentPage = currentPage * resultsPerPage;
87114
const firstResultOnCurrentPage = lastResultOnCurrentPage - resultsPerPage;
88115
const numberOfPages = Math.ceil(billedUsage.length / resultsPerPage);
@@ -99,15 +126,21 @@ function TeamUsage() {
99126
<div className="space-y-8 mb-6" style={{ width: "max-content" }}>
100127
<div className="flex flex-col truncate">
101128
<div className="text-base text-gray-500 truncate">Period</div>
102-
<div className="text-lg text-gray-600 font-semibold truncate">
129+
<div
130+
className="text-lg text-gray-600 font-semibold truncate cursor-pointer"
131+
onClick={() =>
132+
handleCurrentMonthClick(timestampStartOfCurrentMonth, Date.now())
133+
}
134+
>
103135
{startOfCurrentMonth.toLocaleString("default", { month: "long" })}{" "}
104136
{startOfCurrentMonth.getFullYear()}
105137
</div>
138+
{getBillingHistory()}
106139
</div>
107140
<div className="flex flex-col truncate">
108141
<div className="text-base text-gray-500">Total usage</div>
109142
<div className="flex text-lg text-gray-600 font-semibold">
110-
<CreditsSvg />
143+
<CreditsSvg className="my-auto mr-1" />
111144
<span>{calculateTotalUsage()} Total Credits</span>
112145
</div>
113146
</div>
@@ -142,7 +175,7 @@ function TeamUsage() {
142175
<span>Usage</span>
143176
</ItemField>
144177
<ItemField className="flex my-auto">
145-
<CreditsSvg />
178+
<CreditsSvg className="my-auto mr-1" />
146179
<span>Credits</span>
147180
</ItemField>
148181
<ItemField className="my-auto" />

0 commit comments

Comments
 (0)