2024-04-28 19:24:35 +00:00
|
|
|
import { FC, useState } from "react";
|
2024-04-08 13:41:47 +00:00
|
|
|
import { observer } from "mobx-react";
|
|
|
|
import useSWR from "swr";
|
2024-04-28 19:24:35 +00:00
|
|
|
import { Inbox, PanelLeft } from "lucide-react";
|
2024-04-08 13:41:47 +00:00
|
|
|
// components
|
|
|
|
import { EmptyState } from "@/components/empty-state";
|
|
|
|
import { InboxSidebar, InboxContentRoot } from "@/components/inbox";
|
|
|
|
import { InboxLayoutLoader } from "@/components/ui";
|
|
|
|
// constants
|
|
|
|
import { EmptyStateType } from "@/constants/empty-state";
|
2024-04-28 19:24:35 +00:00
|
|
|
// helpers
|
|
|
|
import { cn } from "@/helpers/common.helper";
|
2024-04-08 13:41:47 +00:00
|
|
|
// hooks
|
|
|
|
import { useProjectInbox } from "@/hooks/store";
|
|
|
|
|
|
|
|
type TInboxIssueRoot = {
|
|
|
|
workspaceSlug: string;
|
|
|
|
projectId: string;
|
|
|
|
inboxIssueId: string | undefined;
|
|
|
|
inboxAccessible: boolean;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const InboxIssueRoot: FC<TInboxIssueRoot> = observer((props) => {
|
|
|
|
const { workspaceSlug, projectId, inboxIssueId, inboxAccessible } = props;
|
2024-04-28 19:24:35 +00:00
|
|
|
// states
|
2024-04-29 14:08:46 +00:00
|
|
|
const [isMobileSidebar, setIsMobileSidebar] = useState(true);
|
2024-04-08 13:41:47 +00:00
|
|
|
// hooks
|
2024-04-15 07:19:14 +00:00
|
|
|
const { loader, error, fetchInboxIssues } = useProjectInbox();
|
2024-04-08 13:41:47 +00:00
|
|
|
|
|
|
|
useSWR(
|
|
|
|
inboxAccessible && workspaceSlug && projectId ? `PROJECT_INBOX_ISSUES_${workspaceSlug}_${projectId}` : null,
|
2024-04-10 14:25:16 +00:00
|
|
|
async () => {
|
|
|
|
inboxAccessible &&
|
|
|
|
workspaceSlug &&
|
|
|
|
projectId &&
|
|
|
|
(await fetchInboxIssues(workspaceSlug.toString(), projectId.toString()));
|
2024-04-08 13:41:47 +00:00
|
|
|
},
|
2024-04-10 08:22:57 +00:00
|
|
|
{ revalidateOnFocus: false, revalidateIfStale: false }
|
2024-04-08 13:41:47 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// loader
|
2024-04-15 07:19:14 +00:00
|
|
|
if (loader === "init-loading")
|
2024-04-08 13:41:47 +00:00
|
|
|
return (
|
|
|
|
<div className="relative flex w-full h-full flex-col">
|
|
|
|
<InboxLayoutLoader />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
|
|
|
// error
|
|
|
|
if (error && error?.status === "init-error")
|
|
|
|
return (
|
|
|
|
<div className="relative w-full h-full flex flex-col gap-3 justify-center items-center">
|
|
|
|
<Inbox size={60} strokeWidth={1.5} />
|
|
|
|
<div className="text-custom-text-200">{error?.message}</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
2024-04-28 19:24:35 +00:00
|
|
|
<>
|
|
|
|
{!inboxIssueId && (
|
|
|
|
<div className="flex lg:hidden items-center px-4 w-full h-12 border-b border-custom-border-200">
|
|
|
|
<PanelLeft
|
2024-04-29 14:08:46 +00:00
|
|
|
onClick={() => setIsMobileSidebar(!isMobileSidebar)}
|
|
|
|
className={cn("w-4 h-4 ", isMobileSidebar ? "text-custom-primary-100" : " text-custom-text-200")}
|
2024-04-28 19:24:35 +00:00
|
|
|
/>
|
2024-04-08 13:41:47 +00:00
|
|
|
</div>
|
|
|
|
)}
|
2024-04-28 19:24:35 +00:00
|
|
|
<div className="w-full h-full flex overflow-hidden bg-custom-background-100">
|
|
|
|
<div
|
|
|
|
className={cn(
|
|
|
|
"absolute z-10 top-[50px] lg:!top-0 lg:!relative bg-custom-background-100 flex-shrink-0 w-full lg:w-2/6 bottom-0 transition-all",
|
2024-04-29 14:08:46 +00:00
|
|
|
isMobileSidebar ? "translate-x-0" : "-translate-x-full lg:!translate-x-0"
|
2024-04-28 19:24:35 +00:00
|
|
|
)}
|
|
|
|
>
|
|
|
|
<InboxSidebar
|
2024-04-29 14:08:46 +00:00
|
|
|
setIsMobileSidebar={setIsMobileSidebar}
|
2024-04-28 19:24:35 +00:00
|
|
|
workspaceSlug={workspaceSlug.toString()}
|
|
|
|
projectId={projectId.toString()}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{inboxIssueId ? (
|
|
|
|
<InboxContentRoot
|
2024-04-29 14:08:46 +00:00
|
|
|
setIsMobileSidebar={setIsMobileSidebar}
|
|
|
|
isMobileSidebar={isMobileSidebar}
|
2024-04-28 19:24:35 +00:00
|
|
|
workspaceSlug={workspaceSlug.toString()}
|
|
|
|
projectId={projectId.toString()}
|
|
|
|
inboxIssueId={inboxIssueId.toString()}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<div className="w-full h-full relative flex justify-center items-center">
|
|
|
|
<EmptyState type={EmptyStateType.INBOX_DETAIL_EMPTY_STATE} layout="screen-simple" />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</>
|
2024-04-08 13:41:47 +00:00
|
|
|
);
|
|
|
|
});
|