import React, { useState } from "react"; import useSWR from "swr"; import { useRouter } from "next/router"; // component import { SelectMonthModal } from "components/automation"; import { CustomSelect, CustomSearchSelect, ToggleSwitch, StateGroupIcon, DoubleCircleIcon } from "@plane/ui"; // icons import { ArchiveX } from "lucide-react"; // services import { ProjectStateService } from "services/project"; // constants import { PROJECT_AUTOMATION_MONTHS } from "constants/project"; import { STATES_LIST } from "constants/fetch-keys"; // types import { IProject } from "types"; // helper import { getStatesList } from "helpers/state.helper"; type Props = { projectDetails: IProject | undefined; handleChange: (formData: Partial) => Promise; disabled?: boolean; }; const projectStateService = new ProjectStateService(); export const AutoCloseAutomation: React.FC = ({ projectDetails, handleChange, disabled = false }) => { const [monthModal, setmonthModal] = useState(false); const router = useRouter(); const { workspaceSlug, projectId } = router.query; const { data: stateGroups } = useSWR( workspaceSlug && projectId ? STATES_LIST(projectId as string) : null, workspaceSlug && projectId ? () => projectStateService.getStates(workspaceSlug as string, projectId as string) : null ); const states = getStatesList(stateGroups); const options = states ?.filter((state) => state.group === "cancelled") .map((state) => ({ value: state.id, query: state.name, content: (
{state.name}
), })); const multipleOptions = (options ?? []).length > 1; const defaultState = stateGroups && stateGroups.cancelled ? stateGroups.cancelled[0].id : null; const selectedOption = states?.find((s) => s.id === projectDetails?.default_state ?? defaultState); const currentDefaultState = states?.find((s) => s.id === defaultState); const initialValues: Partial = { close_in: 1, default_state: defaultState, }; return ( <> setmonthModal(false)} handleChange={handleChange} />

Auto-close issues

Plane will automatically close issue that haven’t been completed or cancelled.

projectDetails?.close_in === 0 ? handleChange({ close_in: 1, default_state: defaultState }) : handleChange({ close_in: 0, default_state: null }) } size="sm" disabled={disabled} />
{projectDetails?.close_in !== 0 && (
Auto-close issues that are inactive for
{ handleChange({ close_in: val }); }} input width="w-full" disabled={disabled} > <> {PROJECT_AUTOMATION_MONTHS.map((month) => ( {month.label} ))}
Auto-close Status
{selectedOption ? ( ) : currentDefaultState ? ( ) : ( )} {selectedOption?.name ? selectedOption.name : currentDefaultState?.name ?? State}
} onChange={(val: string) => { handleChange({ default_state: val }); }} options={options} disabled={!multipleOptions} width="w-full" input />
)} ); };