2024-01-24 15:03:54 +00:00
|
|
|
import { FC, useMemo } from "react";
|
2024-02-05 07:49:07 +00:00
|
|
|
import { useRouter } from "next/router";
|
2024-01-24 15:03:54 +00:00
|
|
|
import useSWR from "swr";
|
|
|
|
// components
|
2024-03-06 13:09:14 +00:00
|
|
|
import { TOAST_TYPE, setToast } from "@plane/ui";
|
|
|
|
import { EUserProjectRoles } from "constants/project";
|
2024-02-05 07:49:07 +00:00
|
|
|
import { useEventTracker, useInboxIssues, useIssueDetail, useUser } from "hooks/store";
|
2024-03-06 08:48:41 +00:00
|
|
|
// ui
|
2024-01-24 15:03:54 +00:00
|
|
|
// types
|
|
|
|
import { TIssue } from "@plane/types";
|
|
|
|
import { TIssueOperations } from "../root";
|
2024-03-06 13:09:14 +00:00
|
|
|
import { InboxIssueMainContent } from "./main-content";
|
|
|
|
import { InboxIssueDetailsSidebar } from "./sidebar";
|
2024-01-24 15:03:54 +00:00
|
|
|
// constants
|
|
|
|
|
|
|
|
export type TInboxIssueDetailRoot = {
|
|
|
|
workspaceSlug: string;
|
|
|
|
projectId: string;
|
|
|
|
inboxId: string;
|
|
|
|
issueId: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const InboxIssueDetailRoot: FC<TInboxIssueDetailRoot> = (props) => {
|
|
|
|
const { workspaceSlug, projectId, inboxId, issueId } = props;
|
2024-02-05 07:49:07 +00:00
|
|
|
// router
|
|
|
|
const router = useRouter();
|
2024-01-24 15:03:54 +00:00
|
|
|
// hooks
|
|
|
|
const {
|
|
|
|
issues: { fetchInboxIssueById, updateInboxIssue, removeInboxIssue },
|
|
|
|
} = useInboxIssues();
|
|
|
|
const {
|
|
|
|
issue: { getIssueById },
|
2024-02-28 09:53:45 +00:00
|
|
|
fetchActivities,
|
|
|
|
fetchComments,
|
2024-01-24 15:03:54 +00:00
|
|
|
} = useIssueDetail();
|
2024-02-05 07:49:07 +00:00
|
|
|
const { captureIssueEvent } = useEventTracker();
|
2024-01-24 15:03:54 +00:00
|
|
|
const {
|
|
|
|
membership: { currentProjectRole },
|
|
|
|
} = useUser();
|
|
|
|
|
|
|
|
const issueOperations: TIssueOperations = useMemo(
|
|
|
|
() => ({
|
|
|
|
fetch: async (workspaceSlug: string, projectId: string, issueId: string) => {
|
|
|
|
try {
|
|
|
|
await fetchInboxIssueById(workspaceSlug, projectId, inboxId, issueId);
|
|
|
|
} catch (error) {
|
|
|
|
console.error("Error fetching the parent issue");
|
|
|
|
}
|
|
|
|
},
|
2024-03-06 13:09:14 +00:00
|
|
|
update: async (workspaceSlug: string, projectId: string, issueId: string, data: Partial<TIssue>) => {
|
2024-01-24 15:03:54 +00:00
|
|
|
try {
|
2024-02-27 11:28:46 +00:00
|
|
|
await updateInboxIssue(workspaceSlug, projectId, inboxId, issueId, data);
|
2024-02-05 07:49:07 +00:00
|
|
|
captureIssueEvent({
|
|
|
|
eventName: "Inbox issue updated",
|
2024-02-27 11:28:46 +00:00
|
|
|
payload: { ...data, state: "SUCCESS", element: "Inbox" },
|
2024-02-05 07:49:07 +00:00
|
|
|
updates: {
|
|
|
|
changed_property: Object.keys(data).join(","),
|
|
|
|
change_details: Object.values(data).join(","),
|
|
|
|
},
|
|
|
|
path: router.asPath,
|
|
|
|
});
|
2024-01-24 15:03:54 +00:00
|
|
|
} catch (error) {
|
2024-03-06 08:48:41 +00:00
|
|
|
setToast({
|
2024-01-24 15:03:54 +00:00
|
|
|
title: "Issue update failed",
|
2024-03-06 08:48:41 +00:00
|
|
|
type: TOAST_TYPE.ERROR,
|
2024-01-24 15:03:54 +00:00
|
|
|
message: "Issue update failed",
|
|
|
|
});
|
2024-02-05 07:49:07 +00:00
|
|
|
captureIssueEvent({
|
|
|
|
eventName: "Inbox issue updated",
|
|
|
|
payload: { state: "SUCCESS", element: "Inbox" },
|
|
|
|
updates: {
|
|
|
|
changed_property: Object.keys(data).join(","),
|
|
|
|
change_details: Object.values(data).join(","),
|
|
|
|
},
|
|
|
|
path: router.asPath,
|
|
|
|
});
|
2024-01-24 15:03:54 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
remove: async (workspaceSlug: string, projectId: string, issueId: string) => {
|
|
|
|
try {
|
|
|
|
await removeInboxIssue(workspaceSlug, projectId, inboxId, issueId);
|
2024-03-06 08:48:41 +00:00
|
|
|
setToast({
|
2024-01-24 15:03:54 +00:00
|
|
|
title: "Issue deleted successfully",
|
2024-03-06 08:48:41 +00:00
|
|
|
type: TOAST_TYPE.SUCCESS,
|
2024-01-24 15:03:54 +00:00
|
|
|
message: "Issue deleted successfully",
|
|
|
|
});
|
2024-02-05 07:49:07 +00:00
|
|
|
captureIssueEvent({
|
|
|
|
eventName: "Inbox issue deleted",
|
|
|
|
payload: { id: issueId, state: "SUCCESS", element: "Inbox" },
|
|
|
|
path: router.asPath,
|
|
|
|
});
|
2024-01-24 15:03:54 +00:00
|
|
|
} catch (error) {
|
2024-02-05 07:49:07 +00:00
|
|
|
captureIssueEvent({
|
|
|
|
eventName: "Inbox issue deleted",
|
|
|
|
payload: { id: issueId, state: "FAILED", element: "Inbox" },
|
|
|
|
path: router.asPath,
|
|
|
|
});
|
2024-03-06 08:48:41 +00:00
|
|
|
setToast({
|
2024-01-24 15:03:54 +00:00
|
|
|
title: "Issue delete failed",
|
2024-03-06 08:48:41 +00:00
|
|
|
type: TOAST_TYPE.ERROR,
|
2024-01-24 15:03:54 +00:00
|
|
|
message: "Issue delete failed",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}),
|
2024-03-06 08:48:41 +00:00
|
|
|
[inboxId, fetchInboxIssueById, updateInboxIssue, removeInboxIssue]
|
2024-01-24 15:03:54 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
useSWR(
|
|
|
|
workspaceSlug && projectId && inboxId && issueId
|
|
|
|
? `INBOX_ISSUE_DETAIL_${workspaceSlug}_${projectId}_${inboxId}_${issueId}`
|
|
|
|
: null,
|
|
|
|
async () => {
|
|
|
|
if (workspaceSlug && projectId && inboxId && issueId) {
|
|
|
|
await issueOperations.fetch(workspaceSlug, projectId, issueId);
|
2024-02-28 09:53:45 +00:00
|
|
|
await fetchActivities(workspaceSlug, projectId, issueId);
|
|
|
|
await fetchComments(workspaceSlug, projectId, issueId);
|
2024-01-24 15:03:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
// checking if issue is editable, based on user role
|
|
|
|
const is_editable = !!currentProjectRole && currentProjectRole >= EUserProjectRoles.MEMBER;
|
|
|
|
|
|
|
|
// issue details
|
|
|
|
const issue = getIssueById(issueId);
|
|
|
|
|
2024-01-25 08:11:02 +00:00
|
|
|
if (!issue) return <></>;
|
2024-01-24 15:03:54 +00:00
|
|
|
return (
|
2024-01-25 08:11:02 +00:00
|
|
|
<div className="flex h-full overflow-hidden">
|
2024-02-21 12:22:35 +00:00
|
|
|
<div className="h-full w-2/3 space-y-5 divide-y-2 divide-custom-border-300 overflow-y-auto p-5 vertical-scrollbar scrollbar-md">
|
2024-01-25 08:11:02 +00:00
|
|
|
<InboxIssueMainContent
|
|
|
|
workspaceSlug={workspaceSlug}
|
|
|
|
projectId={projectId}
|
|
|
|
inboxId={inboxId}
|
|
|
|
issueId={issueId}
|
|
|
|
issueOperations={issueOperations}
|
|
|
|
is_editable={is_editable}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="h-full w-1/3 space-y-5 overflow-hidden border-l border-custom-border-300 py-5">
|
|
|
|
<InboxIssueDetailsSidebar
|
|
|
|
workspaceSlug={workspaceSlug}
|
|
|
|
projectId={projectId}
|
|
|
|
issueId={issueId}
|
|
|
|
issueOperations={issueOperations}
|
|
|
|
is_editable={is_editable}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-01-24 15:03:54 +00:00
|
|
|
);
|
|
|
|
};
|