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-01-25 08:11:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const InboxContentRoot: FC<TInboxContentRoot> = observer((props) => {
|
2024-04-08 13:41:47 +00:00
|
|
|
const { workspaceSlug, projectId, inboxIssueId } = props;
|
|
|
|
// 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-08 13:41:47 +00:00
|
|
|
useSWR(
|
|
|
|
workspaceSlug && projectId && inboxIssueId
|
|
|
|
? `PROJECT_INBOX_ISSUE_DETAIL_${workspaceSlug}_${projectId}_${inboxIssueId}`
|
|
|
|
: null,
|
|
|
|
() => {
|
|
|
|
workspaceSlug && projectId && inboxIssueId && fetchInboxIssueById(workspaceSlug, projectId, inboxIssueId);
|
|
|
|
},
|
|
|
|
{ revalidateOnFocus: false }
|
|
|
|
);
|
|
|
|
|
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
|
|
|
|
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
|
|
|
</>
|
|
|
|
);
|
|
|
|
});
|