Skip to content

Commit a3d9767

Browse files
author
Laurie T. Malau
committed
[usage] More useful notification
1 parent 5cf2cb8 commit a3d9767

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed

components/dashboard/src/AppNotifications.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import { useEffect, useState } from "react";
88
import Alert from "./components/Alert";
9-
import { getGitpodService } from "./service/service";
9+
import { getGitpodService, gitpodHostUrl } from "./service/service";
1010

1111
const KEY_APP_NOTIFICATIONS = "gitpod-app-notifications";
1212

@@ -36,6 +36,7 @@ export function AppNotifications() {
3636
};
3737

3838
const topNotification = notifications[0];
39+
3940
if (topNotification === undefined) {
4041
return null;
4142
}
@@ -45,6 +46,25 @@ export function AppNotifications() {
4546
setNotifications([]);
4647
};
4748

49+
const getManageBilling = () => {
50+
let href;
51+
if (notifications.length === 1) {
52+
href = `${gitpodHostUrl}billing`;
53+
} else if (notifications.length === 2) {
54+
href = `${gitpodHostUrl}t/${notifications[notifications.length - 1]}/billing`;
55+
}
56+
return (
57+
<span>
58+
{" "}
59+
Manage
60+
<a className="gp-link hover:text-gray-600" href={href}>
61+
{" "}
62+
billing.
63+
</a>
64+
</span>
65+
);
66+
};
67+
4868
return (
4969
<div className="app-container pt-2">
5070
<Alert
@@ -55,6 +75,7 @@ export function AppNotifications() {
5575
className="flex rounded mb-2 w-full"
5676
>
5777
<span>{topNotification}</span>
78+
{getManageBilling()}
5879
</Alert>
5980
</div>
6081
);

components/server/ee/src/workspace/gitpod-server-impl.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2254,10 +2254,31 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
22542254
const billingMode = await this.billingModes.getBillingModeForUser(user, new Date());
22552255
if (billingMode.mode === "usage-based") {
22562256
const limit = await this.billingService.checkUsageLimitReached(user);
2257-
if (limit.reached) {
2258-
result.unshift("The usage limit is reached.");
2259-
} else if (limit.almostReached) {
2260-
result.unshift("The usage limit is almost reached.");
2257+
let teamOrUser;
2258+
switch (limit.attributionId.kind) {
2259+
case "user": {
2260+
if (limit.reached) {
2261+
result.unshift(`You have reached your usage limit.`);
2262+
} else if (limit.almostReached) {
2263+
result.unshift(`You have reached 80% or more of your usage limit.`);
2264+
}
2265+
break;
2266+
}
2267+
case "team": {
2268+
teamOrUser = await this.teamDB.findTeamById(limit.attributionId.teamId);
2269+
if (teamOrUser) {
2270+
if (limit.reached) {
2271+
result.push(teamOrUser?.slug);
2272+
result.unshift(`Your team '${teamOrUser?.name}' has reached its usage limit.`);
2273+
} else if (limit.almostReached) {
2274+
result.push(teamOrUser?.slug);
2275+
result.unshift(
2276+
`Your team '${teamOrUser?.name}' has reached 80% or more of its usage limit.`,
2277+
);
2278+
}
2279+
}
2280+
break;
2281+
}
22612282
}
22622283
}
22632284
} catch (error) {

0 commit comments

Comments
 (0)