Skip to content

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

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

import { PageTitle } from "@app/components/PageTitle";
import {
  LookingForOrgPageLink,
  Tabs,
  TabsContent,
  TabsList,
  TabsTrigger
} from "@app/components/v3";
import { PageHeader } from "@app/components/v3/platform";
import { ROUTE_PATHS } from "@app/const/routes";
import { useOrganization } from "@app/context";

import { LogsSection } from "./components";
import { AuditLogSettingsTab } from "./components/AuditLogSettingsTab";
import { AuditLogStreamsTab } from "./components/AuditLogStreamTab";

enum AuditLogsPageTabs {
  AuditLogs = "audit-logs",
  Streams = "streams",
  Settings = "settings"
}

const AuditLogsTab = () => <LogsSection pageView />;

export const AuditLogsPage = () => {
  const navigate = useNavigate();
  const { isSubOrganization, currentOrg } = useOrganization();
  const { selectedTab } = useSearch({
    from: ROUTE_PATHS.Organization.AuditLogsPage.id
  });

  const tabs = [
    { key: AuditLogsPageTabs.AuditLogs, label: "Audit Logs", component: AuditLogsTab },
    {
      key: AuditLogsPageTabs.Streams,
      label: "External Log Streams",
      component: AuditLogStreamsTab
    },
    { key: AuditLogsPageTabs.Settings, label: "Settings", component: AuditLogSettingsTab }
  ];

  const activeTab = tabs.some((tab) => tab.key === selectedTab)
    ? selectedTab
    : AuditLogsPageTabs.AuditLogs;

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

  return (
    <div className="bg-page">
      <PageTitle title="Audit Logs" />
      <link rel="icon" href="/infisical.ico" />
      <meta property="og:image" content="/images/message.png" />
      <div className="flex w-full justify-center bg-page pb-6 text-foreground-inverse">
        <div className="w-full max-w-8xl">
          <PageHeader
            scope={isSubOrganization ? "namespace" : "org"}
            title={`${isSubOrganization ? "Sub-Organization" : "Organization"} Audit Logs`}
            description="Audit logs for security and compliance teams to monitor information access."
          >
            <LookingForOrgPageLink page="auditLogs" target="root" />
          </PageHeader>
          <Tabs value={activeTab} onValueChange={updateSelectedTab}>
            <TabsList variant={isSubOrganization ? "sub-org" : "org"}>
              {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>
    </div>
  );
};