-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
Copy pathroot.tsx
123 lines (111 loc) · 4.23 KB
/
root.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import { FC, useEffect, useState } from "react";
import { observer } from "mobx-react";
import dynamic from "next/dynamic";
import useSWR from "swr";
import { EUserPermissions, EUserPermissionsLevel } from "@plane/constants";
import { TNameDescriptionLoader } from "@plane/types";
// components
import { ContentWrapper } from "@plane/ui";
// hooks
import { IssuePeekOverviewLoader } from "@/components/issues/peek-overview/loader";
import { useProjectInbox, useUser, useUserPermissions } from "@/hooks/store";
import { useAppRouter } from "@/hooks/use-app-router";
const InboxIssueActionsHeader = dynamic(
() => import("@/components/inbox/content/inbox-issue-header").then((m) => m.InboxIssueActionsHeader),
{
ssr: false,
loading: () => null,
}
);
const InboxIssueMainContent = dynamic(
() => import("@/components/inbox/content/issue-root").then((m) => m.InboxIssueMainContent),
{
ssr: false,
loading: () => <IssuePeekOverviewLoader removeRoutePeekId={() => null} />,
}
);
type TInboxContentRoot = {
workspaceSlug: string;
projectId: string;
inboxIssueId: string;
isMobileSidebar: boolean;
setIsMobileSidebar: (value: boolean) => void;
isNotificationEmbed?: boolean;
embedRemoveCurrentNotification?: () => void;
};
export const InboxContentRoot: FC<TInboxContentRoot> = observer((props) => {
const {
workspaceSlug,
projectId,
inboxIssueId,
isMobileSidebar,
setIsMobileSidebar,
isNotificationEmbed = false,
embedRemoveCurrentNotification,
} = props;
/// router
const router = useAppRouter();
// states
const [isSubmitting, setIsSubmitting] = useState<TNameDescriptionLoader>("saved");
// hooks
const { data: currentUser } = useUser();
const { currentTab, fetchInboxIssueById, getIssueInboxByIssueId, getIsIssueAvailable } = useProjectInbox();
const inboxIssue = getIssueInboxByIssueId(inboxIssueId);
const { allowPermissions, projectPermissionsByWorkspaceSlugAndProjectId } = useUserPermissions();
// derived values
const isIssueAvailable = getIsIssueAvailable(inboxIssueId?.toString() || "");
useEffect(() => {
if (!isIssueAvailable && inboxIssueId && !isNotificationEmbed) {
router.replace(`/${workspaceSlug}/projects/${projectId}/inbox?currentTab=${currentTab}`);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isIssueAvailable, isNotificationEmbed]);
useSWR(
workspaceSlug && projectId && inboxIssueId
? `PROJECT_INBOX_ISSUE_DETAIL_${workspaceSlug}_${projectId}_${inboxIssueId}`
: null,
workspaceSlug && projectId && inboxIssueId
? () => fetchInboxIssueById(workspaceSlug, projectId, inboxIssueId)
: null,
{
revalidateOnFocus: false,
revalidateIfStale: false,
}
);
const isEditable =
allowPermissions([EUserPermissions.ADMIN], EUserPermissionsLevel.PROJECT, workspaceSlug, projectId) ||
inboxIssue?.issue.created_by === currentUser?.id;
const isGuest = projectPermissionsByWorkspaceSlugAndProjectId(workspaceSlug, projectId) === EUserPermissions.GUEST;
const isOwner = inboxIssue?.issue.created_by === currentUser?.id;
const readOnly = !isOwner && isGuest;
if (!inboxIssue) return <></>;
const isIssueDisabled = [-1, 1, 2].includes(inboxIssue.status);
return (
<>
<div className="w-full h-full overflow-hidden relative flex flex-col">
<div className="flex-shrink-0 min-h-[52px] z-[11]">
<InboxIssueActionsHeader
setIsMobileSidebar={setIsMobileSidebar}
isMobileSidebar={isMobileSidebar}
workspaceSlug={workspaceSlug}
projectId={projectId}
inboxIssue={inboxIssue}
isSubmitting={isSubmitting}
isNotificationEmbed={isNotificationEmbed || false}
embedRemoveCurrentNotification={embedRemoveCurrentNotification}
/>
</div>
<ContentWrapper className="space-y-5 divide-y-2 divide-custom-border-200">
<InboxIssueMainContent
workspaceSlug={workspaceSlug}
projectId={projectId}
inboxIssue={inboxIssue}
isEditable={isEditable && !isIssueDisabled && !readOnly}
isSubmitting={isSubmitting}
setIsSubmitting={setIsSubmitting}
/>
</ContentWrapper>
</div>
</>
);
});