import { useRouter } from "next/router";
// icons
import {
CalendarDays,
CopyPlus,
History,
LinkIcon,
MessageSquare,
Paperclip,
Rocket,
Signal,
Tag,
Users2,
} from "lucide-react";
import {
DoubleCircleIcon,
Tooltip,
BlockedIcon,
BlockerIcon,
RelatedIcon,
UserGroupIcon,
ArchiveIcon,
ContrastIcon,
LayersIcon,
DiceIcon,
} from "@plane/ui";
// helpers
import { renderShortDateWithYearFormat } from "helpers/date-time.helper";
import { capitalizeFirstLetter } from "helpers/string.helper";
// types
import { IIssueActivity } from "types";
const IssueLink = ({ activity }: { activity: IIssueActivity }) => (
);
const UserLink = ({ activity }: { activity: IIssueActivity }) => (
);
const activityDetails: {
[key: string]: {
message: (activity: IIssueActivity, showIssue: boolean, workspaceSlug: string) => React.ReactNode;
icon: React.ReactNode;
};
} = {
assignees: {
message: (activity, showIssue) => (
<>
{activity.old_value === "" ? "added a new assignee " : "removed the assignee "}
{showIssue && (
<>
{" "}
to
>
)}
.
>
),
icon: ,
},
archived_at: {
message: (activity) => {
if (activity.new_value === "restore") return "restored the issue.";
else return "archived the issue.";
},
icon: ,
},
attachment: {
message: (activity, showIssue) => (
<>
{activity.verb === "created" ? "uploaded a new " : "removed an "}
{activity.new_value && activity.new_value !== "" ? (
) : (
"attachment"
)}
{showIssue && activity.verb === "created" ? " to " : " from "}
{showIssue && }
>
),
icon: ,
},
blocking: {
message: (activity) => (
<>
{activity.old_value === "" ? "marked this issue is blocking issue " : "removed the blocking issue "}
.
>
),
icon: ,
},
blocked_by: {
message: (activity) => (
<>
{activity.old_value === ""
? "marked this issue is being blocked by issue "
: "removed this issue being blocked by issue "}
.
>
),
icon: ,
},
duplicate: {
message: (activity) => (
<>
{activity.old_value === "" ? "marked this issue as duplicate of " : "removed this issue as a duplicate of "}
.
>
),
icon: ,
},
relates_to: {
message: (activity) => (
<>
{activity.old_value === "" ? "marked that this issue relates to " : "removed the relation from "}
.
>
),
icon: ,
},
cycles: {
message: (activity) => (
<>
{activity.verb === "created" && "added this issue to the cycle "}
{activity.verb === "updated" && "set the cycle to "}
{activity.verb === "deleted" && "removed the issue from the cycle "}
>
),
icon: ,
},
description: {
message: (activity, showIssue) => (
<>
updated the description
{showIssue && (
<>
{" "}
of
>
)}
.
>
),
icon: ,
},
estimate_point: {
message: (activity, showIssue) => (
<>
{activity.new_value ? "set the estimate point to " : "removed the estimate point "}
{activity.new_value && {activity.new_value}}
{showIssue && (
<>
{" "}
for
>
)}
>
),
icon: ,
},
issue: {
message: (activity) => {
if (activity.verb === "created") return "created the issue.";
else return "deleted an issue.";
},
icon: ,
},
labels: {
message: (activity, showIssue) => (
<>
{activity.old_value === "" ? "added a new label " : "removed the label "}
{activity.old_value === "" ? activity.new_value : activity.old_value}
{showIssue && (
<>
{" "}
to
>
)}
>
),
icon: ,
},
link: {
message: (activity, showIssue) => (
<>
{activity.verb === "created" && "added this "}
{activity.verb === "updated" && "updated this "}
{activity.verb === "deleted" && "removed this "}
{showIssue && (
<>
{" "}
to
>
)}
.
>
),
icon: ,
},
modules: {
message: (activity) => (
<>
{activity.verb === "created" && "added this "}
{activity.verb === "updated" && "updated this "}
{activity.verb === "deleted" && "removed this "}
module{" "}
.
>
),
icon: ,
},
name: {
message: (activity, showIssue) => (
<>
set the name to {activity.new_value}
{showIssue && (
<>
{" "}
of
>
)}
.
>
),
icon: ,
},
parent: {
message: (activity, showIssue) => (
<>
{activity.new_value ? "set the parent to " : "removed the parent "}
{showIssue && (
<>
{" "}
for
>
)}
.
>
),
icon: ,
},
priority: {
message: (activity, showIssue) => (
<>
set the priority to{" "}
{activity.new_value ? capitalizeFirstLetter(activity.new_value) : "None"}
{showIssue && (
<>
{" "}
for
>
)}
.
>
),
icon: ,
},
start_date: {
message: (activity, showIssue) => (
<>
{activity.new_value ? "set the start date to " : "removed the start date "}
{activity.new_value ? renderShortDateWithYearFormat(activity.new_value) : "None"}
{showIssue && (
<>
{" "}
for
>
)}
>
),
icon: ,
},
state: {
message: (activity, showIssue) => (
<>
set the state to {activity.new_value}
{showIssue && (
<>
{" "}
for
>
)}
.
>
),
icon: ,
},
target_date: {
message: (activity, showIssue) => (
<>
{activity.new_value ? "set the target date to " : "removed the target date "}
{activity.new_value && (
{renderShortDateWithYearFormat(activity.new_value)}
)}
{showIssue && (
<>
{" "}
for
>
)}
>
),
icon: ,
},
};
export const ActivityIcon = ({ activity }: { activity: IIssueActivity }) => (
<>{activityDetails[activity.field as keyof typeof activityDetails]?.icon}>
);
export const ActivityMessage = ({ activity, showIssue = false }: { activity: IIssueActivity; showIssue?: boolean }) => {
const router = useRouter();
const { workspaceSlug } = router.query;
return (
<>
{activityDetails[activity.field as keyof typeof activityDetails]?.message(
activity,
showIssue,
workspaceSlug?.toString() ?? ""
)}
>
);
};