import { useEffect, useState } from "react"; import { faArrowUpRightFromSquare, faBookOpen } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import ms from "ms"; import { UpgradePlanModal } from "@app/components/license/UpgradePlanModal"; import { OrgPermissionAuditLogsActions, OrgPermissionSubjects, ProjectPermissionAuditLogsActions, ProjectPermissionSub, useSubscription } from "@app/context"; import { Timezone } from "@app/helpers/datetime"; import { withPermission, withProjectPermission } from "@app/hoc"; import { Project } from "@app/hooks/api/projects/types"; import { usePopUp } from "@app/hooks/usePopUp"; import { LogsDateFilter } from "./LogsDateFilter"; import { LogsFilter } from "./LogsFilter"; import { LogsTable } from "./LogsTable"; import { AuditLogDateFilterType, Presets, TAuditLogDateFilterFormData, TAuditLogFilterFormData } from "./types"; type Props = { presets?: Presets; refetchInterval?: number; showFilters?: boolean; pageView?: boolean; project?: Project; }; const LogsSectionComponent = ({ presets, refetchInterval, showFilters = true, pageView = false, project }: Props) => { const { subscription } = useSubscription(); const { popUp, handlePopUpOpen, handlePopUpToggle } = usePopUp(["upgradePlan"] as const); const [logFilter, setLogFilter] = useState({ eventType: presets?.eventType || [], actor: presets?.actorId, eventMetadata: presets?.eventMetadata }); const [timezone, setTimezone] = useState(Timezone.Local); const [dateFilter, setDateFilter] = useState( presets?.endDate || presets?.startDate ? { type: AuditLogDateFilterType.Absolute, startDate: presets?.startDate || new Date(Number(new Date()) - ms("1h")), endDate: presets?.endDate || new Date() } : { startDate: new Date(Number(new Date()) - ms("1h")), endDate: new Date(), type: AuditLogDateFilterType.Relative, relativeModeValue: "1h" } ); useEffect(() => { if (subscription && !subscription.auditLogs) { handlePopUpOpen("upgradePlan"); } }, [subscription]); if (pageView) return (

Audit History

Docs
{showFilters && ( )} {showFilters && ( )}
{ handlePopUpToggle("upgradePlan", isOpen); }} text="You can use audit logs if you switch to a paid Infisical plan." />
); return (
{showFilters && ( )} {showFilters && ( )}
{ handlePopUpToggle("upgradePlan", isOpen); }} text="You can use audit logs if you switch to a paid Infisical plan." />
); }; export const LogsSection = (props: Props) => { const { project } = props; if (project) { const ProjectLogsSectionWithPermission = withProjectPermission(LogsSectionComponent, { action: ProjectPermissionAuditLogsActions.Read, subject: ProjectPermissionSub.AuditLogs }); return ; } const OrgLogsSectionWithPermission = withPermission(LogsSectionComponent, { action: OrgPermissionAuditLogsActions.Read, subject: OrgPermissionSubjects.AuditLogs }); return ; };