Skip to content

[usage] More useful notification #13406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion components/dashboard/src/AppNotifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { useEffect, useState } from "react";
import Alert from "./components/Alert";
import { getGitpodService } from "./service/service";
import { getGitpodService, gitpodHostUrl } from "./service/service";

const KEY_APP_NOTIFICATIONS = "gitpod-app-notifications";

Expand Down Expand Up @@ -36,6 +36,7 @@ export function AppNotifications() {
};

const topNotification = notifications[0];

if (topNotification === undefined) {
return null;
}
Expand All @@ -45,6 +46,25 @@ export function AppNotifications() {
setNotifications([]);
};

const getManageBilling = () => {
let href;
if (notifications.length === 1) {
href = `${gitpodHostUrl}billing`;
} else if (notifications.length === 2) {
href = `${gitpodHostUrl}t/${notifications[notifications.length - 1]}/billing`;
}
return (
<span>
{" "}
Manage
<a className="gp-link hover:text-gray-600" href={href}>
{" "}
billing.
</a>
</span>
);
};

return (
<div className="app-container pt-2">
<Alert
Expand All @@ -55,6 +75,7 @@ export function AppNotifications() {
className="flex rounded mb-2 w-full"
>
<span>{topNotification}</span>
{getManageBilling()}
</Alert>
</div>
);
Expand Down
29 changes: 25 additions & 4 deletions components/server/ee/src/workspace/gitpod-server-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2256,10 +2256,31 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
const billingMode = await this.billingModes.getBillingModeForUser(user, new Date());
if (billingMode.mode === "usage-based") {
const limit = await this.billingService.checkUsageLimitReached(user);
if (limit.reached) {
result.unshift("The usage limit is reached.");
} else if (limit.almostReached) {
result.unshift("The usage limit is almost reached.");
let teamOrUser;
switch (limit.attributionId.kind) {
case "user": {
if (limit.reached) {
result.unshift(`You have reached your usage limit.`);
} else if (limit.almostReached) {
result.unshift(`You have reached 80% or more of your usage limit.`);
}
break;
}
case "team": {
teamOrUser = await this.teamDB.findTeamById(limit.attributionId.teamId);
if (teamOrUser) {
if (limit.reached) {
result.push(teamOrUser?.slug);
result.unshift(`Your team '${teamOrUser?.name}' has reached its usage limit.`);
} else if (limit.almostReached) {
result.push(teamOrUser?.slug);
result.unshift(
`Your team '${teamOrUser?.name}' has reached 80% or more of its usage limit.`,
);
}
}
break;
}
}
}
} catch (error) {
Expand Down