"use client"; import React, { useMemo, useState } from "react"; import { observer } from "mobx-react"; import { useParams } from "next/navigation"; import { ArchiveRestore } from "lucide-react"; // types import { PROJECT_AUTOMATION_MONTHS, EUserPermissions, EUserPermissionsLevel, PROJECT_SETTINGS_TRACKER_ELEMENTS, PROJECT_SETTINGS_TRACKER_EVENTS, } from "@plane/constants"; import { useTranslation } from "@plane/i18n"; import type { IProject } from "@plane/types"; // ui import { CustomSelect, Loader, ToggleSwitch } from "@plane/ui"; // component import { SelectMonthModal } from "@/components/automation"; // constants // hooks import { captureElementAndEvent } from "@/helpers/event-tracker.helper"; import { useProject } from "@/hooks/store/use-project"; import { useUserPermissions } from "@/hooks/store/user"; type Props = { handleChange: (formData: Partial) => Promise; }; const initialValues: Partial = { archive_in: 1 }; export const AutoArchiveAutomation: React.FC = observer((props) => { const { handleChange } = props; // router const { workspaceSlug } = useParams(); // states const [monthModal, setmonthModal] = useState(false); // store hooks const { allowPermissions } = useUserPermissions(); const { t } = useTranslation(); const { currentProjectDetails } = useProject(); const isAdmin = allowPermissions( [EUserPermissions.ADMIN], EUserPermissionsLevel.PROJECT, workspaceSlug?.toString(), currentProjectDetails?.id ); const autoArchiveStatus = useMemo(() => { if (currentProjectDetails?.archive_in === undefined) return false; return currentProjectDetails.archive_in !== 0; }, [currentProjectDetails]); return ( <> setmonthModal(false)} handleChange={handleChange} />

{t("project_settings.automations.auto-archive.title")}

{t("project_settings.automations.auto-archive.description")}

{ if (currentProjectDetails?.archive_in === 0) { await handleChange({ archive_in: 1 }); } else { await handleChange({ archive_in: 0 }); } captureElementAndEvent({ element: { elementName: PROJECT_SETTINGS_TRACKER_ELEMENTS.AUTOMATIONS_ARCHIVE_TOGGLE_BUTTON, }, event: { eventName: PROJECT_SETTINGS_TRACKER_EVENTS.auto_archive_workitems, state: "SUCCESS", }, }); }} size="sm" disabled={!isAdmin} />
{currentProjectDetails ? ( autoArchiveStatus && (
{t("project_settings.automations.auto-archive.duration")}
{ handleChange({ archive_in: val }); }} input disabled={!isAdmin} > <> {PROJECT_AUTOMATION_MONTHS.map((month) => ( {t(month.i18n_label, { months: month.value })} ))}
) ) : ( )}
); });