2024-01-23 07:58:58 +00:00
|
|
|
import { FC, useMemo, useState } from "react";
|
|
|
|
import { observer } from "mobx-react-lite";
|
2024-04-23 07:22:31 +00:00
|
|
|
import { History, LucideIcon, MessageCircle } from "lucide-react";
|
2024-04-11 15:58:59 +00:00
|
|
|
// types
|
2024-03-19 14:38:35 +00:00
|
|
|
import { TIssueComment } from "@plane/types";
|
2024-03-06 08:48:41 +00:00
|
|
|
// ui
|
2024-04-11 15:58:59 +00:00
|
|
|
import { TOAST_TYPE, setToast } from "@plane/ui";
|
2024-01-23 07:58:58 +00:00
|
|
|
// components
|
2024-04-23 07:22:31 +00:00
|
|
|
import { IssueActivityCommentRoot, IssueCommentRoot, IssueCommentCreate } from "@/components/issues";
|
2024-04-11 15:58:59 +00:00
|
|
|
// hooks
|
|
|
|
import { useIssueDetail, useProject } from "@/hooks/store";
|
2024-01-23 07:58:58 +00:00
|
|
|
|
|
|
|
type TIssueActivity = {
|
|
|
|
workspaceSlug: string;
|
|
|
|
projectId: string;
|
|
|
|
issueId: string;
|
2024-04-03 12:32:07 +00:00
|
|
|
disabled?: boolean;
|
2024-01-23 07:58:58 +00:00
|
|
|
};
|
|
|
|
|
2024-04-23 07:22:31 +00:00
|
|
|
type TActivityTabs = "all" | "comments";
|
2024-01-23 07:58:58 +00:00
|
|
|
|
|
|
|
const activityTabs: { key: TActivityTabs; title: string; icon: LucideIcon }[] = [
|
|
|
|
{
|
|
|
|
key: "comments",
|
|
|
|
title: "Comments",
|
|
|
|
icon: MessageCircle,
|
|
|
|
},
|
2024-04-23 07:22:31 +00:00
|
|
|
{
|
|
|
|
key: "all",
|
|
|
|
title: "All activity",
|
|
|
|
icon: History,
|
|
|
|
},
|
2024-01-23 07:58:58 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
export type TActivityOperations = {
|
|
|
|
createComment: (data: Partial<TIssueComment>) => Promise<void>;
|
|
|
|
updateComment: (commentId: string, data: Partial<TIssueComment>) => Promise<void>;
|
|
|
|
removeComment: (commentId: string) => Promise<void>;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const IssueActivity: FC<TIssueActivity> = observer((props) => {
|
2024-04-03 12:32:07 +00:00
|
|
|
const { workspaceSlug, projectId, issueId, disabled = false } = props;
|
2024-01-23 07:58:58 +00:00
|
|
|
// hooks
|
|
|
|
const { createComment, updateComment, removeComment } = useIssueDetail();
|
|
|
|
const { getProjectById } = useProject();
|
|
|
|
// state
|
2024-04-23 07:22:31 +00:00
|
|
|
const [activityTab, setActivityTab] = useState<TActivityTabs>("comments");
|
2024-01-23 07:58:58 +00:00
|
|
|
|
|
|
|
const activityOperations: TActivityOperations = useMemo(
|
|
|
|
() => ({
|
|
|
|
createComment: async (data: Partial<TIssueComment>) => {
|
|
|
|
try {
|
|
|
|
if (!workspaceSlug || !projectId || !issueId) throw new Error("Missing fields");
|
|
|
|
await createComment(workspaceSlug, projectId, issueId, data);
|
2024-03-06 08:48:41 +00:00
|
|
|
setToast({
|
2024-05-07 09:33:24 +00:00
|
|
|
title: "Success!",
|
2024-03-06 08:48:41 +00:00
|
|
|
type: TOAST_TYPE.SUCCESS,
|
2024-01-23 07:58:58 +00:00
|
|
|
message: "Comment created successfully.",
|
|
|
|
});
|
|
|
|
} catch (error) {
|
2024-03-06 08:48:41 +00:00
|
|
|
setToast({
|
2024-05-07 09:33:24 +00:00
|
|
|
title: "Error!",
|
2024-03-06 08:48:41 +00:00
|
|
|
type: TOAST_TYPE.ERROR,
|
2024-01-23 07:58:58 +00:00
|
|
|
message: "Comment creation failed. Please try again later.",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
updateComment: async (commentId: string, data: Partial<TIssueComment>) => {
|
|
|
|
try {
|
|
|
|
if (!workspaceSlug || !projectId || !issueId) throw new Error("Missing fields");
|
|
|
|
await updateComment(workspaceSlug, projectId, issueId, commentId, data);
|
2024-03-06 08:48:41 +00:00
|
|
|
setToast({
|
2024-05-07 09:33:24 +00:00
|
|
|
title: "Success!",
|
2024-03-06 08:48:41 +00:00
|
|
|
type: TOAST_TYPE.SUCCESS,
|
2024-01-23 07:58:58 +00:00
|
|
|
message: "Comment updated successfully.",
|
|
|
|
});
|
|
|
|
} catch (error) {
|
2024-03-06 08:48:41 +00:00
|
|
|
setToast({
|
2024-05-07 09:33:24 +00:00
|
|
|
title: "Error!",
|
2024-03-06 08:48:41 +00:00
|
|
|
type: TOAST_TYPE.ERROR,
|
2024-01-23 07:58:58 +00:00
|
|
|
message: "Comment update failed. Please try again later.",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
removeComment: async (commentId: string) => {
|
|
|
|
try {
|
|
|
|
if (!workspaceSlug || !projectId || !issueId) throw new Error("Missing fields");
|
|
|
|
await removeComment(workspaceSlug, projectId, issueId, commentId);
|
2024-03-06 08:48:41 +00:00
|
|
|
setToast({
|
2024-05-07 09:33:24 +00:00
|
|
|
title: "Success!",
|
2024-03-06 08:48:41 +00:00
|
|
|
type: TOAST_TYPE.SUCCESS,
|
2024-01-23 07:58:58 +00:00
|
|
|
message: "Comment removed successfully.",
|
|
|
|
});
|
|
|
|
} catch (error) {
|
2024-03-06 08:48:41 +00:00
|
|
|
setToast({
|
2024-05-07 09:33:24 +00:00
|
|
|
title: "Error!",
|
2024-03-06 08:48:41 +00:00
|
|
|
type: TOAST_TYPE.ERROR,
|
2024-01-23 07:58:58 +00:00
|
|
|
message: "Comment remove failed. Please try again later.",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}),
|
2024-03-06 08:48:41 +00:00
|
|
|
[workspaceSlug, projectId, issueId, createComment, updateComment, removeComment]
|
2024-01-23 07:58:58 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const project = getProjectById(projectId);
|
|
|
|
if (!project) return <></>;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="space-y-3 pt-3">
|
|
|
|
{/* header */}
|
|
|
|
<div className="text-lg text-custom-text-100">Activity</div>
|
|
|
|
|
|
|
|
{/* rendering activity */}
|
|
|
|
<div className="space-y-3">
|
|
|
|
<div className="relative flex items-center gap-1">
|
|
|
|
{activityTabs.map((tab) => (
|
|
|
|
<div
|
|
|
|
key={tab.key}
|
|
|
|
className={`relative flex items-center px-2 py-1.5 gap-1 cursor-pointer transition-all rounded
|
|
|
|
${
|
|
|
|
tab.key === activityTab
|
|
|
|
? `text-custom-text-100 bg-custom-background-80`
|
|
|
|
: `text-custom-text-200 hover:bg-custom-background-80`
|
|
|
|
}`}
|
|
|
|
onClick={() => setActivityTab(tab.key)}
|
|
|
|
>
|
|
|
|
<div className="flex-shrink-0 w-4 h-4 flex justify-center items-center">
|
|
|
|
<tab.icon className="w-3 h-3" />
|
|
|
|
</div>
|
|
|
|
<div className="text-sm">{tab.title}</div>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="min-h-[200px]">
|
|
|
|
{activityTab === "all" ? (
|
|
|
|
<div className="space-y-3">
|
|
|
|
<IssueActivityCommentRoot
|
2024-04-11 15:58:59 +00:00
|
|
|
projectId={projectId}
|
2024-01-23 07:58:58 +00:00
|
|
|
workspaceSlug={workspaceSlug}
|
|
|
|
issueId={issueId}
|
|
|
|
activityOperations={activityOperations}
|
|
|
|
showAccessSpecifier={project.is_deployed}
|
2024-04-03 12:32:07 +00:00
|
|
|
disabled={disabled}
|
2024-01-23 07:58:58 +00:00
|
|
|
/>
|
2024-04-03 12:32:07 +00:00
|
|
|
{!disabled && (
|
|
|
|
<IssueCommentCreate
|
2024-05-02 12:52:00 +00:00
|
|
|
issueId={issueId}
|
2024-04-11 15:58:59 +00:00
|
|
|
projectId={projectId}
|
2024-04-03 12:32:07 +00:00
|
|
|
workspaceSlug={workspaceSlug}
|
|
|
|
activityOperations={activityOperations}
|
|
|
|
showAccessSpecifier={project.is_deployed}
|
|
|
|
/>
|
|
|
|
)}
|
2024-01-23 07:58:58 +00:00
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div className="space-y-3">
|
|
|
|
<IssueCommentRoot
|
2024-04-11 15:58:59 +00:00
|
|
|
projectId={projectId}
|
2024-01-23 07:58:58 +00:00
|
|
|
workspaceSlug={workspaceSlug}
|
|
|
|
issueId={issueId}
|
|
|
|
activityOperations={activityOperations}
|
|
|
|
showAccessSpecifier={project.is_deployed}
|
2024-04-03 12:32:07 +00:00
|
|
|
disabled={disabled}
|
2024-01-23 07:58:58 +00:00
|
|
|
/>
|
2024-04-03 12:32:07 +00:00
|
|
|
{!disabled && (
|
|
|
|
<IssueCommentCreate
|
2024-05-02 12:52:00 +00:00
|
|
|
issueId={issueId}
|
2024-04-11 15:58:59 +00:00
|
|
|
projectId={projectId}
|
2024-04-03 12:32:07 +00:00
|
|
|
workspaceSlug={workspaceSlug}
|
|
|
|
activityOperations={activityOperations}
|
|
|
|
showAccessSpecifier={project.is_deployed}
|
|
|
|
/>
|
|
|
|
)}
|
2024-01-23 07:58:58 +00:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|