2024-04-08 13:41:47 +00:00
|
|
|
import { FC, useState } from "react";
|
2024-01-25 08:11:02 +00:00
|
|
|
import { observer } from "mobx-react";
|
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-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-04-08 13:41:47 +00:00
|
|
|
const { fetchInboxIssueById, getIssueInboxByIssueId } = useProjectInbox();
|
|
|
|
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-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-04-30 14:09:50 +00:00
|
|
|
: null
|
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>
|
|
|
|
<div className="h-full w-full space-y-5 divide-y-2 divide-custom-border-300 overflow-y-auto p-5 vertical-scrollbar scrollbar-md">
|
|
|
|
<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
|
|
|
</>
|
|
|
|
);
|
|
|
|
});
|