import { useState, ReactElement } from "react"; import { observer } from "mobx-react"; import { useRouter } from "next/router"; import useSWR from "swr"; // icons import { ArchiveRestoreIcon } from "lucide-react"; // ui import { ArchiveIcon, Button, Loader, TOAST_TYPE, setToast } from "@plane/ui"; // components import { PageHead } from "@/components/core"; import { ProjectArchivedIssueDetailsHeader } from "@/components/headers"; import { IssueDetailRoot } from "@/components/issues"; // constants import { EIssuesStoreType } from "@/constants/issue"; import { EUserProjectRoles } from "@/constants/project"; // hooks import { useIssueDetail, useIssues, useProject, useUser } from "@/hooks/store"; // layouts import { AppLayout } from "@/layouts/app-layout"; // types import { NextPageWithLayout } from "@/lib/types"; const ArchivedIssueDetailsPage: NextPageWithLayout = observer(() => { // router const router = useRouter(); const { workspaceSlug, projectId, archivedIssueId } = router.query; // states const [isRestoring, setIsRestoring] = useState(false); // hooks const { fetchIssue, issue: { getIssueById }, } = useIssueDetail(); const { issues: { restoreIssue }, } = useIssues(EIssuesStoreType.ARCHIVED); const { getProjectById } = useProject(); const { membership: { currentProjectRole }, } = useUser(); const { isLoading, data: swrArchivedIssueDetails } = useSWR( workspaceSlug && projectId && archivedIssueId ? `ARCHIVED_ISSUE_DETAIL_${workspaceSlug}_${projectId}_${archivedIssueId}` : null, workspaceSlug && projectId && archivedIssueId ? () => fetchIssue(workspaceSlug.toString(), projectId.toString(), archivedIssueId.toString(), "ARCHIVED") : null ); // derived values const issue = archivedIssueId ? getIssueById(archivedIssueId.toString()) : undefined; const project = issue ? getProjectById(issue?.project_id) : undefined; const pageTitle = project && issue ? `${project?.identifier}-${issue?.sequence_id} ${issue?.name}` : undefined; // auth const canRestoreIssue = !!currentProjectRole && currentProjectRole >= EUserProjectRoles.MEMBER; if (!issue) return <>; const handleRestore = async () => { if (!workspaceSlug || !projectId || !archivedIssueId) return; setIsRestoring(true); await restoreIssue(workspaceSlug.toString(), projectId.toString(), archivedIssueId.toString()) .then(() => { setToast({ type: TOAST_TYPE.SUCCESS, title: "Restore success", message: "Your issue can be found in project issues.", }); router.push(`/${workspaceSlug}/projects/${projectId}/issues/${archivedIssueId}`); }) .catch(() => { setToast({ type: TOAST_TYPE.ERROR, title: "Error!", message: "Issue could not be restored. Please try again.", }); }) .finally(() => setIsRestoring(false)); }; const issueLoader = !issue || isLoading ? true : false; return ( <> {issueLoader ? (
) : (
{issue?.archived_at && canRestoreIssue && (

This issue has been archived.

)} {workspaceSlug && projectId && archivedIssueId && ( )}
)} ); }); ArchivedIssueDetailsPage.getLayout = function getLayout(page: ReactElement) { return ( } withProjectWrapper> {page} ); }; export default ArchivedIssueDetailsPage;