/** * Copyright (c) 2023-present Plane Software, Inc. and contributors * SPDX-License-Identifier: AGPL-3.0-only * See the LICENSE file for details. */ import { useMemo, useState } from "react"; import { observer } from "mobx-react"; import { useParams } from "next/navigation"; import { RestoreOutline } from "@makeplane/propel/icons"; // plane imports import { PROJECT_AUTOMATION_MONTHS, EUserPermissions, EUserPermissionsLevel } from "@plane/constants"; import { useTranslation } from "@plane/i18n"; import type { IProject } from "@plane/types"; import { Switch } from "@makeplane/propel/components/switch"; import { CustomSelect, Loader } from "@plane/ui"; // component import { SelectMonthModal } from "@/components/automation"; import { SettingsControlItem } from "@/components/settings/control-item"; // hooks 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 = observer(function AutoArchiveAutomation(props: 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]); const handleToggleArchive = async () => { if (currentProjectDetails?.archive_in === 0) { await handleChange({ archive_in: 1 }); } else { await handleChange({ archive_in: 0 }); } }; return ( <> setmonthModal(false)} handleChange={handleChange} />
} />
{currentProjectDetails ? ( autoArchiveStatus && (
{t("project_settings.automations.auto-archive.duration")}
void handleChange({ archive_in: val })} input disabled={!isAdmin} > <> {PROJECT_AUTOMATION_MONTHS.map((month) => ( {t(month.i18n_label, { months: month.value })} ))}
) ) : ( )}
); });