import { Controller, useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; import { z } from "zod"; import { UpgradePlanModal } from "@app/components/license/UpgradePlanModal"; import { createNotification } from "@app/components/notifications"; import { Button, FormControl, Input } from "@app/components/v2"; import { useProjectPermission, useSubscription, useWorkspace } from "@app/context"; import { usePopUp } from "@app/hooks"; import { ProjectMembershipRole } from "@app/hooks/api/roles/types"; import { useUpdateWorkspaceAuditLogsRetention } from "@app/hooks/api/workspace/queries"; const formSchema = z.object({ auditLogsRetentionDays: z.coerce.number().min(0) }); type TForm = z.infer; export const AuditLogsRetentionSection = () => { const { mutateAsync: updateAuditLogsRetention } = useUpdateWorkspaceAuditLogsRetention(); const { currentWorkspace } = useWorkspace(); const { membership } = useProjectPermission(); const { subscription } = useSubscription(); const { popUp, handlePopUpOpen, handlePopUpToggle } = usePopUp(["upgradePlan"] as const); const { control, formState: { isSubmitting, isDirty }, handleSubmit } = useForm({ resolver: zodResolver(formSchema), values: { auditLogsRetentionDays: currentWorkspace?.auditLogsRetentionDays ?? subscription?.auditLogsRetentionDays ?? 0 } }); if (!currentWorkspace) return null; const handleAuditLogsRetentionSubmit = async ({ auditLogsRetentionDays }: TForm) => { try { if (!subscription?.auditLogs) { handlePopUpOpen("upgradePlan", { description: "You can only configure audit logs retention if you upgrade your plan." }); return; } if (subscription && auditLogsRetentionDays > subscription?.auditLogsRetentionDays) { handlePopUpOpen("upgradePlan", { description: "To update your audit logs retention period to a higher value, upgrade your plan." }); return; } await updateAuditLogsRetention({ auditLogsRetentionDays, projectSlug: currentWorkspace.slug }); createNotification({ text: "Successfully updated audit logs retention period", type: "success" }); } catch { createNotification({ text: "Failed updating audit logs retention period", type: "error" }); } }; // render only for dedicated/self-hosted instances of Infisical if ( window.location.origin.includes("https://app.infisical.com") || window.location.origin.includes("https://gamma.infisical.com") ) { return null; } const isAdmin = membership.roles.includes(ProjectMembershipRole.Admin); return ( <>

Audit Logs Retention

Set the number of days to keep your project audit logs.

( )} />
handlePopUpToggle("upgradePlan", isOpen)} text={(popUp.upgradePlan?.data as { description: string })?.description} /> ); };