Skip to content

Commit 99dfe13

Browse files
committed
Spending Limit Reached modal 🛹
1 parent d06ac79 commit 99dfe13

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

components/dashboard/src/start/CreateWorkspace.tsx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
RunningWorkspacePrebuildStarting,
1212
ContextURL,
1313
DisposableCollection,
14+
Team,
1415
} from "@gitpod/gitpod-protocol";
1516
import { ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error";
1617
import Modal from "../components/Modal";
@@ -25,6 +26,8 @@ import PrebuildLogs from "../components/PrebuildLogs";
2526
import CodeText from "../components/CodeText";
2627
import FeedbackComponent from "../feedback-form/FeedbackComponent";
2728
import { isGitpodIo } from "../utils";
29+
import { AttributionId } from "@gitpod/gitpod-protocol/lib/attribution";
30+
import { TeamsContext } from "../teams/teams-context";
2831

2932
export interface CreateWorkspaceProps {
3033
contextUrl: string;
@@ -185,6 +188,11 @@ export default class CreateWorkspace extends React.Component<CreateWorkspaceProp
185188
phase = StartPhase.Stopped;
186189
statusMessage = <LimitReachedOutOfHours />;
187190
break;
191+
case ErrorCodes.PAYMENT_OUT_OF_CREDITS:
192+
error = undefined; // to hide the error (otherwise rendered behind the modal)
193+
phase = StartPhase.Stopped;
194+
statusMessage = <SpendingLimitReachedModal hints={this.state?.error?.data} />;
195+
break;
188196
default:
189197
statusMessage = (
190198
<p className="text-base text-gitpod-red w-96">
@@ -335,6 +343,44 @@ function LimitReachedOutOfHours() {
335343
</LimitReachedModal>
336344
);
337345
}
346+
function SpendingLimitReachedModal(p: { hints: any }) {
347+
const { teams } = useContext(TeamsContext);
348+
// const [attributionId, setAttributionId] = useState<AttributionId | undefined>();
349+
const [attributedTeam, setAttributedTeam] = useState<Team | undefined>();
350+
351+
useEffect(() => {
352+
const attributionId: AttributionId | undefined =
353+
p.hints && p.hints.attributionId && AttributionId.parse(p.hints.attributionId);
354+
if (attributionId) {
355+
// setAttributionId(attributionId);
356+
if (attributionId.kind === "team") {
357+
const team = teams?.find((t) => t.id === attributionId.teamId);
358+
setAttributedTeam(team);
359+
}
360+
}
361+
}, []);
362+
363+
return (
364+
<Modal visible={true} closeable={false} onClose={() => {}}>
365+
<h3 className="flex">
366+
<span className="flex-grow">Spending Limit Reached</span>
367+
</h3>
368+
<div className="border-t border-b border-gray-200 dark:border-gray-800 mt-4 -mx-6 px-6 py-2">
369+
<p className="mt-1 mb-2 text-base dark:text-gray-400">Please increase the spending limit and retry.</p>
370+
</div>
371+
<div className="flex justify-end mt-6 space-x-2">
372+
<a href={gitpodHostUrl.with({ pathname: "billing" }).toString()}>
373+
<button>Billing Settings</button>
374+
</a>
375+
{attributedTeam && (
376+
<a href={gitpodHostUrl.with({ pathname: `t/${attributedTeam?.slug}/billing` }).toString()}>
377+
<button>Team Billing</button>
378+
</a>
379+
)}
380+
</div>
381+
</Modal>
382+
);
383+
}
338384

339385
function RepositoryNotFoundView(p: { error: StartWorkspaceError }) {
340386
const [statusMessage, setStatusMessage] = useState<React.ReactNode>();

components/dashboard/src/start/StartWorkspace.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ export default class StartWorkspace extends React.Component<StartWorkspaceProps,
528528
try {
529529
const desktopLink = new URL(openLink);
530530
redirect =
531-
desktopLink.protocol != "http:" && desktopLink.protocol != "https:";
531+
desktopLink.protocol !== "http:" && desktopLink.protocol !== "https:";
532532
} catch {}
533533
if (redirect) {
534534
window.location.href = openLink;

0 commit comments

Comments
 (0)