Path: blob/main/components/dashboard/src/teams/OrgSettingsPage.tsx
2501 views
/**1* Copyright (c) 2022 Gitpod GmbH. All rights reserved.2* Licensed under the GNU Affero General Public License (AGPL).3* See License.AGPL.txt in the project root for license information.4*/56import { BillingMode } from "@gitpod/gitpod-protocol/lib/billing-mode";7import { useMemo } from "react";8import { Redirect } from "react-router";9import Header from "../components/Header";10import { SpinnerLoader } from "../components/Loader";11import { PageWithSubMenu } from "../components/PageWithSubMenu";12import { useOrgBillingMode } from "../data/billing-mode/org-billing-mode-query";13import { useCurrentOrg } from "../data/organizations/orgs-query";14import { useFeatureFlag } from "../data/featureflag-query";15import { Organization } from "@gitpod/public-api/lib/gitpod/v1/organization_pb";16import { useIsOwner } from "../data/organizations/members-query";17import { useInstallationConfiguration } from "../data/installation/installation-config-query";1819export interface OrgSettingsPageProps {20children: React.ReactNode;21}2223export function OrgSettingsPage({ children }: OrgSettingsPageProps) {24const org = useCurrentOrg();25const isOwner = useIsOwner();26const orgBillingMode = useOrgBillingMode();27const oidcServiceEnabled = useFeatureFlag("oidcServiceEnabled");28const orgGitAuthProviders = useFeatureFlag("orgGitAuthProviders");29const isOnboardingEnabled = useFeatureFlag("enterprise_onboarding_enabled");30const { data: installationConfig } = useInstallationConfiguration();31const isDedicatedInstallation = !!installationConfig?.isDedicatedInstallation;3233const menu = useMemo(34() =>35getOrgSettingsMenu({36org: org.data,37billingMode: orgBillingMode.data,38ssoEnabled: oidcServiceEnabled,39orgGitAuthProviders,40isOwner,41isDedicatedInstallation,42showOnboarding: isOnboardingEnabled && isDedicatedInstallation,43}),44[45org.data,46orgBillingMode.data,47oidcServiceEnabled,48orgGitAuthProviders,49isOwner,50isDedicatedInstallation,51isOnboardingEnabled,52],53);5455const title = "Organization Settings";56const subtitle = "Manage your organization's settings.";5758// Render as much of the page as we can in a loading state to avoid content shift59if (org.isLoading) {60return (61<div className="w-full">62<Header title={title} subtitle={subtitle} />63<div className="w-full">64<SpinnerLoader />65</div>66</div>67);68}6970// TODO: redirect when current page is not included in menu71const onlyForOwner = false;7273// After we've loaded, ensure user is an owner, if not, redirect74if (onlyForOwner && !isOwner) {75return <Redirect to={"/"} />;76}7778return (79<PageWithSubMenu subMenu={menu} title={title} subtitle={subtitle}>80{children}81</PageWithSubMenu>82);83}8485function getOrgSettingsMenu(params: {86org?: Organization;87billingMode?: BillingMode;88ssoEnabled?: boolean;89orgGitAuthProviders: boolean;90isOwner?: boolean;91showOnboarding?: boolean;92isDedicatedInstallation?: boolean;93}) {94const { billingMode, ssoEnabled, orgGitAuthProviders, isOwner, showOnboarding, isDedicatedInstallation } = params;95const result = [96{97title: "General",98link: [`/settings`],99},100{101title: "Policies",102link: [`/settings/policy`],103},104];105if (!isDedicatedInstallation) {106result.push(107{108title: "Networking",109link: [`/settings/networking`],110},111{112title: "Authentication",113link: [`/settings/auth`],114},115);116}117if (showOnboarding) {118result.push({119title: "Onboarding",120link: [`/settings/onboarding`],121});122}123if (isOwner && ssoEnabled) {124result.push({125title: "SSO",126link: [`/sso`],127});128}129if (isOwner && orgGitAuthProviders) {130result.push({131title: "Git Providers",132link: [`/settings/git`],133});134}135if (isOwner && billingMode?.mode !== "none") {136// The Billing page handles billing mode itself, so: always show it!137result.push({138title: "Billing",139link: ["/billing"],140});141}142return result;143}144145146