import React, { useCallback } from "react"; import { observer } from "mobx-react-lite"; import { useParams } from "next/navigation"; import useSWR from "swr"; // types import { TModuleFilters } from "@plane/types"; // components import { EmptyState } from "@/components/empty-state"; import { ArchivedModulesView, ModuleAppliedFiltersList } from "@/components/modules"; import { CycleModuleListLayout } from "@/components/ui"; // constants import { EmptyStateType } from "@/constants/empty-state"; // helpers import { calculateTotalFilters } from "@/helpers/filter.helper"; // hooks import { useModule, useModuleFilter } from "@/hooks/store"; export const ArchivedModuleLayoutRoot: React.FC = observer(() => { // router const { workspaceSlug, projectId } = useParams(); // hooks const { fetchArchivedModules, projectArchivedModuleIds, loader } = useModule(); // module filters hook const { clearAllFilters, currentProjectArchivedFilters, updateFilters } = useModuleFilter(); // derived values const totalArchivedModules = projectArchivedModuleIds?.length ?? 0; useSWR( workspaceSlug && projectId ? `ARCHIVED_MODULES_${workspaceSlug.toString()}_${projectId.toString()}` : null, async () => { if (workspaceSlug && projectId) { await fetchArchivedModules(workspaceSlug.toString(), projectId.toString()); } }, { revalidateIfStale: false, revalidateOnFocus: false } ); const handleRemoveFilter = useCallback( (key: keyof TModuleFilters, value: string | null) => { if (!projectId) return; let newValues = currentProjectArchivedFilters?.[key] ?? []; if (!value) newValues = []; else newValues = newValues.filter((val) => val !== value); updateFilters(projectId.toString(), { [key]: newValues }, "archived"); }, [currentProjectArchivedFilters, projectId, updateFilters] ); if (!workspaceSlug || !projectId) return <>; if (loader || !projectArchivedModuleIds) { return ; } return ( <> {calculateTotalFilters(currentProjectArchivedFilters ?? {}) !== 0 && (
clearAllFilters(projectId.toString(), "archived")} handleRemoveFilter={handleRemoveFilter} alwaysAllowEditing isArchived />
)} {totalArchivedModules === 0 ? (
) : (
)} ); });