Skip to content

Commit afe33dc

Browse files
svenefftingeroboquat
authored andcommitted
[usage view] remove unused billingmode
1 parent 9c77d94 commit afe33dc

File tree

3 files changed

+14
-60
lines changed

3 files changed

+14
-60
lines changed

components/dashboard/src/Usage.tsx

+3-28
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,19 @@
44
* See License-AGPL.txt in the project root for license information.
55
*/
66

7-
import { useContext, useEffect, useState } from "react";
7+
import { useContext } from "react";
88

9-
import { getGitpodService, gitpodHostUrl } from "./service/service";
10-
import { BillingMode } from "@gitpod/gitpod-protocol/lib/billing-mode";
119
import UsageView from "./components/UsageView";
12-
import { AttributionId } from "@gitpod/gitpod-protocol/lib/attribution";
1310
import { UserContext } from "./user-context";
1411

1512
function TeamUsage() {
1613
const { user } = useContext(UserContext);
17-
const [billingMode, setBillingMode] = useState<BillingMode | undefined>(undefined);
18-
const [attributionId, setAttributionId] = useState<AttributionId | undefined>();
1914

20-
useEffect(() => {
21-
if (!user) {
22-
return;
23-
}
24-
setAttributionId({ kind: "user", userId: user.id });
25-
(async () => {
26-
const billingMode = await getGitpodService().server.getBillingModeForUser();
27-
setBillingMode(billingMode);
28-
})();
29-
}, [user]);
30-
31-
useEffect(() => {
32-
if (!billingMode) {
33-
return;
34-
}
35-
if (!BillingMode.showUsageBasedBilling(billingMode)) {
36-
window.location.href = gitpodHostUrl.asDashboard().toString();
37-
}
38-
}, [billingMode]);
39-
40-
if (!billingMode || !attributionId) {
15+
if (!user) {
4116
return <></>;
4217
}
4318

44-
return <UsageView billingMode={billingMode} attributionId={attributionId} />;
19+
return <UsageView attributionId={{ kind: "user", userId: user.id }} />;
4520
}
4621

4722
export default TeamUsage;

components/dashboard/src/components/UsageView.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,15 @@ import { ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error";
2121
import { ReactComponent as CreditsSvg } from "../images/credits.svg";
2222
import { ReactComponent as Spinner } from "../icons/Spinner.svg";
2323
import { ReactComponent as UsageIcon } from "../images/usage-default.svg";
24-
import { BillingMode } from "@gitpod/gitpod-protocol/lib/billing-mode";
2524
import { toRemoteURL } from "../projects/render-utils";
2625
import { WorkspaceType } from "@gitpod/gitpod-protocol";
2726
import PillLabel from "./PillLabel";
2827

2928
interface UsageViewProps {
3029
attributionId: AttributionId;
31-
billingMode: BillingMode;
3230
}
3331

34-
function UsageView({ attributionId, billingMode }: UsageViewProps) {
32+
function UsageView({ attributionId }: UsageViewProps) {
3533
const [usagePage, setUsagePage] = useState<ListUsageResponse | undefined>(undefined);
3634
const [errorMessage, setErrorMessage] = useState("");
3735
const today = new Date();

components/dashboard/src/teams/TeamUsage.tsx

+10-29
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,27 @@
44
* See License-AGPL.txt in the project root for license information.
55
*/
66

7-
import { useContext, useEffect, useState } from "react";
7+
import { useContext } from "react";
88
import { useLocation } from "react-router";
99
import { getCurrentTeam, TeamsContext } from "./teams-context";
10-
import { getGitpodService, gitpodHostUrl } from "../service/service";
11-
import { BillingMode } from "@gitpod/gitpod-protocol/lib/billing-mode";
1210
import UsageView from "../components/UsageView";
13-
import { AttributionId } from "@gitpod/gitpod-protocol/lib/attribution";
1411

1512
function TeamUsage() {
1613
const { teams } = useContext(TeamsContext);
1714
const location = useLocation();
1815
const team = getCurrentTeam(location, teams);
19-
const [billingMode, setBillingMode] = useState<BillingMode | undefined>(undefined);
20-
const [attributionId, setAttributionId] = useState<AttributionId | undefined>();
21-
22-
useEffect(() => {
23-
if (!team) {
24-
return;
25-
}
26-
setAttributionId({ kind: "team", teamId: team.id });
27-
(async () => {
28-
const billingMode = await getGitpodService().server.getBillingModeForTeam(team.id);
29-
setBillingMode(billingMode);
30-
})();
31-
}, [team]);
32-
33-
useEffect(() => {
34-
if (!billingMode) {
35-
return;
36-
}
37-
if (!BillingMode.showUsageBasedBilling(billingMode)) {
38-
window.location.href = gitpodHostUrl.asDashboard().toString();
39-
}
40-
}, [billingMode]);
41-
42-
if (!billingMode || !attributionId) {
16+
if (!team) {
4317
return <></>;
4418
}
4519

46-
return <UsageView billingMode={billingMode} attributionId={attributionId} />;
20+
return (
21+
<UsageView
22+
attributionId={{
23+
kind: "team",
24+
teamId: team.id,
25+
}}
26+
/>
27+
);
4728
}
4829

4930
export default TeamUsage;

0 commit comments

Comments
 (0)