import { FC, useState } from "react"; import Link from "next/link"; import { observer } from "mobx-react-lite"; import { AlertCircle, Archive, ArchiveRestoreIcon, FileText, Globe2, LinkIcon, Lock, Pencil, Star, Trash2, } from "lucide-react"; import { copyUrlToClipboard } from "helpers/string.helper"; import { renderFormattedTime, renderFormattedDate } from "helpers/date-time.helper"; // ui import { CustomMenu, Tooltip } from "@plane/ui"; // components import { CreateUpdatePageModal, DeletePageModal } from "components/pages"; // constants import { EUserProjectRoles } from "constants/project"; import { useRouter } from "next/router"; import { useProjectPages } from "hooks/store/use-project-specific-pages"; import { useMember, usePage, useUser } from "hooks/store"; import { IIssueLabel } from "@plane/types"; export interface IPagesListItem { pageId: string; projectId: string; } export const PagesListItem: FC = observer(({ pageId, projectId }: IPagesListItem) => { const projectPageStore = useProjectPages(); // Now, I am observing only the projectPages, out of the projectPageStore. const { archivePage, restorePage } = projectPageStore; const pageStore = usePage(pageId); // states const router = useRouter(); const { workspaceSlug } = router.query; const [createUpdatePageModal, setCreateUpdatePageModal] = useState(false); const [deletePageModal, setDeletePageModal] = useState(false); const { currentUser, membership: { currentProjectRole }, } = useUser(); const { project: { getProjectMemberDetails }, } = useMember(); if (!pageStore) return null; const { archived_at, label_details, access, is_favorite, owned_by, name, created_at, updated_at, makePublic, makePrivate, addToFavorites, removeFromFavorites, } = pageStore; const handleCopyUrl = async (e: React.MouseEvent) => { e.preventDefault(); e.stopPropagation(); await copyUrlToClipboard(`${workspaceSlug}/projects/${projectId}/pages/${pageId}`); }; const handleAddToFavorites = (e: React.MouseEvent) => { e.preventDefault(); e.stopPropagation(); addToFavorites(); }; const handleRemoveFromFavorites = (e: React.MouseEvent) => { e.preventDefault(); e.stopPropagation(); removeFromFavorites(); }; const handleMakePublic = (e: React.MouseEvent) => { e.preventDefault(); e.stopPropagation(); makePublic(); }; const handleMakePrivate = (e: React.MouseEvent) => { e.preventDefault(); e.stopPropagation(); makePrivate(); }; const handleArchivePage = async (e: React.MouseEvent) => { e.preventDefault(); e.stopPropagation(); await archivePage(workspaceSlug as string, projectId as string, pageId as string); }; const handleRestorePage = async (e: React.MouseEvent) => { e.preventDefault(); e.stopPropagation(); await restorePage(workspaceSlug as string, projectId as string, pageId as string); }; const handleDeletePage = (e: React.MouseEvent) => { e.preventDefault(); e.stopPropagation(); setDeletePageModal(true); }; const handleEditPage = (e: React.MouseEvent) => { e.preventDefault(); e.stopPropagation(); setCreateUpdatePageModal(true); }; const ownerDetails = getProjectMemberDetails(owned_by); const isCurrentUserOwner = owned_by === currentUser?.id; const userCanEdit = isCurrentUserOwner || (currentProjectRole && [EUserProjectRoles.ADMIN, EUserProjectRoles.MEMBER].includes(currentProjectRole)); const userCanChangeAccess = isCurrentUserOwner; const userCanArchive = isCurrentUserOwner || currentProjectRole === EUserProjectRoles.ADMIN; const userCanDelete = isCurrentUserOwner || currentProjectRole === EUserProjectRoles.ADMIN; const isEditingAllowed = !!currentProjectRole && currentProjectRole >= EUserProjectRoles.MEMBER; return ( <> setCreateUpdatePageModal(false)} projectId={projectId} /> setDeletePageModal(false)} pageId={pageId} />
  • {name}

    {label_details.length > 0 && label_details.map((label: IIssueLabel) => (
    {label.name}
    ))}
    {archived_at ? (

    {renderFormattedTime(archived_at)}

    ) : (

    {renderFormattedTime(updated_at)}

    )} {isEditingAllowed && ( {is_favorite ? ( ) : ( )} )} {userCanChangeAccess && ( {access ? ( ) : ( )} )} {archived_at ? ( <> {userCanArchive && (
    Restore page
    )} {userCanDelete && isEditingAllowed && (
    Delete page
    )} ) : ( <> {userCanEdit && isEditingAllowed && (
    Edit page
    )} {userCanArchive && isEditingAllowed && (
    Archive page
    )} )}
    Copy page link
  • ); });