Skip to content

Polish handling of BillingMode #12130

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 7 commits into from
Aug 17, 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
8 changes: 5 additions & 3 deletions components/dashboard/src/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,6 @@ export default function Menu() {
server.isStudent().then((v) => () => setIsStudent(v)),
server.isChargebeeCustomer().then((v) => () => setIsChargebeeCustomer(v)),
]).then((setters) => setters.forEach((s) => s()));

// Refresh billing mode
refreshUserBillingMode();
}, []);

useEffect(() => {
Expand All @@ -163,6 +160,11 @@ export default function Menu() {
}
}, [team]);

useEffect(() => {
// Refresh billing mode
refreshUserBillingMode();
}, [teams]);

const teamOrUserSlug = !!team ? "/t/" + team.slug : "/projects";
const leftMenu: Entry[] = (() => {
// Project menu
Expand Down
7 changes: 5 additions & 2 deletions components/dashboard/src/settings/Preferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import SelectIDE from "./SelectIDE";
import SelectWorkspaceClass from "./selectClass";
import { PageWithSettingsSubMenu } from "./PageWithSettingsSubMenu";
import { FeatureFlagContext } from "../contexts/FeatureFlagContext";
import { BillingMode } from "@gitpod/gitpod-protocol/lib/billing-mode";

type Theme = "light" | "dark" | "system";

export default function Preferences() {
const { user } = useContext(UserContext);
const { user, userBillingMode } = useContext(UserContext);
const { setIsDark } = useContext(ThemeContext);
const { showWorkspaceClassesUI } = useContext(FeatureFlagContext);

Expand Down Expand Up @@ -56,7 +57,9 @@ export default function Preferences() {
<h3>Editor</h3>
<p className="text-base text-gray-500 dark:text-gray-400">Choose the editor for opening workspaces.</p>
<SelectIDE location="preferences" />
<SelectWorkspaceClass enabled={showWorkspaceClassesUI} />
<SelectWorkspaceClass
enabled={showWorkspaceClassesUI || BillingMode.canSetWorkspaceClass(userBillingMode)}
/>
<h3 className="mt-12">Theme</h3>
<p className="text-base text-gray-500 dark:text-gray-400">Early bird or night owl? Choose your side.</p>
<div className="mt-4 space-x-3 flex">
Expand Down
307 changes: 162 additions & 145 deletions components/dashboard/src/teams/TeamBilling.tsx

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion components/gitpod-protocol/src/billing-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ export namespace BillingMode {
);
}

export function canSetWorkspaceClass(billingMode: BillingMode): boolean {
export function canSetWorkspaceClass(billingMode?: BillingMode): boolean {
if (!billingMode) {
return false;
}

// if has any Stripe subscription, either directly or per team
return billingMode.mode === "usage-based";
}
Expand All @@ -52,6 +56,9 @@ interface Chargebee {
interface UsageBased {
mode: "usage-based";

/** True iff this is a team, and is based on a paid plan. Currently only set for teams! */
paid?: boolean;

/** User is already converted, but is member with at least one Chargebee-based "Team Plan" */
hasChargebeeTeamPlan?: boolean;

Expand Down
Loading