Skip to content

Commit 317f559

Browse files
committed
[dashboard] Add Usage-Based feature flag and empty Billing page
1 parent c025034 commit 317f559

File tree

12 files changed

+76
-25
lines changed

12 files changed

+76
-25
lines changed

components/dashboard/src/Menu.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { getProjectSettingsMenu } from "./projects/ProjectSettings";
2727
import { ProjectContext } from "./projects/project-context";
2828
import { PaymentContext } from "./payment-context";
2929
import FeedbackFormModal from "./feedback-form/FeedbackModal";
30+
import { getExperimentsClient } from "./experiments/client";
3031

3132
interface Entry {
3233
title: string;
@@ -39,8 +40,15 @@ export default function Menu() {
3940
const { teams } = useContext(TeamsContext);
4041
const location = useLocation();
4142
const team = getCurrentTeam(location, teams);
42-
const { showPaymentUI, setShowPaymentUI, setCurrency, setIsStudent, setIsChargebeeCustomer } =
43-
useContext(PaymentContext);
43+
const {
44+
showPaymentUI,
45+
setShowPaymentUI,
46+
showUsageBasedUI,
47+
setShowUsageBasedUI,
48+
setCurrency,
49+
setIsStudent,
50+
setIsChargebeeCustomer,
51+
} = useContext(PaymentContext);
4452
const { project, setProject } = useContext(ProjectContext);
4553
const [isFeedbackFormVisible, setFeedbackFormVisible] = useState<boolean>(false);
4654

@@ -143,6 +151,12 @@ export default function Menu() {
143151
const { server } = getGitpodService();
144152
Promise.all([
145153
server.getShowPaymentUI().then((v) => () => setShowPaymentUI(v)),
154+
getExperimentsClient()
155+
.getValueAsync("isUsageBasedBillingEnabled", false, {
156+
userID: user?.id,
157+
teamName: team?.name,
158+
})
159+
.then((v) => () => setShowUsageBasedUI(v)),
146160
server.getClientRegion().then((v) => () => {
147161
// @ts-ignore
148162
setCurrency(countries[v]?.currency === "EUR" ? "EUR" : "USD");
@@ -211,7 +225,7 @@ export default function Menu() {
211225
{
212226
title: "Settings",
213227
link: "/settings",
214-
alternatives: getSettingsMenu({ showPaymentUI }).flatMap((e) => e.link),
228+
alternatives: getSettingsMenu({ showPaymentUI, showUsageBasedUI }).flatMap((e) => e.link),
215229
},
216230
];
217231
})();

components/dashboard/src/payment-context.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { Currency } from "@gitpod/gitpod-protocol/lib/plans";
1010
const PaymentContext = createContext<{
1111
showPaymentUI?: boolean;
1212
setShowPaymentUI: React.Dispatch<boolean>;
13+
showUsageBasedUI?: boolean;
14+
setShowUsageBasedUI: React.Dispatch<boolean>;
1315
currency: Currency;
1416
setCurrency: React.Dispatch<Currency>;
1517
isStudent?: boolean;
@@ -18,6 +20,7 @@ const PaymentContext = createContext<{
1820
setIsChargebeeCustomer: React.Dispatch<boolean>;
1921
}>({
2022
setShowPaymentUI: () => null,
23+
setShowUsageBasedUI: () => null,
2124
currency: "USD",
2225
setCurrency: () => null,
2326
setIsStudent: () => null,
@@ -26,6 +29,7 @@ const PaymentContext = createContext<{
2629

2730
const PaymentContextProvider: React.FC = ({ children }) => {
2831
const [showPaymentUI, setShowPaymentUI] = useState<boolean>();
32+
const [showUsageBasedUI, setShowUsageBasedUI] = useState<boolean>();
2933
const [currency, setCurrency] = useState<Currency>("USD");
3034
const [isStudent, setIsStudent] = useState<boolean>();
3135
const [isChargebeeCustomer, setIsChargebeeCustomer] = useState<boolean>();
@@ -35,6 +39,8 @@ const PaymentContextProvider: React.FC = ({ children }) => {
3539
value={{
3640
showPaymentUI,
3741
setShowPaymentUI,
42+
showUsageBasedUI,
43+
setShowUsageBasedUI,
3844
currency,
3945
setCurrency,
4046
isStudent,

components/dashboard/src/settings/Account.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { PaymentContext } from "../payment-context";
1616

1717
export default function Account() {
1818
const { user } = useContext(UserContext);
19-
const { showPaymentUI } = useContext(PaymentContext);
19+
const { showPaymentUI, showUsageBasedUI } = useContext(PaymentContext);
2020

2121
const [modal, setModal] = useState(false);
2222
const [typedEmail, setTypedEmail] = useState("");
@@ -56,7 +56,7 @@ export default function Account() {
5656
</ConfirmationModal>
5757

5858
<PageWithSubMenu
59-
subMenu={getSettingsMenu({ showPaymentUI })}
59+
subMenu={getSettingsMenu({ showPaymentUI, showUsageBasedUI })}
6060
title="Account"
6161
subtitle="Manage account and Git configuration."
6262
>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
3+
* Licensed under the GNU Affero General Public License (AGPL).
4+
* See License-AGPL.txt in the project root for license information.
5+
*/
6+
7+
export default function Billing() {
8+
return <div></div>;
9+
}

components/dashboard/src/settings/EnvironmentVariables.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ function sortEnvVars(a: UserEnvVarValue, b: UserEnvVarValue) {
145145
}
146146

147147
export default function EnvVars() {
148-
const { showPaymentUI } = useContext(PaymentContext);
148+
const { showPaymentUI, showUsageBasedUI } = useContext(PaymentContext);
149149
const [envVars, setEnvVars] = useState([] as UserEnvVarValue[]);
150150
const [currentEnvVar, setCurrentEnvVar] = useState({
151151
name: "",
@@ -207,7 +207,7 @@ export default function EnvVars() {
207207

208208
return (
209209
<PageWithSubMenu
210-
subMenu={getSettingsMenu({ showPaymentUI })}
210+
subMenu={getSettingsMenu({ showPaymentUI, showUsageBasedUI })}
211211
title="Variables"
212212
subtitle="Configure environment variables for all workspaces."
213213
>

components/dashboard/src/settings/Integrations.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ import { SelectAccountModal } from "./SelectAccountModal";
2626
import getSettingsMenu from "./settings-menu";
2727

2828
export default function Integrations() {
29-
const { showPaymentUI } = useContext(PaymentContext);
29+
const { showPaymentUI, showUsageBasedUI } = useContext(PaymentContext);
3030

3131
return (
3232
<div>
3333
<PageWithSubMenu
34-
subMenu={getSettingsMenu({ showPaymentUI })}
34+
subMenu={getSettingsMenu({ showPaymentUI, showUsageBasedUI })}
3535
title="Integrations"
3636
subtitle="Manage permissions for Git providers and integrations."
3737
>

components/dashboard/src/settings/Notifications.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { PaymentContext } from "../payment-context";
1515

1616
export default function Notifications() {
1717
const { user, setUser } = useContext(UserContext);
18-
const { showPaymentUI } = useContext(PaymentContext);
18+
const { showPaymentUI, showUsageBasedUI } = useContext(PaymentContext);
1919
const [isOnboardingMail, setOnboardingMail] = useState(
2020
!!user?.additionalData?.emailNotificationSettings?.allowsOnboardingMail,
2121
);
@@ -84,7 +84,7 @@ export default function Notifications() {
8484
return (
8585
<div>
8686
<PageWithSubMenu
87-
subMenu={getSettingsMenu({ showPaymentUI })}
87+
subMenu={getSettingsMenu({ showPaymentUI, showUsageBasedUI })}
8888
title="Notifications"
8989
subtitle="Choose when to be notified."
9090
>

components/dashboard/src/settings/Plans.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ type TeamClaimModal =
4545

4646
export default function () {
4747
const { user } = useContext(UserContext);
48-
const { showPaymentUI, currency, setCurrency, isStudent, isChargebeeCustomer } = useContext(PaymentContext);
48+
const { showPaymentUI, showUsageBasedUI, currency, setCurrency, isStudent, isChargebeeCustomer } =
49+
useContext(PaymentContext);
4950
const [accountStatement, setAccountStatement] = useState<AccountStatement>();
5051
const [availableCoupons, setAvailableCoupons] = useState<PlanCoupon[]>();
5152
const [appliedCoupons, setAppliedCoupons] = useState<PlanCoupon[]>();
@@ -636,7 +637,7 @@ export default function () {
636637
return (
637638
<div>
638639
<PageWithSubMenu
639-
subMenu={getSettingsMenu({ showPaymentUI })}
640+
subMenu={getSettingsMenu({ showPaymentUI, showUsageBasedUI })}
640641
title="Plans"
641642
subtitle="Manage account usage and billing."
642643
>

components/dashboard/src/settings/Preferences.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type Theme = "light" | "dark" | "system";
2020

2121
export default function Preferences() {
2222
const { user } = useContext(UserContext);
23-
const { showPaymentUI } = useContext(PaymentContext);
23+
const { showPaymentUI, showUsageBasedUI } = useContext(PaymentContext);
2424
const { setIsDark } = useContext(ThemeContext);
2525

2626
const [theme, setTheme] = useState<Theme>(localStorage.theme || "system");
@@ -54,7 +54,7 @@ export default function Preferences() {
5454
return (
5555
<div>
5656
<PageWithSubMenu
57-
subMenu={getSettingsMenu({ showPaymentUI })}
57+
subMenu={getSettingsMenu({ showPaymentUI, showUsageBasedUI })}
5858
title="Preferences"
5959
subtitle="Configure user preferences."
6060
>

components/dashboard/src/settings/Teams.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ import { Disposable } from "@gitpod/gitpod-protocol";
2626
import { PaymentContext } from "../payment-context";
2727

2828
export default function Teams() {
29-
const { showPaymentUI } = useContext(PaymentContext);
29+
const { showPaymentUI, showUsageBasedUI } = useContext(PaymentContext);
3030

3131
return (
3232
<div>
3333
<PageWithSubMenu
34-
subMenu={getSettingsMenu({ showPaymentUI })}
34+
subMenu={getSettingsMenu({ showPaymentUI, showUsageBasedUI })}
3535
title="Team Plans"
3636
subtitle="View and manage subscriptions for your team with one centralized billing."
3737
>

components/dashboard/src/settings/settings-menu.ts

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

7-
export default function getSettingsMenu(params: { showPaymentUI?: boolean }) {
7+
import {
8+
settingsPathAccount,
9+
settingsPathBilling,
10+
settingsPathIntegrations,
11+
settingsPathMain,
12+
settingsPathNotifications,
13+
settingsPathPlans,
14+
settingsPathPreferences,
15+
settingsPathTeams,
16+
settingsPathVariables,
17+
} from "./settings.routes";
18+
19+
export default function getSettingsMenu(params: { showPaymentUI?: boolean; showUsageBasedUI?: boolean }) {
820
return [
921
{
1022
title: "Account",
11-
link: ["/account", "/settings"],
23+
link: [settingsPathAccount, settingsPathMain],
1224
},
1325
{
1426
title: "Notifications",
15-
link: ["/notifications"],
27+
link: [settingsPathNotifications],
1628
},
1729
...(params.showPaymentUI
1830
? [
31+
...(params.showUsageBasedUI
32+
? [
33+
{
34+
title: "Billing",
35+
link: [settingsPathBilling],
36+
},
37+
]
38+
: []),
1939
{
2040
title: "Plans",
21-
link: ["/plans"],
41+
link: [settingsPathPlans],
2242
},
2343
{
2444
title: "Team Plans",
25-
link: ["/teams"],
45+
link: [settingsPathTeams],
2646
},
2747
]
2848
: []),
2949
{
3050
title: "Variables",
31-
link: ["/variables"],
51+
link: [settingsPathVariables],
3252
},
3353
{
3454
title: "Integrations",
35-
link: ["/integrations", "/access-control"],
55+
link: [settingsPathIntegrations, "/access-control"],
3656
},
3757
{
3858
title: "Preferences",
39-
link: ["/preferences"],
59+
link: [settingsPathPreferences],
4060
},
4161
];
4262
}

components/dashboard/src/settings/settings.routes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const settingsPathMain = "/settings";
99
export const settingsPathAccount = "/account";
1010
export const settingsPathIntegrations = "/integrations";
1111
export const settingsPathNotifications = "/notifications";
12+
export const settingsPathBilling = "/billing";
1213
export const settingsPathPlans = "/plans";
1314
export const settingsPathPreferences = "/preferences";
1415

0 commit comments

Comments
 (0)