Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

4.6 KB
Raw Blame
import { Link, useSearch } from "@tanstack/react-router";
import { InfoIcon } from "lucide-react";

import { PageTitle } from "@app/components/PageTitle";
import {
  AlertDescription,
  AlertTitle,
  DismissableAlert,
  LookingForOrgPageLink,
  PageHeader
} from "@app/components/v3";
import { ROUTE_PATHS } from "@app/const/routes";
import { useOrganization, useSubscription } from "@app/context";

import { OrgEncryptionTab } from "../OrgEncryptionTab";
import { OrgGeneralTab } from "../OrgGeneralTab";
import { OrgProductSettingsTab } from "../OrgProductSettingsTab";
import { OrgSecurityTab } from "../OrgSecurityTab";
import { OrgSubOrgsTab } from "../OrgSubOrgsTab";

export const OrgTabGroup = () => {
  const search = useSearch({
    from: ROUTE_PATHS.Organization.SettingsPage.id
  });
  const { currentOrg, isSubOrganization } = useOrganization();
  const { subscription } = useSubscription();

  const tabs = [
    {
      name: "General",
      key: "tab-org-general",
      component: OrgGeneralTab,
      description: isSubOrganization
        ? "Update your sub-organization's name and other general settings."
        : "Update your organization's name, incident contacts, and other general settings."
    },
    {
      name: "Security",
      key: "tab-org-security",
      component: OrgSecurityTab,
      description:
        "Configure authentication requirements and access token limits for your organization.",
      isHidden: isSubOrganization
    },
    {
      name: "Encryption",
      key: "tab-org-encryption",
      component: OrgEncryptionTab,
      description: `Configure the key management systems (KMS) used to encrypt your ${
        isSubOrganization ? "sub-" : ""
      }organization's data.`
    },
    {
      name: "Product Settings",
      key: "product-settings",
      component: OrgProductSettingsTab,
      description: `Configure product-specific defaults and features across your ${
        isSubOrganization ? "sub-" : ""
      }organization.`
    },
    {
      name: "Sub Organizations",
      key: "tab-sub-organizations",
      component: OrgSubOrgsTab,
      description: "Create and manage sub-organizations to isolate teams, environments, and data.",
      isHidden: isSubOrganization,
      requiresFeature: !subscription?.subOrganization
    }
  ];

  const visibleTabs = tabs.filter((el) => !el.isHidden);
  const defaultTab = visibleTabs.find((item) => !item.requiresFeature)?.key ?? visibleTabs[0].key;
  const selectedTab = search.selectedTab
    ? (visibleTabs.find((item) => item.key === search.selectedTab && !item.requiresFeature)?.key ??
      defaultTab)
    : defaultTab;
  const activeTab = visibleTabs.find((item) => item.key === selectedTab);
  const ActiveTabComponent = activeTab?.component;
  const selectedTabName = activeTab?.name;
  const settingsTitle = `${isSubOrganization ? "Sub-Organization" : "Organization"} Settings`;
  const pageTitle = selectedTabName ? `${selectedTabName} - ${settingsTitle}` : settingsTitle;

  return (
    <div className="flex w-full flex-col">
      <PageTitle title={pageTitle} />
      <PageHeader
        scope={isSubOrganization ? "namespace" : "org"}
        description={
          activeTab?.description ??
          `Configure ${isSubOrganization ? "sub-" : ""}organization-wide settings`
        }
        title={selectedTabName ?? settingsTitle}
      >
        <LookingForOrgPageLink page="settings" target="root" />
      </PageHeader>
      <div className="flex flex-col gap-6">
        {selectedTab === "tab-org-general" && (
          <DismissableAlert variant="info" actionKey="org_general_settings_moved_banner_dismissed">
            <InfoIcon />
            <AlertTitle>Some Settings Have Moved</AlertTitle>
            <AlertDescription>
              <p>
                Audit log streams now live under{" "}
                <Link
                  to="/organizations/$orgId/audit-logs"
                  params={{ orgId: currentOrg.id }}
                  search={{ selectedTab: "streams" }}
                  className="underline hover:opacity-80"
                >
                  Audit Logs
                </Link>
                , and workflow integrations, OAuth applications, and external migrations have moved
                to{" "}
                <Link
                  to="/organizations/$orgId/integrations"
                  params={{ orgId: currentOrg.id }}
                  className="underline hover:opacity-80"
                >
                  Integrations
                </Link>
                .
              </p>
            </AlertDescription>
          </DismissableAlert>
        )}
        {ActiveTabComponent && <ActiveTabComponent />}
      </div>
    </div>
  );
};