import { useRouter } from "next/router";
import { useEffect } from "react";
import { observer } from "mobx-react-lite";
// store hooks
import { useEstimate, useLabel } from "hooks/store";
// icons
import { Tooltip, BlockedIcon, BlockerIcon, RelatedIcon, LayersIcon, DiceIcon } from "@plane/ui";
import {
TagIcon,
CopyPlus,
Calendar,
Link2Icon,
Users2Icon,
ArchiveIcon,
PaperclipIcon,
ContrastIcon,
TriangleIcon,
LayoutGridIcon,
SignalMediumIcon,
MessageSquareIcon,
UsersIcon,
} from "lucide-react";
// helpers
import { renderFormattedDate } from "helpers/date-time.helper";
import { capitalizeFirstLetter } from "helpers/string.helper";
// types
import { IIssueActivity } from "@plane/types";
const IssueLink = ({ activity }: { activity: IIssueActivity }) => {
const router = useRouter();
const { workspaceSlug } = router.query;
return (
{activity.issue_detail ? `${activity.project_detail.identifier}-${activity.issue_detail.sequence_id}` : "Issue"}{" "}
{activity.issue_detail?.name}
);
};
const UserLink = ({ activity }: { activity: IIssueActivity }) => {
const router = useRouter();
const { workspaceSlug } = router.query;
return (
{activity.new_value && activity.new_value !== "" ? activity.new_value : activity.old_value}
);
};
const LabelPill = observer(({ labelId, workspaceSlug }: { labelId: string; workspaceSlug: string }) => {
// store hooks
const { workspaceLabels, fetchWorkspaceLabels } = useLabel();
useEffect(() => {
if (!workspaceLabels) fetchWorkspaceLabels(workspaceSlug);
}, [fetchWorkspaceLabels, workspaceLabels, workspaceSlug]);
return (
l.id === labelId)?.color ?? "#000000",
}}
aria-hidden="true"
/>
);
});
const EstimatePoint = observer((props: { point: string }) => {
const { point } = props;
const { areEstimatesEnabledForCurrentProject, getEstimatePointValue } = useEstimate();
const currentPoint = Number(point) + 1;
const estimateValue = getEstimatePointValue(Number(point));
return (
{areEstimatesEnabledForCurrentProject
? estimateValue
: `${currentPoint} ${currentPoint > 1 ? "points" : "point"}`}
);
});
const activityDetails: {
[key: string]: {
message: (activity: IIssueActivity, showIssue: boolean, workspaceSlug: string) => React.ReactNode;
icon: React.ReactNode;
};
} = {
assignees: {
message: (activity, showIssue) => {
if (activity.old_value === "")
return (
<>
added a new assignee
{showIssue && (
<>
{" "}
to
>
)}
.
>
);
else
return (
<>
removed the assignee
{showIssue && (
<>
{" "}
from
>
)}
.
>
);
},
icon: ,
},
archived_at: {
message: (activity) => {
if (activity.new_value === "restore") return "restored the issue.";
else return "archived the issue.";
},
icon: ,
},
attachment: {
message: (activity, showIssue) => {
if (activity.verb === "created")
return (
<>
uploaded a new{" "}
attachment
{showIssue && (
<>
{" "}
to
>
)}
>
);
else
return (
<>
removed an attachment
{showIssue && (
<>
{" "}
from
>
)}
.
>
);
},
icon: ,
},
blocking: {
message: (activity) => {
if (activity.old_value === "")
return (
<>
marked this issue is blocking issue{" "}
{activity.new_value}.
>
);
else
return (
<>
removed the blocking issue {activity.old_value}.
>
);
},
icon: ,
},
blocked_by: {
message: (activity) => {
if (activity.old_value === "")
return (
<>
marked this issue is being blocked by{" "}
{activity.new_value}.
>
);
else
return (
<>
removed this issue being blocked by issue{" "}
{activity.old_value}.
>
);
},
icon: ,
},
cycles: {
message: (activity, showIssue, workspaceSlug) => {
if (activity.verb === "created")
return (
<>
added this issue to the cycle
{activity.new_value}
>
);
else if (activity.verb === "updated")
return (
<>
set the cycle to
{activity.new_value}
>
);
else
return (
<>
removed the issue from the cycle{" "}
{activity.old_value}
>
);
},
icon: ,
},
duplicate: {
message: (activity) => {
if (activity.old_value === "")
return (
<>
marked this issue as duplicate of{" "}
{activity.new_value}.
>
);
else
return (
<>
removed this issue as a duplicate of{" "}
{activity.old_value}.
>
);
},
icon: ,
},
description: {
message: (activity, showIssue) => (
<>
updated the description
{showIssue && (
<>
{" "}
of
>
)}
.
>
),
icon: ,
},
estimate_point: {
message: (activity, showIssue) => {
if (!activity.new_value)
return (
<>
removed the estimate point
{showIssue && (
<>
{" "}
from
>
)}
.
>
);
else
return (
<>
set the estimate point to
{showIssue && (
<>
{" "}
for
>
)}
.
>
);
},
icon: ,
},
issue: {
message: (activity) => {
if (activity.verb === "created") return "created the issue.";
else return "deleted an issue.";
},
icon: ,
},
labels: {
message: (activity, showIssue, workspaceSlug) => {
if (activity.old_value === "")
return (
<>
added a new label{" "}
{activity.new_value}
{showIssue && (
{" "}
to
)}
>
);
else
return (
<>
removed the label{" "}
{activity.old_value}
{showIssue && (
{" "}
from
)}
>
);
},
icon: ,
},
link: {
message: (activity, showIssue) => {
if (activity.verb === "created")
return (
<>
added this{" "}
link
{showIssue && (
<>
{" "}
to
>
)}
.
>
);
else if (activity.verb === "updated")
return (
<>
updated the{" "}
link
{showIssue && (
<>
{" "}
from
>
)}
.
>
);
else
return (
<>
removed this{" "}
link
{showIssue && (
<>
{" "}
from
>
)}
.
>
);
},
icon: ,
},
modules: {
message: (activity, showIssue, workspaceSlug) => {
if (activity.verb === "created")
return (
<>
added this issue to the module{" "}
{activity.new_value}
>
);
else if (activity.verb === "updated")
return (
<>
set the module to{" "}
{activity.new_value}
>
);
else
return (
<>
removed the issue from the module{" "}
{activity.old_value}
>
);
},
icon: ,
},
name: {
message: (activity, showIssue) => (
<>
set the name to {activity.new_value}
{showIssue && (
<>
{" "}
of
>
)}
.
>
),
icon: ,
},
parent: {
message: (activity, showIssue) => {
if (!activity.new_value)
return (
<>
removed the parent {activity.old_value}
{showIssue && (
<>
{" "}
from
>
)}
.
>
);
else
return (
<>
set the parent to {activity.new_value}
{showIssue && (
<>
{" "}
for
>
)}
.
>
);
},
icon: ,
},
priority: {
message: (activity, showIssue) => (
<>
set the priority to{" "}
{activity.new_value ? capitalizeFirstLetter(activity.new_value) : "None"}
{showIssue && (
<>
{" "}
for
>
)}
.
>
),
icon: ,
},
relates_to: {
message: (activity) => {
if (activity.old_value === "")
return (
<>
marked that this issue relates to{" "}
{activity.new_value}.
>
);
else
return (
<>
removed the relation from {activity.old_value}.
>
);
},
icon: ,
},
start_date: {
message: (activity, showIssue) => {
if (!activity.new_value)
return (
<>
removed the start date
{showIssue && (
<>
{" "}
from
>
)}
.
>
);
else
return (
<>
set the start date to{" "}
{renderFormattedDate(activity.new_value)}
{showIssue && (
<>
{" "}
for
>
)}
.
>
);
},
icon: ,
},
state: {
message: (activity, showIssue) => (
<>
set the state to {activity.new_value}
{showIssue && (
<>
{" "}
for
>
)}
.
>
),
icon: ,
},
target_date: {
message: (activity, showIssue) => {
if (!activity.new_value)
return (
<>
removed the due date
{showIssue && (
<>
{" "}
from
>
)}
.
>
);
else
return (
<>
set the due date to{" "}
{renderFormattedDate(activity.new_value)}
{showIssue && (
<>
{" "}
for
>
)}
.
>
);
},
icon: ,
},
};
export const ActivityIcon = ({ activity }: { activity: IIssueActivity }) => (
<>{activityDetails[activity.field as keyof typeof activityDetails]?.icon}>
);
type ActivityMessageProps = {
activity: IIssueActivity;
showIssue?: boolean;
};
export const ActivityMessage = ({ activity, showIssue = false }: ActivityMessageProps) => {
const router = useRouter();
const { workspaceSlug } = router.query;
return (
<>
{activityDetails[activity.field as keyof typeof activityDetails]?.message(
activity,
showIssue,
workspaceSlug ? workspaceSlug.toString() : activity.workspace_detail?.slug ?? ""
)}
>
);
};