import { FC, useRef, useState } from "react"; import { observer } from "mobx-react-lite"; import { MoveRight, MoveDiagonal, Bell, Link2, Trash2 } from "lucide-react"; // hooks import useOutsideClickDetector from "hooks/use-outside-click-detector"; // store hooks import { useIssueDetail, useUser } from "hooks/store"; // components import { DeleteArchivedIssueModal, DeleteIssueModal, IssueActivity, IssueUpdateStatus, PeekOverviewIssueDetails, PeekOverviewProperties, } from "components/issues"; // ui import { Button, CenterPanelIcon, CustomSelect, FullScreenPanelIcon, SidePanelIcon, Spinner } from "@plane/ui"; // types import { TIssue } from "@plane/types"; interface IIssueView { workspaceSlug: string; projectId: string; issueId: string; isLoading?: boolean; isArchived?: boolean; issue: TIssue | undefined; handleCopyText: (e: React.MouseEvent) => void; redirectToIssueDetail: () => void; issueUpdate: (issue: Partial) => void; issueDelete: () => Promise; issueReactionCreate: (reaction: string) => void; issueReactionRemove: (reaction: string) => void; issueCommentCreate: (comment: any) => void; issueCommentUpdate: (comment: any) => void; issueCommentRemove: (commentId: string) => void; issueCommentReactionCreate: (commentId: string, reaction: string) => void; issueCommentReactionRemove: (commentId: string, reaction: string) => void; issueSubscriptionCreate: () => void; issueSubscriptionRemove: () => void; disableUserActions?: boolean; showCommentAccessSpecifier?: boolean; issueOperations: any; } type TPeekModes = "side-peek" | "modal" | "full-screen"; const PEEK_OPTIONS: { key: TPeekModes; icon: any; title: string }[] = [ { key: "side-peek", icon: SidePanelIcon, title: "Side Peek", }, { key: "modal", icon: CenterPanelIcon, title: "Modal", }, { key: "full-screen", icon: FullScreenPanelIcon, title: "Full Screen", }, ]; export const IssueView: FC = observer((props) => { const { workspaceSlug, projectId, issueId, issue, isLoading, isArchived, handleCopyText, redirectToIssueDetail, issueUpdate, issueReactionCreate, issueReactionRemove, issueCommentCreate, issueCommentUpdate, issueCommentRemove, issueCommentReactionCreate, issueCommentReactionRemove, issueSubscriptionCreate, issueSubscriptionRemove, issueDelete, disableUserActions = false, showCommentAccessSpecifier = false, issueOperations, } = props; // states const [peekMode, setPeekMode] = useState("side-peek"); const [isSubmitting, setIsSubmitting] = useState<"submitting" | "submitted" | "saved">("saved"); // ref const issuePeekOverviewRef = useRef(null); // store hooks const { activity, reaction, subscription, setPeekIssue, isAnyModalOpen, isDeleteIssueModalOpen, toggleDeleteIssueModal, } = useIssueDetail(); const { currentUser } = useUser(); const removeRoutePeekId = () => { setPeekIssue(undefined); }; const issueReactions = reaction.getReactionsByIssueId(issueId) || []; const issueActivity = activity.getActivitiesByIssueId(issueId); const issueSubscription = subscription.getSubscriptionByIssueId(issueId) || {}; const currentMode = PEEK_OPTIONS.find((m) => m.key === peekMode); useOutsideClickDetector(issuePeekOverviewRef, () => !isAnyModalOpen && removeRoutePeekId()); return ( <> {issue && !isArchived && ( toggleDeleteIssueModal(false)} data={issue} onSubmit={issueDelete} /> )} {issue && isArchived && ( toggleDeleteIssueModal(false)} onSubmit={issueDelete} /> )}
{issueId && (
{/* header */}
{currentMode && (
setPeekMode(val)} customButton={ } > {PEEK_OPTIONS.map((mode) => (
{mode.title}
))}
)}
{issue?.created_by !== currentUser?.id && !issue?.assignee_ids.includes(currentUser?.id ?? "") && !issue?.archived_at && ( )} {!disableUserActions && ( )}
{/* content */}
{isLoading && !issue ? (
) : ( issue && ( <> {["side-peek", "modal"].includes(peekMode) ? (
{isArchived && (
)} setIsSubmitting(value)} isSubmitting={isSubmitting} workspaceSlug={workspaceSlug} issue={issue} issueUpdate={issueUpdate} issueReactions={issueReactions} user={currentUser} issueReactionCreate={issueReactionCreate} issueReactionRemove={issueReactionRemove} />
) : (
setIsSubmitting(value)} isSubmitting={isSubmitting} workspaceSlug={workspaceSlug} issue={issue} issueReactions={issueReactions} issueUpdate={issueUpdate} user={currentUser} issueReactionCreate={issueReactionCreate} issueReactionRemove={issueReactionRemove} />
)} ) )}
)}
); });