import { useRouter } from "next/router";
// icons
import { Icon, Tooltip } from "components/ui";
import { CopyPlus } from "lucide-react";
import { Squares2X2Icon } from "@heroicons/react/24/outline";
import { BlockedIcon, BlockerIcon, RelatedIcon } from "components/icons";
// 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 router = useRouter();
const { workspaceSlug } = router.query;
return (
{activity.issue_detail
? `${activity.project_detail.identifier}-${activity.issue_detail.sequence_id}`
: "Issue"}
);
};
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 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: ,
},
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: ,
},
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: ,
},
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: ,
},
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{" "}
{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) => {
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: ,
},
start_date: {
message: (activity, showIssue) => {
if (!activity.new_value)
return (
<>
removed the start date
{showIssue && (
<>
{" "}
from
>
)}
.
>
);
else
return (
<>
set the start date to{" "}
{renderShortDateWithYearFormat(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{" "}
{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() ?? ""
)}
>
);
};