import { useCallback, useEffect, useState } from "react"; import { useRouter } from "next/router"; import { observer } from "mobx-react-lite"; import useSWR from "swr"; import { useForm } from "react-hook-form"; import { AlertTriangle, CheckCircle2, Clock, Copy, ExternalLink, Inbox, XCircle } from "lucide-react"; // hooks import { useProjectState, useUser, useInboxIssues } from "hooks/store"; // components import { IssueDescriptionForm, // FIXME: have to replace this once the issue details page is ready --issue-detail-- // IssueDetailsSidebar, // IssueReaction, IssueUpdateStatus, } from "components/issues"; import { InboxIssueActivity } from "components/inbox"; // ui import { Loader, StateGroupIcon } from "@plane/ui"; // helpers import { renderFormattedDate } from "helpers/date-time.helper"; // types import { IInboxIssue, TIssue } from "@plane/types"; import { EUserProjectRoles } from "constants/project"; const defaultValues: Partial = { name: "", description_html: "", assignee_ids: [], priority: "low", target_date: new Date().toString(), label_ids: [], }; export const InboxMainContent: React.FC = observer(() => { // states const [isSubmitting, setIsSubmitting] = useState<"submitting" | "submitted" | "saved">("saved"); // router const router = useRouter(); const { workspaceSlug, projectId, inboxId, inboxIssueId } = router.query; // store hooks const { currentInboxIssueIds: currentInboxIssues, fetchIssueDetails, getIssueById, updateIssue } = useInboxIssues(); const { currentUser, membership: { currentProjectRole }, } = useUser(); const { projectStates } = useProjectState(); // form info const { reset, control, watch } = useForm({ defaultValues, }); useSWR( workspaceSlug && projectId && inboxId && inboxIssueId ? `INBOX_ISSUE_DETAILS_${inboxIssueId.toString()}` : null, workspaceSlug && projectId && inboxId && inboxIssueId ? () => fetchIssueDetails(workspaceSlug.toString(), projectId.toString(), inboxId.toString(), inboxIssueId.toString()) : null ); const issuesList = currentInboxIssues; const issueDetails = inboxIssueId ? getIssueById(inboxId as string, inboxIssueId.toString()) : undefined; const currentIssueState = projectStates?.find((s) => s.id === issueDetails?.state_id); const submitChanges = useCallback( async (formData: Partial) => { if (!workspaceSlug || !projectId || !inboxIssueId || !inboxId || !issueDetails) return; await updateIssue( workspaceSlug.toString(), projectId.toString(), inboxId.toString(), issueDetails.issue_inbox[0].id, formData ); }, [workspaceSlug, inboxIssueId, projectId, inboxId, issueDetails, updateIssue] ); // const onKeyDown = useCallback( // (e: KeyboardEvent) => { // if (!issuesList || !inboxIssueId) return; // const currentIssueIndex = issuesList.findIndex((issue) => issue.issue_inbox[0].id === inboxIssueId); // switch (e.key) { // case "ArrowUp": // Router.push({ // pathname: `/${workspaceSlug}/projects/${projectId}/inbox/${inboxId}`, // query: { // inboxIssueId: // currentIssueIndex === 0 // ? issuesList[issuesList.length - 1].issue_inbox[0].id // : issuesList[currentIssueIndex - 1].issue_inbox[0].id, // }, // }); // break; // case "ArrowDown": // Router.push({ // pathname: `/${workspaceSlug}/projects/${projectId}/inbox/${inboxId}`, // query: { // inboxIssueId: // currentIssueIndex === issuesList.length - 1 // ? issuesList[0].issue_inbox[0].id // : issuesList[currentIssueIndex + 1].issue_inbox[0].id, // }, // }); // break; // default: // break; // } // }, // [workspaceSlug, projectId, inboxIssueId, inboxId, issuesList] // ); // useEffect(() => { // document.addEventListener("keydown", onKeyDown); // return () => { // document.removeEventListener("keydown", onKeyDown); // }; // }, [onKeyDown]); useEffect(() => { if (!issueDetails || !inboxIssueId) return; reset({ ...issueDetails, assignee_ids: issueDetails.assignee_ids ?? issueDetails.assignee_ids, label_ids: issueDetails.label_ids ?? issueDetails.label_ids, }); }, [issueDetails, reset, inboxIssueId]); const issueStatus = issueDetails?.issue_inbox[0].status; if (!inboxIssueId) return (
{issuesList && issuesList.length > 0 ? ( {issuesList?.length} issues found. Select an issue from the sidebar to view its details. ) : ( No issues found )}
); const isAllowed = !!currentProjectRole && currentProjectRole >= EUserProjectRoles.MEMBER; return ( <> {issueDetails ? (
{issueStatus === -2 ? ( <>

This issue is still pending.

) : issueStatus === -1 ? ( <>

This issue has been declined.

) : issueStatus === 0 ? ( <> {new Date(issueDetails.issue_inbox[0].snoozed_till ?? "") < new Date() ? (

This issue was snoozed till {renderFormattedDate(issueDetails.issue_inbox[0].snoozed_till ?? "")}.

) : (

This issue has been snoozed till{" "} {renderFormattedDate(issueDetails.issue_inbox[0].snoozed_till ?? "")}.

)} ) : issueStatus === 1 ? ( <>

This issue has been accepted.

) : issueStatus === 2 ? ( <>

This issue has been marked as a duplicate of this issue .

) : null}
{currentIssueState && ( )}
{/* FIXME: have to replace this once the issue details page is ready --issue-detail-- */} {/*
setIsSubmitting(value)} isSubmitting={isSubmitting} workspaceSlug={workspaceSlug as string} issue={{ name: issueDetails.name, description_html: issueDetails.description_html, id: issueDetails.id, }} handleFormSubmit={submitChanges} isAllowed={isAllowed || currentUser?.id === issueDetails.created_by} />
*/} {/* FIXME: have to replace this once the issue details page is ready --issue-detail-- */} {/* {workspaceSlug && projectId && ( )} */}
{/* FIXME: have to replace this once the issue details page is ready --issue-detail-- */} {/* */}
) : (
)} ); });