2022-11-24 13:48:18 +00:00
|
|
|
// next
|
|
|
|
import Image from "next/image";
|
2022-12-03 13:41:07 +00:00
|
|
|
// ui
|
|
|
|
import { Spinner } from "ui";
|
|
|
|
// icons
|
2022-11-24 13:48:18 +00:00
|
|
|
import {
|
2022-11-30 15:58:45 +00:00
|
|
|
CalendarDaysIcon,
|
2022-11-24 13:48:18 +00:00
|
|
|
ChartBarIcon,
|
|
|
|
ChatBubbleBottomCenterTextIcon,
|
|
|
|
Squares2X2Icon,
|
2022-12-03 13:41:07 +00:00
|
|
|
UserIcon,
|
2022-11-24 13:48:18 +00:00
|
|
|
} from "@heroicons/react/24/outline";
|
2022-12-03 13:41:07 +00:00
|
|
|
// types
|
|
|
|
import { IssueResponse, IState } from "types";
|
|
|
|
// constants
|
2022-11-24 13:48:18 +00:00
|
|
|
import { addSpaceIfCamelCase, timeAgo } from "constants/common";
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
issueActivities: any[] | undefined;
|
|
|
|
states: IState[] | undefined;
|
2022-12-03 13:41:07 +00:00
|
|
|
issues: IssueResponse | undefined;
|
2022-11-24 13:48:18 +00:00
|
|
|
};
|
|
|
|
|
2022-12-01 14:29:21 +00:00
|
|
|
const activityIcons: {
|
|
|
|
[key: string]: JSX.Element;
|
|
|
|
} = {
|
2022-11-24 13:48:18 +00:00
|
|
|
state: <Squares2X2Icon className="h-4 w-4" />,
|
|
|
|
priority: <ChartBarIcon className="h-4 w-4" />,
|
|
|
|
name: <ChatBubbleBottomCenterTextIcon className="h-4 w-4" />,
|
|
|
|
description: <ChatBubbleBottomCenterTextIcon className="h-4 w-4" />,
|
2022-11-30 15:58:45 +00:00
|
|
|
target_date: <CalendarDaysIcon className="h-4 w-4" />,
|
2022-12-03 13:41:07 +00:00
|
|
|
parent: <UserIcon className="h-4 w-4" />,
|
2022-11-24 13:48:18 +00:00
|
|
|
};
|
|
|
|
|
2022-12-03 13:41:07 +00:00
|
|
|
const IssueActivitySection: React.FC<Props> = ({ issueActivities, states, issues }) => {
|
2022-11-24 13:48:18 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{issueActivities ? (
|
|
|
|
<div className="space-y-3">
|
2022-12-01 14:29:21 +00:00
|
|
|
{issueActivities.map((activity, index) => {
|
2022-11-24 13:48:18 +00:00
|
|
|
if (activity.field !== "updated_by")
|
|
|
|
return (
|
|
|
|
<div key={activity.id} className="relative flex gap-x-2 w-full">
|
2022-12-01 14:29:21 +00:00
|
|
|
{issueActivities.length > 1 && index !== issueActivities.length - 1 ? (
|
2022-11-24 13:48:18 +00:00
|
|
|
<span
|
|
|
|
className="absolute top-5 left-2.5 h-full w-0.5 bg-gray-200"
|
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
{activity.field ? (
|
|
|
|
<div className="relative z-10 flex-shrink-0 -ml-1">
|
|
|
|
<div
|
|
|
|
className={`h-7 w-7 bg-gray-700 text-white border-2 border-white grid place-items-center rounded-full`}
|
|
|
|
>
|
|
|
|
{activityIcons[activity.field as keyof typeof activityIcons]}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
) : (
|
2022-11-29 14:19:39 +00:00
|
|
|
<div className="relative z-10 flex-shrink-0 border-2 border-white rounded-full h-[34px] -ml-1.5">
|
2022-11-24 13:48:18 +00:00
|
|
|
{activity.actor_detail.avatar && activity.actor_detail.avatar !== "" ? (
|
|
|
|
<Image
|
|
|
|
src={activity.actor_detail.avatar}
|
|
|
|
alt={activity.actor_detail.name}
|
|
|
|
height={30}
|
|
|
|
width={30}
|
|
|
|
className="rounded-full"
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<div
|
|
|
|
className={`h-8 w-8 bg-gray-700 text-white border-2 border-white grid place-items-center rounded-full`}
|
|
|
|
>
|
|
|
|
{activity.actor_detail.first_name.charAt(0)}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
2022-11-30 15:58:45 +00:00
|
|
|
<div className="w-full text-xs">
|
2022-11-24 13:48:18 +00:00
|
|
|
<p>
|
2022-11-30 15:58:45 +00:00
|
|
|
<span className="font-medium">
|
|
|
|
{activity.actor_detail.first_name} {activity.actor_detail.last_name}
|
2022-12-01 14:29:21 +00:00
|
|
|
</span>
|
|
|
|
<span> {activity.verb} </span>
|
2022-11-24 13:48:18 +00:00
|
|
|
{activity.verb !== "created" ? (
|
|
|
|
<span>{activity.field ?? "commented"}</span>
|
|
|
|
) : (
|
|
|
|
" this issue"
|
|
|
|
)}
|
2022-11-30 15:58:45 +00:00
|
|
|
<span className="ml-2 text-gray-500">{timeAgo(activity.created_at)}</span>
|
2022-11-24 13:48:18 +00:00
|
|
|
</p>
|
|
|
|
<div className="w-full mt-2">
|
|
|
|
{activity.verb !== "created" && (
|
2022-11-30 15:58:45 +00:00
|
|
|
<div>
|
2022-11-24 13:48:18 +00:00
|
|
|
<div>
|
2022-11-30 15:58:45 +00:00
|
|
|
<span className="text-gray-500">From: </span>
|
|
|
|
{activity.field === "state"
|
|
|
|
? activity.old_value
|
|
|
|
? addSpaceIfCamelCase(
|
|
|
|
states?.find((s) => s.id === activity.old_value)?.name ?? ""
|
|
|
|
)
|
|
|
|
: "None"
|
2022-12-03 13:41:07 +00:00
|
|
|
: activity.field === "parent"
|
|
|
|
? activity.old_value
|
|
|
|
? issues?.results.find((i) => i.id === activity.old_value)?.name
|
|
|
|
: "None"
|
2022-12-01 14:29:21 +00:00
|
|
|
: activity.old_value ?? "None"}
|
2022-11-24 13:48:18 +00:00
|
|
|
</div>
|
|
|
|
<div>
|
2022-11-30 15:58:45 +00:00
|
|
|
<span className="text-gray-500">To: </span>
|
|
|
|
{activity.field === "state"
|
|
|
|
? activity.new_value
|
|
|
|
? addSpaceIfCamelCase(
|
|
|
|
states?.find((s) => s.id === activity.new_value)?.name ?? ""
|
|
|
|
)
|
|
|
|
: "None"
|
2022-12-03 13:41:07 +00:00
|
|
|
: activity.field === "parent"
|
|
|
|
? activity.new_value
|
|
|
|
? issues?.results.find((i) => i.id === activity.new_value)?.name
|
|
|
|
: "None"
|
2022-12-01 14:29:21 +00:00
|
|
|
: activity.new_value ?? "None"}
|
2022-11-24 13:48:18 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div className="w-full h-full flex justify-center items-center">
|
|
|
|
<Spinner />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default IssueActivitySection;
|