2024-04-08 13:41:47 +00:00
|
|
|
import { FC, useCallback, useRef } from "react";
|
2024-01-25 08:11:02 +00:00
|
|
|
import { observer } from "mobx-react";
|
2024-04-08 13:41:47 +00:00
|
|
|
import { useRouter } from "next/router";
|
|
|
|
import { TInboxIssueCurrentTab } from "@plane/types";
|
|
|
|
import { Loader } from "@plane/ui";
|
2024-01-24 15:03:54 +00:00
|
|
|
// components
|
2024-04-08 13:41:47 +00:00
|
|
|
import { EmptyState } from "@/components/empty-state";
|
|
|
|
import { FiltersRoot, InboxIssueAppliedFilters, InboxIssueList } from "@/components/inbox";
|
|
|
|
import { InboxSidebarLoader } from "@/components/ui";
|
|
|
|
// constants
|
|
|
|
import { EmptyStateType } from "@/constants/empty-state";
|
|
|
|
// helpers
|
|
|
|
import { cn } from "@/helpers/common.helper";
|
2024-04-10 14:25:16 +00:00
|
|
|
import { EInboxIssueCurrentTab } from "@/helpers/inbox.helper";
|
2024-04-08 13:41:47 +00:00
|
|
|
// hooks
|
|
|
|
import { useProject, useProjectInbox } from "@/hooks/store";
|
|
|
|
import { useIntersectionObserver } from "@/hooks/use-intersection-observer";
|
2024-01-24 15:03:54 +00:00
|
|
|
|
2024-04-08 13:41:47 +00:00
|
|
|
type IInboxSidebarProps = {
|
2024-01-24 15:03:54 +00:00
|
|
|
workspaceSlug: string;
|
|
|
|
projectId: string;
|
|
|
|
};
|
|
|
|
|
2024-04-08 13:41:47 +00:00
|
|
|
const tabNavigationOptions: { key: TInboxIssueCurrentTab; label: string }[] = [
|
|
|
|
{
|
2024-04-10 14:25:16 +00:00
|
|
|
key: EInboxIssueCurrentTab.OPEN,
|
2024-04-08 13:41:47 +00:00
|
|
|
label: "Open",
|
|
|
|
},
|
|
|
|
{
|
2024-04-10 14:25:16 +00:00
|
|
|
key: EInboxIssueCurrentTab.CLOSED,
|
2024-04-08 13:41:47 +00:00
|
|
|
label: "Closed",
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
export const InboxSidebar: FC<IInboxSidebarProps> = observer((props) => {
|
|
|
|
const { workspaceSlug, projectId } = props;
|
|
|
|
// ref
|
|
|
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
|
|
const elementRef = useRef<HTMLDivElement>(null);
|
|
|
|
// store
|
|
|
|
const { currentProjectDetails } = useProject();
|
2024-01-25 08:11:02 +00:00
|
|
|
const {
|
2024-04-08 13:41:47 +00:00
|
|
|
currentTab,
|
|
|
|
handleCurrentTab,
|
2024-04-15 07:19:14 +00:00
|
|
|
loader,
|
2024-04-08 13:41:47 +00:00
|
|
|
inboxIssuesArray,
|
|
|
|
inboxIssuePaginationInfo,
|
|
|
|
fetchInboxPaginationIssues,
|
|
|
|
getAppliedFiltersCount,
|
|
|
|
} = useProjectInbox();
|
|
|
|
|
|
|
|
const router = useRouter();
|
2024-01-24 15:03:54 +00:00
|
|
|
|
2024-04-08 13:41:47 +00:00
|
|
|
const fetchNextPages = useCallback(() => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
|
|
|
fetchInboxPaginationIssues(workspaceSlug.toString(), projectId.toString());
|
|
|
|
}, [workspaceSlug, projectId, fetchInboxPaginationIssues]);
|
|
|
|
// page observer
|
|
|
|
useIntersectionObserver({
|
|
|
|
containerRef,
|
|
|
|
elementRef,
|
|
|
|
callback: fetchNextPages,
|
|
|
|
rootMargin: "20%",
|
|
|
|
});
|
2024-02-19 15:37:43 +00:00
|
|
|
|
2024-01-24 15:03:54 +00:00
|
|
|
return (
|
2024-04-08 13:41:47 +00:00
|
|
|
<div className="flex-shrink-0 w-2/6 h-full border-r border-custom-border-300">
|
|
|
|
<div className="relative w-full h-full flex flex-col overflow-hidden">
|
|
|
|
<div className="border-b border-custom-border-300 flex-shrink-0 w-full h-[50px] relative flex items-center gap-2 pr-3 whitespace-nowrap">
|
|
|
|
{tabNavigationOptions.map((option) => (
|
|
|
|
<div
|
|
|
|
key={option?.key}
|
|
|
|
className={cn(
|
|
|
|
`text-sm relative flex items-center gap-1 h-[50px] px-2 cursor-pointer transition-all font-medium`,
|
|
|
|
currentTab === option?.key ? `text-custom-primary-100` : `hover:text-custom-text-200`
|
|
|
|
)}
|
|
|
|
onClick={() => {
|
|
|
|
if (currentTab != option?.key) handleCurrentTab(option?.key);
|
2024-04-10 10:38:31 +00:00
|
|
|
router.push(`/${workspaceSlug}/projects/${projectId}/inbox?currentTab=${option?.key}`);
|
2024-04-08 13:41:47 +00:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
<div>{option?.label}</div>
|
|
|
|
{option?.key === "open" && currentTab === option?.key && (
|
|
|
|
<div className="rounded-full p-1.5 py-0.5 bg-custom-primary-100/20 text-custom-primary-100 text-xs font-semibold">
|
|
|
|
{inboxIssuePaginationInfo?.total_results || 0}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
<div
|
|
|
|
className={cn(
|
|
|
|
`border absolute bottom-0 right-0 left-0 rounded-t-md`,
|
|
|
|
currentTab === option?.key ? `border-custom-primary-100` : `border-transparent`
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
<div className="ml-auto">
|
|
|
|
<FiltersRoot />
|
2024-01-24 15:03:54 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2024-04-08 13:41:47 +00:00
|
|
|
<InboxIssueAppliedFilters />
|
2024-01-24 15:03:54 +00:00
|
|
|
|
2024-04-15 07:19:14 +00:00
|
|
|
{loader != undefined && loader === "filter-loading" && !inboxIssuePaginationInfo?.next_page_results ? (
|
2024-04-08 13:41:47 +00:00
|
|
|
<InboxSidebarLoader />
|
|
|
|
) : (
|
|
|
|
<div
|
|
|
|
className="w-full h-full overflow-hidden overflow-y-auto vertical-scrollbar scrollbar-md"
|
|
|
|
ref={containerRef}
|
|
|
|
>
|
|
|
|
{inboxIssuesArray.length > 0 ? (
|
|
|
|
<InboxIssueList
|
|
|
|
workspaceSlug={workspaceSlug}
|
|
|
|
projectId={projectId}
|
|
|
|
projectIdentifier={currentProjectDetails?.identifier}
|
|
|
|
inboxIssues={inboxIssuesArray}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<div className="flex items-center justify-center h-full w-full">
|
|
|
|
<EmptyState
|
|
|
|
type={
|
|
|
|
getAppliedFiltersCount > 0
|
|
|
|
? EmptyStateType.INBOX_SIDEBAR_FILTER_EMPTY_STATE
|
2024-04-10 14:25:16 +00:00
|
|
|
: currentTab === EInboxIssueCurrentTab.OPEN
|
2024-04-08 13:41:47 +00:00
|
|
|
? EmptyStateType.INBOX_SIDEBAR_OPEN_TAB
|
|
|
|
: EmptyStateType.INBOX_SIDEBAR_CLOSED_TAB
|
|
|
|
}
|
|
|
|
layout="screen-simple"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
|
|
|
<div ref={elementRef}>
|
|
|
|
{inboxIssuePaginationInfo?.next_page_results && (
|
|
|
|
<Loader className="mx-auto w-full space-y-4 py-4 px-2">
|
|
|
|
<Loader.Item height="64px" width="w-100" />
|
|
|
|
<Loader.Item height="64px" width="w-100" />
|
|
|
|
</Loader>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
2024-02-19 15:37:43 +00:00
|
|
|
</div>
|
2024-01-24 15:03:54 +00:00
|
|
|
</div>
|
|
|
|
);
|
2024-01-25 08:11:02 +00:00
|
|
|
});
|