/** * Copyright (c) 2023-present Plane Software, Inc. and contributors * SPDX-License-Identifier: AGPL-3.0-only * See the LICENSE file for details. */ import { useEffect, useState } from "react"; import { observer } from "mobx-react"; import { useTranslation } from "@plane/i18n"; import type { TInboxIssueCurrentTab } from "@plane/types"; import { EInboxIssueCurrentTab } from "@plane/types"; import { cn } from "@plane/utils"; import { useSearchParams } from "next/navigation"; import { useProjectExternalContours } from "@/hooks/store/use-project-external-contours"; import { useAppRouter } from "@/hooks/use-app-router"; import { ExternalContoursEmptyState } from "./empty-state"; import { ExternalContoursListItem } from "./list-item"; type Props = { workspaceSlug: string; projectId: string; inboxIssueId: string | undefined; setIsMobileSidebar: (value: boolean) => void; }; const tabNavigationOptions: { key: TInboxIssueCurrentTab; i18n_label: string }[] = [ { key: EInboxIssueCurrentTab.OPEN, i18n_label: "external_contours_page.tabs.open" }, { key: EInboxIssueCurrentTab.CLOSED, i18n_label: "external_contours_page.tabs.closed" }, ]; export const ExternalContoursSidebar = observer(function ExternalContoursSidebar(props: Props) { const { workspaceSlug, projectId, inboxIssueId, setIsMobileSidebar } = props; const router = useAppRouter(); const searchParams = useSearchParams(); const { t } = useTranslation(); const { currentTab, filteredRequestIds, openRequestIds, closedRequestIds, loader, handleCurrentTab } = useProjectExternalContours(); const [pendingTab, setPendingTab] = useState(null); const routeTab = (searchParams.get("currentTab") as TInboxIssueCurrentTab | null) ?? currentTab; const resolvedTab = pendingTab ?? routeTab; const isTabTransitioning = loader === "init-loading" || pendingTab !== null || routeTab !== currentTab; useEffect(() => { if (pendingTab && loader !== "init-loading" && routeTab === pendingTab && currentTab === pendingTab) { setPendingTab(null); } }, [currentTab, loader, pendingTab, routeTab]); useEffect(() => { if (workspaceSlug && projectId && filteredRequestIds.length > 0 && inboxIssueId === undefined) { router.push( `/${workspaceSlug}/projects/${projectId}/external-contours?currentTab=${resolvedTab}&inboxIssueId=${filteredRequestIds[0]}` ); } }, [filteredRequestIds, inboxIssueId, projectId, resolvedTab, router, workspaceSlug]); return (
{tabNavigationOptions.map((option) => { const count = option.key === EInboxIssueCurrentTab.CLOSED ? closedRequestIds.length : openRequestIds.length; return ( ); })}
{isTabTransitioning ? (
{t("loading")}...
) : filteredRequestIds.length > 0 ? (
{filteredRequestIds.map((requestId) => ( ))}
) : (
)}
); });