Skip to content

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

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

import { PageTitle } from "@app/components/PageTitle";
import {
  AlertDescription,
  DismissableAlert,
  PageHeader,
  Tabs,
  TabsContent,
  TabsList,
  TabsTrigger
} from "@app/components/v3";
import { ROUTE_PATHS } from "@app/const/routes";
import { useOrganization } from "@app/context";
import {
  OrgPermissionAppConnectionActions,
  OrgPermissionSubjects
} from "@app/context/OrgPermissionContext/types";
import { withPermission } from "@app/hoc";
import { AppConnectionsTable } from "@app/pages/organization/AppConnections/AppConnectionsPage/components";
import { ExternalMigrationsTab } from "@app/pages/organization/SettingsPage/components/ExternalMigrationsTab";
import { OrgWorkflowIntegrationTab } from "@app/pages/organization/SettingsPage/components/OrgWorkflowIntegrationTab";
import { IntegrationsListPageTabs } from "@app/types/integrations";

const AppConnectionsTab = withPermission(
  () => (
    <>
      <DismissableAlert
        variant="info"
        className="mb-4"
        actionKey="app_connections_project_scope_banner_dismissed"
      >
        <InfoIcon />
        <AlertDescription>
          App connections can also be created and managed independently in projects now.
        </AlertDescription>
      </DismissableAlert>
      <AppConnectionsTable />
    </>
  ),
  {
    action: OrgPermissionAppConnectionActions.Read,
    subject: OrgPermissionSubjects.AppConnections,
    accessRestrictedMode: "dialog"
  }
);

export const IntegrationsPage = () => {
  const navigate = useNavigate();
  const { currentOrg, isSubOrganization } = useOrganization();
  const selectedTab = useSearch({
    from: ROUTE_PATHS.Organization.IntegrationsPage.id,
    select: (el) => el.selectedTab,
    structuralSharing: true
  });

  const tabs = [
    {
      key: IntegrationsListPageTabs.AppConnections as string,
      label: "App Connections",
      component: AppConnectionsTab
    },
    {
      key: "workflow-integrations",
      label: "Workflow Integrations",
      component: OrgWorkflowIntegrationTab
    },
    {
      key: "external-migrations",
      label: "External Migrations",
      component: ExternalMigrationsTab
    }
  ];

  const activeTab = tabs.some((tab) => tab.key === selectedTab)
    ? selectedTab
    : IntegrationsListPageTabs.AppConnections;

  const updateSelectedTab = (tab: string) => {
    navigate({
      to: "/organizations/$orgId/integrations",
      params: { orgId: currentOrg.id },
      search: { selectedTab: tab }
    });
  };

  return (
    <>
      <PageTitle title="Integrations" />
      <link rel="icon" href="/infisical.ico" />
      <meta property="og:image" content="/images/message.png" />
      <div className="flex w-full justify-center bg-page text-foreground-inverse">
        <div className="flex w-full max-w-8xl flex-col">
          <PageHeader
            scope={isSubOrganization ? "namespace" : "org"}
            title="Integrations"
            description="Connect Infisical to external services and manage organization-wide integrations."
          />
          <Tabs value={activeTab} onValueChange={updateSelectedTab}>
            <TabsList
              variant={isSubOrganization ? "sub-org" : "org"}
              aria-label={
                isSubOrganization
                  ? "Sub-organization integrations sections"
                  : "Organization integrations sections"
              }
            >
              {tabs.map(({ key, label }) => (
                <TabsTrigger value={key} key={`tab-${key}`}>
                  {label}
                </TabsTrigger>
              ))}
            </TabsList>
            {tabs.map(({ key, component: Component }) => (
              <TabsContent value={key} key={`tab-panel-${key}`}>
                <Component />
              </TabsContent>
            ))}
          </Tabs>
        </div>
      </div>
    </>
  );
};