Skip to content

Commit f6b577c

Browse files
committed
[dashboard] Show all the user's teams which have usage-based billing enabled
1 parent af5ef7a commit f6b577c

File tree

1 file changed

+59
-9
lines changed

1 file changed

+59
-9
lines changed

components/dashboard/src/settings/Billing.tsx

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,37 @@
44
* See License-AGPL.txt in the project root for license information.
55
*/
66

7-
import { useContext } from "react";
7+
import { Team } from "@gitpod/gitpod-protocol";
8+
import { useContext, useEffect, useState } from "react";
89
import { Link } from "react-router-dom";
10+
import getSettingsMenu from "./settings-menu";
11+
import { ReactComponent as Spinner } from "../icons/Spinner.svg";
12+
import DropDown from "../components/DropDown";
913
import { PageWithSubMenu } from "../components/PageWithSubMenu";
1014
import { PaymentContext } from "../payment-context";
11-
import getSettingsMenu from "./settings-menu";
15+
import { getGitpodService } from "../service/service";
16+
import { TeamsContext } from "../teams/teams-context";
1217

1318
export default function Billing() {
1419
const { showPaymentUI, showUsageBasedUI } = useContext(PaymentContext);
20+
const { teams } = useContext(TeamsContext);
21+
const [teamsWithBillingEnabled, setTeamsWithBillingEnabled] = useState<Team[] | undefined>();
22+
23+
useEffect(() => {
24+
if (!teams) {
25+
setTeamsWithBillingEnabled(undefined);
26+
return;
27+
}
28+
const teamsWithBilling: Team[] = [];
29+
Promise.all(
30+
teams.map(async (t) => {
31+
const subscriptionId = await getGitpodService().server.findStripeSubscriptionIdForTeam(t.id);
32+
if (subscriptionId) {
33+
teamsWithBilling.push(t);
34+
}
35+
}),
36+
).then(() => setTeamsWithBillingEnabled(teamsWithBilling));
37+
}, [teams]);
1538

1639
return (
1740
<PageWithSubMenu
@@ -21,13 +44,40 @@ export default function Billing() {
2144
>
2245
<h3>Usage-Based Billing</h3>
2346
<h2 className="text-gray-500">Manage usage-based billing, spending limit, and payment method.</h2>
24-
<p className="mt-8">
25-
Hint:{" "}
26-
<Link className="gp-link" to="/teams/new">
27-
Create a team
28-
</Link>{" "}
29-
to set up usage-based billing.
30-
</p>
47+
<div className="mt-8">
48+
<h3>Billing Account</h3>
49+
{teamsWithBillingEnabled === undefined && <Spinner className="m-2 h-5 w-5 animate-spin" />}
50+
{teamsWithBillingEnabled && teamsWithBillingEnabled.length === 0 && (
51+
<div className="flex space-x-4">
52+
<span>
53+
<Link className="gp-link" to="/teams/new">
54+
Create a team
55+
</Link>{" "}
56+
to set up usage-based billing.
57+
</span>
58+
</div>
59+
)}
60+
{teamsWithBillingEnabled && teamsWithBillingEnabled.length > 0 && (
61+
<div className="flex space-x-4">
62+
<span>Bill all my usage to:</span>
63+
<DropDown
64+
customClasses="w-32"
65+
renderAsLink={true}
66+
entries={[
67+
{
68+
title: "(none)",
69+
onClick: () => {},
70+
},
71+
].concat(
72+
teamsWithBillingEnabled.map((t) => ({
73+
title: t.name,
74+
onClick: () => {},
75+
})),
76+
)}
77+
/>
78+
</div>
79+
)}
80+
</div>
3181
</PageWithSubMenu>
3282
);
3383
}

0 commit comments

Comments
 (0)