Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/teams/OrgSettingsPage.tsx
2501 views
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
import { BillingMode } from "@gitpod/gitpod-protocol/lib/billing-mode";
8
import { useMemo } from "react";
9
import { Redirect } from "react-router";
10
import Header from "../components/Header";
11
import { SpinnerLoader } from "../components/Loader";
12
import { PageWithSubMenu } from "../components/PageWithSubMenu";
13
import { useOrgBillingMode } from "../data/billing-mode/org-billing-mode-query";
14
import { useCurrentOrg } from "../data/organizations/orgs-query";
15
import { useFeatureFlag } from "../data/featureflag-query";
16
import { Organization } from "@gitpod/public-api/lib/gitpod/v1/organization_pb";
17
import { useIsOwner } from "../data/organizations/members-query";
18
import { useInstallationConfiguration } from "../data/installation/installation-config-query";
19
20
export interface OrgSettingsPageProps {
21
children: React.ReactNode;
22
}
23
24
export function OrgSettingsPage({ children }: OrgSettingsPageProps) {
25
const org = useCurrentOrg();
26
const isOwner = useIsOwner();
27
const orgBillingMode = useOrgBillingMode();
28
const oidcServiceEnabled = useFeatureFlag("oidcServiceEnabled");
29
const orgGitAuthProviders = useFeatureFlag("orgGitAuthProviders");
30
const isOnboardingEnabled = useFeatureFlag("enterprise_onboarding_enabled");
31
const { data: installationConfig } = useInstallationConfiguration();
32
const isDedicatedInstallation = !!installationConfig?.isDedicatedInstallation;
33
34
const menu = useMemo(
35
() =>
36
getOrgSettingsMenu({
37
org: org.data,
38
billingMode: orgBillingMode.data,
39
ssoEnabled: oidcServiceEnabled,
40
orgGitAuthProviders,
41
isOwner,
42
isDedicatedInstallation,
43
showOnboarding: isOnboardingEnabled && isDedicatedInstallation,
44
}),
45
[
46
org.data,
47
orgBillingMode.data,
48
oidcServiceEnabled,
49
orgGitAuthProviders,
50
isOwner,
51
isDedicatedInstallation,
52
isOnboardingEnabled,
53
],
54
);
55
56
const title = "Organization Settings";
57
const subtitle = "Manage your organization's settings.";
58
59
// Render as much of the page as we can in a loading state to avoid content shift
60
if (org.isLoading) {
61
return (
62
<div className="w-full">
63
<Header title={title} subtitle={subtitle} />
64
<div className="w-full">
65
<SpinnerLoader />
66
</div>
67
</div>
68
);
69
}
70
71
// TODO: redirect when current page is not included in menu
72
const onlyForOwner = false;
73
74
// After we've loaded, ensure user is an owner, if not, redirect
75
if (onlyForOwner && !isOwner) {
76
return <Redirect to={"/"} />;
77
}
78
79
return (
80
<PageWithSubMenu subMenu={menu} title={title} subtitle={subtitle}>
81
{children}
82
</PageWithSubMenu>
83
);
84
}
85
86
function getOrgSettingsMenu(params: {
87
org?: Organization;
88
billingMode?: BillingMode;
89
ssoEnabled?: boolean;
90
orgGitAuthProviders: boolean;
91
isOwner?: boolean;
92
showOnboarding?: boolean;
93
isDedicatedInstallation?: boolean;
94
}) {
95
const { billingMode, ssoEnabled, orgGitAuthProviders, isOwner, showOnboarding, isDedicatedInstallation } = params;
96
const result = [
97
{
98
title: "General",
99
link: [`/settings`],
100
},
101
{
102
title: "Policies",
103
link: [`/settings/policy`],
104
},
105
];
106
if (!isDedicatedInstallation) {
107
result.push(
108
{
109
title: "Networking",
110
link: [`/settings/networking`],
111
},
112
{
113
title: "Authentication",
114
link: [`/settings/auth`],
115
},
116
);
117
}
118
if (showOnboarding) {
119
result.push({
120
title: "Onboarding",
121
link: [`/settings/onboarding`],
122
});
123
}
124
if (isOwner && ssoEnabled) {
125
result.push({
126
title: "SSO",
127
link: [`/sso`],
128
});
129
}
130
if (isOwner && orgGitAuthProviders) {
131
result.push({
132
title: "Git Providers",
133
link: [`/settings/git`],
134
});
135
}
136
if (isOwner && billingMode?.mode !== "none") {
137
// The Billing page handles billing mode itself, so: always show it!
138
result.push({
139
title: "Billing",
140
link: ["/billing"],
141
});
142
}
143
return result;
144
}
145
146