2024-05-31 09:40:38 +00:00
|
|
|
import { FC, useEffect, useState } from "react";
|
2024-01-25 08:11:02 +00:00
|
|
|
import { observer } from "mobx-react";
|
2024-05-31 09:40:38 +00:00
|
|
|
import { useRouter } from "next/router";
|
2024-04-08 13:41:47 +00:00
|
|
|
import useSWR from "swr";
|
|
|
|
import { InboxIssueActionsHeader, InboxIssueMainContent } from "@/components/inbox";
|
|
|
|
import { EUserProjectRoles } from "@/constants/project";
|
|
|
|
import { useProjectInbox, useUser } from "@/hooks/store";
|
2024-01-25 08:11:02 +00:00
|
|
|
|
|
|
|
type TInboxContentRoot = {
|
|
|
|
workspaceSlug: string;
|
|
|
|
projectId: string;
|
2024-04-08 13:41:47 +00:00
|
|
|
inboxIssueId: string;
|
2024-04-29 14:08:46 +00:00
|
|
|
isMobileSidebar: boolean;
|
|
|
|
setIsMobileSidebar: (value: boolean) => void;
|
2024-01-25 08:11:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const InboxContentRoot: FC<TInboxContentRoot> = observer((props) => {
|
2024-04-29 14:08:46 +00:00
|
|
|
const { workspaceSlug, projectId, inboxIssueId, isMobileSidebar, setIsMobileSidebar } = props;
|
2024-05-31 09:40:38 +00:00
|
|
|
/// router
|
|
|
|
const router = useRouter();
|
2024-04-08 13:41:47 +00:00
|
|
|
// states
|
|
|
|
const [isSubmitting, setIsSubmitting] = useState<"submitting" | "submitted" | "saved">("saved");
|
2024-01-25 08:11:02 +00:00
|
|
|
// hooks
|
2024-05-31 09:40:38 +00:00
|
|
|
const { currentTab, fetchInboxIssueById, getIssueInboxByIssueId, getIsIssueAvailable } = useProjectInbox();
|
2024-04-08 13:41:47 +00:00
|
|
|
const inboxIssue = getIssueInboxByIssueId(inboxIssueId);
|
2024-01-25 08:11:02 +00:00
|
|
|
const {
|
2024-04-08 13:41:47 +00:00
|
|
|
membership: { currentProjectRole },
|
|
|
|
} = useUser();
|
2024-05-31 09:40:38 +00:00
|
|
|
// derived values
|
|
|
|
const isIssueAvailable = getIsIssueAvailable(inboxIssueId?.toString() || "");
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (!isIssueAvailable && inboxIssueId) {
|
|
|
|
router.replace(`/${workspaceSlug}/projects/${projectId}/inbox?currentTab=${currentTab}`);
|
|
|
|
}
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
}, [isIssueAvailable]);
|
2024-01-25 08:11:02 +00:00
|
|
|
|
2024-04-30 14:09:50 +00:00
|
|
|
useSWR(
|
2024-04-08 13:41:47 +00:00
|
|
|
workspaceSlug && projectId && inboxIssueId
|
|
|
|
? `PROJECT_INBOX_ISSUE_DETAIL_${workspaceSlug}_${projectId}_${inboxIssueId}`
|
|
|
|
: null,
|
2024-04-11 15:58:59 +00:00
|
|
|
workspaceSlug && projectId && inboxIssueId
|
|
|
|
? () => fetchInboxIssueById(workspaceSlug, projectId, inboxIssueId)
|
2024-05-08 09:17:18 +00:00
|
|
|
: null,
|
|
|
|
{
|
|
|
|
revalidateOnFocus: false,
|
|
|
|
revalidateIfStale: false,
|
|
|
|
}
|
2024-04-08 13:41:47 +00:00
|
|
|
);
|
|
|
|
|
2024-04-10 10:38:31 +00:00
|
|
|
const isEditable = !!currentProjectRole && currentProjectRole >= EUserProjectRoles.MEMBER;
|
2024-01-25 08:11:02 +00:00
|
|
|
|
2024-04-08 13:41:47 +00:00
|
|
|
if (!inboxIssue) return <></>;
|
2024-04-10 08:22:57 +00:00
|
|
|
|
2024-04-10 10:38:31 +00:00
|
|
|
const isIssueDisabled = [-1, 1, 2].includes(inboxIssue.status);
|
2024-04-10 08:22:57 +00:00
|
|
|
|
2024-01-25 08:11:02 +00:00
|
|
|
return (
|
|
|
|
<>
|
2024-04-08 13:41:47 +00:00
|
|
|
<div className="w-full h-full overflow-hidden relative flex flex-col">
|
|
|
|
<div className="flex-shrink-0 min-h-[50px] border-b border-custom-border-300">
|
|
|
|
<InboxIssueActionsHeader
|
2024-04-29 14:08:46 +00:00
|
|
|
setIsMobileSidebar={setIsMobileSidebar}
|
|
|
|
isMobileSidebar={isMobileSidebar}
|
2024-04-08 13:41:47 +00:00
|
|
|
workspaceSlug={workspaceSlug}
|
|
|
|
projectId={projectId}
|
|
|
|
inboxIssue={inboxIssue}
|
|
|
|
isSubmitting={isSubmitting}
|
|
|
|
/>
|
|
|
|
</div>
|
2024-05-01 12:31:30 +00:00
|
|
|
<div className="h-full w-full space-y-5 divide-y-2 divide-custom-border-200 overflow-y-auto px-6 py-5 vertical-scrollbar scrollbar-md">
|
2024-04-08 13:41:47 +00:00
|
|
|
<InboxIssueMainContent
|
|
|
|
workspaceSlug={workspaceSlug}
|
|
|
|
projectId={projectId}
|
|
|
|
inboxIssue={inboxIssue}
|
2024-04-10 10:38:31 +00:00
|
|
|
isEditable={isEditable && !isIssueDisabled}
|
2024-04-08 13:41:47 +00:00
|
|
|
isSubmitting={isSubmitting}
|
|
|
|
setIsSubmitting={setIsSubmitting}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-01-25 08:11:02 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
});
|