/** * Copyright (c) 2023-present Plane Software, Inc. and contributors * SPDX-License-Identifier: AGPL-3.0-only * See the LICENSE file for details. */ import { useCallback, useEffect } from "react"; import { observer } from "mobx-react"; import { PanelLeft } from "lucide-react"; import { useTranslation } from "@plane/i18n"; import { Button } from "@plane/propel/button"; import { IconButton } from "@plane/propel/icon-button"; import { CheckCircleFilledIcon, ChevronDownIcon, ChevronUpIcon, CloseCircleFilledIcon, LinkIcon, NewTabIcon } from "@plane/propel/icons"; import { TOAST_TYPE, setToast } from "@plane/propel/toast"; import type { TNameDescriptionLoader } from "@plane/types"; import { EInboxIssueCurrentTab } from "@plane/types"; import { ControlLink, Header, Row } from "@plane/ui"; import { copyUrlToClipboard, generateWorkItemLink } from "@plane/utils"; import { NameDescriptionUpdateStatus } from "@/components/issues/issue-update-status"; import { useProject } from "@/hooks/store/use-project"; import { useProjectInbox } from "@/hooks/store/use-project-inbox"; import { useAppRouter } from "@/hooks/use-app-router"; import type { IInboxIssueStore } from "@/store/inbox/inbox-issue.store"; import { InboxIssueStatus } from "@/components/inbox/inbox-issue-status"; type Props = { workspaceSlug: string; projectId: string; inboxIssue: IInboxIssueStore | undefined; isSubmitting: TNameDescriptionLoader; isMobileSidebar: boolean; setIsMobileSidebar: (value: boolean) => void; }; export const ExternalContoursIssueActionsHeader = observer(function ExternalContoursIssueActionsHeader(props: Props) { const { workspaceSlug, projectId, inboxIssue, isSubmitting, isMobileSidebar, setIsMobileSidebar } = props; const { t } = useTranslation(); const router = useAppRouter(); const { currentTab, filteredInboxIssueIds } = useProjectInbox(); const { getProjectById } = useProject(); const issue = inboxIssue?.issue; const currentInboxIssueId = issue?.id; const redirectToRelativeIssue = useCallback( (direction: "next" | "prev") => { if (!filteredInboxIssueIds || !currentInboxIssueId) return; const currentIssueIndex = filteredInboxIssueIds.findIndex((issueId) => issueId === currentInboxIssueId); const nextIssueIndex = direction === "next" ? (currentIssueIndex + 1) % filteredInboxIssueIds.length : (currentIssueIndex - 1 + filteredInboxIssueIds.length) % filteredInboxIssueIds.length; const nextIssueId = filteredInboxIssueIds[nextIssueIndex]; if (!nextIssueId) return; router.push(`/${workspaceSlug}/projects/${projectId}/external-contours?currentTab=${currentTab}&inboxIssueId=${nextIssueId}`); }, [currentInboxIssueId, currentTab, filteredInboxIssueIds, projectId, router, workspaceSlug] ); useEffect(() => { const onKeyDown = (event: KeyboardEvent) => { if (event.key === "ArrowUp") redirectToRelativeIssue("prev"); if (event.key === "ArrowDown") redirectToRelativeIssue("next"); }; document.addEventListener("keydown", onKeyDown); return () => document.removeEventListener("keydown", onKeyDown); }, [redirectToRelativeIssue]); if (!issue || !inboxIssue) return null; const workItemLink = generateWorkItemLink({ workspaceSlug: workspaceSlug?.toString(), projectId: issue.project_id, issueId: currentInboxIssueId, projectIdentifier: getProjectById(issue.project_id)?.identifier, sequenceId: issue.sequence_id, }); const showWorkflowToast = (actionLabel: string) => setToast({ type: TOAST_TYPE.INFO, title: t("external_contours_page.actions.unsupported_title"), message: t("external_contours_page.actions.unsupported_message", { action: actionLabel.toLowerCase() }), }); const handleCopyLink = () => copyUrlToClipboard(workItemLink).then(() => setToast({ type: TOAST_TYPE.SUCCESS, title: t("common.link_copied"), message: t("common.copied_to_clipboard"), }) ); const isOpenTab = currentTab === EInboxIssueCurrentTab.OPEN; return ( <>
{issue?.project_id && issue.sequence_id && (

{getProjectById(issue.project_id)?.identifier}-{issue.sequence_id}

)}
redirectToRelativeIssue("prev")} /> redirectToRelativeIssue("next")} />
{isOpenTab ? ( <> ) : ( <> )} router.push(workItemLink)} target="_self">
setIsMobileSidebar(!isMobileSidebar)} className={`my-auto mr-2 h-4 w-4 flex-shrink-0 ${isMobileSidebar ? "text-accent-primary" : "text-secondary"}`} />
); });